Heya all,

I'm using a special cakePHP plugin for displaying a fully fledged calendar.
(CakePHP full calendar plugin)

By clicking on an appointment in the calendar, the user is redirected to an edit screen, where he or she can change the date, time and a lot of other related data.
Now, another function of the calender is to change the date of an appointment by simply dragging and dropping the apointment on a different date (using AJAX).

Now the problem i'm having is that, everytime i move an appointment, it opens the edit screen.
This is rather annoying when all you need to do is change the date of the appointment...
does anyone know how to resolver this?

The part of the javascript file performing the magic is as follows:

eventDragStart: function(event) {
                        $(this).qtip("destroy");

        },
        eventDrop: function(event) {
            var startdate = new Date(event.start);
            var startyear = startdate.getFullYear();
            var startday = startdate.getDate();
            var startmonth = startdate.getMonth()+1;
            var starthour = startdate.getHours();
            var startminute = startdate.getMinutes();
            var enddate = new Date(event.end);
            var endyear = enddate.getFullYear();
            var endday = enddate.getDate();
            var endmonth = enddate.getMonth()+1;
            var endhour = enddate.getHours();
            var endminute = enddate.getMinutes();
            if(event.allDay == true) {
                var allday = 1;
            } else {
                var allday = 0;
            }
            var url = "/DbDeKust/workdates/updateCalendar?id="+event.id+"&start="+startyear+"-"+startmonth+"-"+startday+" "+starthour+":"+startminute+":00&end="+endyear+"-"+endmonth+"-"+endday+" "+endhour+":"+endminute+":00&allday="+allday;
            $.post(url, function(data){});
        },
Member Avatar

LastMitch

Now the problem i'm having is that, everytime i move an appointment, it opens the edit screen. This is rather annoying when all you need to do is change the date of the appointment...

What does it has to do with cakePHP plugin?

I mean I don't see any code related to PHP. The code you provided is just jQuery.

Either you didn't installed cakePHP plugin correctly or you modify the cakePHP plugin and it doesn't work correctly now.

Hey LastMitch,

The cakephp plugin i linked to is essentially a wrapper around a jquery file, with some cake code so that it works with cake php projects. (so that it is able to save to the database, for example).

The cake code seems to work correctly, but here it is anyway. excerpt from a controller:

public function workdateCalendar() {
        $this -> Workdate -> recursive = 1;
        $this -> set('Workdate', $this -> paginate());
    }

    // The feed action is called to get the list of workdates (JSON)
    function feed($id = null) {
        $this -> layout = "ajax";
        $inputParameters = $this -> params['url'];
        $conditions = array('conditions' => array('UNIX_TIMESTAMP(workdate_start) >=' => $inputParameters['start'], 'UNIX_TIMESTAMP(workdate_start) <=' => $inputParameters['end']));
        $workdates = $this -> Workdate -> find('all', $conditions);
        foreach ($workdates as $workdate) {
            if ($workdate['Workdate']['workdate_all_day'] == 1) {
                $allday = true;
                $end = $workdate['Workdate']['workdate_start'];
            }
            else {
                $allday = false;
                $end = $workdate['Workdate']['workdate_end'];
            }
            $dataForFullCallender[] = array(
                'id' => $workdate['Workdate']['workdate_id'],
                'title' => $workdate['Workdate']['workdate_note'],
                'start' => $workdate['Workdate']['workdate_start'],
                'end' => $end,
                'allDay' => $allday,
                'url' => '/DbDeKust/workdates/edit/' . $workdate['Workdate']['workdate_id'],
                'details' => $workdate['Workdate']['workdate_note'],
                'className' => 'blue'
            );
        }
        $this -> set("json", json_encode($dataForFullCallender));
    }

    // The update action is called from the jquery file i linked in the OP to update date/time when a workdate is dragged or resized
    public function updateCalendar($id = null) {

        $vars = $this -> params['url'];
        $this -> Workdate -> id = $vars['id'];
        $save = $this -> Workdate -> saveField('workdate_start', $vars['start']);
        $save = $this -> Workdate -> saveField('workdate_end', $vars['end']);
        $save = $this -> Workdate -> saveField('workdate_all_day', $vars['allday']);
    }
Member Avatar

LastMitch

Now the problem i'm having is that, everytime i move an appointment, it opens the edit screen.

Take out the /edit/

From this:

'url' => '/DbDeKust/workdates/edit/' . $workdate['Workdate']['workdate_id'],

to this:

'url' => '/DbDeKust/workdates/' . $workdate['Workdate']['workdate_id'],

I assume there's a open window (iFrame) appearing so on that iFrame disable the link (div tags or html tags) or comment it out.

Heya,

The thing i'm trying to achieve here, is that the user is only redirected when he clicks the appointment, not when he drags it. by removing the /edit/, the click functionality is gone.
And without the ability to edit the appointments, well, the calendar loses it's purpose.

Member Avatar

LastMitch

The thing i'm trying to achieve here, is that the user is only redirected when he clicks the appointment, not when he drags it. by removing the /edit/, the click functionality is gone. And without the ability to edit the appointments, well, the calendar loses it's purpose.

Where is the code that redirected? I hope you understand everything is in javascript meaning your code has no php at all?

This is the only code that related to edting things:

$dataForFullCallender[] = array()

but where is the redirected code and how does the html look likes?

I'm not going to write any javascript redirected code (or modify the code) since we are in PHP section not javascript section.