Welcome Guest, Not a member yet? Register   Sign In
Calendar Class
#1

[eluser]IgnitedCoder[/eluser]
First let me say that I miss the js_calendar plugin from CI 1.7 and here's why...

I am trying to figure out how I can make the next/prev links as well as the day selection links call a javascript function when clicked.

Prev - Next should call a jquery function on my page so I can query the database and dynamically update my page the calendar view. i.e. $this->load->view('cal',$data,true); is returned to my jquery ajax request.

Basically I don't want to reload the calendar via URL/URI.

Any ideas, anyone? I don't want to use a jquery calendar, been down that road.

Thanks in advance
#2

[eluser]danmontgomery[/eluser]
the jquery just needs to be an ajax request to a valid controller/method URI like any other in CI, which should output the calendar based on whatever your criteria are.

Code:
$('#some_id').click( function(e) {
    e.preventDefault();
    $('#calendar_div').load('http://www.domain.com/calendar_controller/view/2011/07');
});

Code:
class Calendar_controller extends CI_Controller {

    public function view($year, $month)
    {
        // set calendar options, check valid input, etc
        echo $this->calendar->generate($year, $month);
    }
}
#3

[eluser]IgnitedCoder[/eluser]
Found a much easier way to call javascript functions on Calendar....

{heading_previous_cell}<th><a href="#">&lt;&lt;</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="#">&gt;&gt;</a></th>{/heading_next_cell}

The viewcalendar function makes the ajax call and of course reloads the div with the new calendar contents.

in controller we have:

Code:
function loadcalendar($dates=null){

        $year = null;
        $month = null;
        
        if($dates!=null){
            list($year, $month) = explode('/', $dates);
        }

        $this->prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   => ''
             );

        $this->prefs['template'] =  '
                {table_open}<table border="0" cellpadding="0" cellspacing="0" class="calendar">{/table_open}

                {heading_row_start}<tr>{/heading_row_start}

                {heading_previous_cell}<th><a href="#">&lt;&lt;</a></th>{/heading_previous_cell}
                {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
                {heading_next_cell}<th><a href="#">&gt;&gt;</a></th>{/heading_next_cell}

                {heading_row_end}</tr>{/heading_row_end}

                {week_row_start}<tr>{/week_row_start}
                {week_day_cell}<td>{week_day}</td>{/week_day_cell}
                {week_row_end}</tr>{/week_row_end}

                {cal_row_start}<tr class="days">{/cal_row_start}
                {cal_cell_start}<td class="day">{/cal_cell_start}

                {cal_cell_content}
                    <div class="day_num">{day}</div>
                    <div class="content">{content}</div>
                {/cal_cell_content}
                {cal_cell_content_today}
                    <div class="day_num highlight">{day}</div>
                    <div class="content">{content}</div>
                {/cal_cell_content_today}

                {cal_cell_no_content}<div class="day_num">{day}</div>{/cal_cell_no_content}
                {cal_cell_no_content_today}<div class="day_num highlight">{day}</div>{/cal_cell_no_content_today}

                {cal_cell_blank}&nbsp;{/cal_cell_blank}

                {cal_cell_end}</td>{/cal_cell_end}
                {cal_row_end}</tr>{/cal_row_end}

                {table_close}</table>{/table_close}
            ';

        $this->load->library('calendar', $this->prefs);
        return $this->calendar->generate($year,$month);

    }

Hope this helps someone...

Brendan




Theme © iAndrew 2016 - Forum software by © MyBB