custom code after add/edit/delete event in Scheduler

Hello,

I would like to run a custom script to update my database after any add, edit or delete in Scheduler in Month, Day, Week views. Can you please point me how to do this? Is there an event handler that could watch for add/edits/delete and then sent the event parameters (id, startdate, enddate) to the external php script.

Many thanks for your help as I am not sure where to start with this.

Cheers,

hi,
you can watch onAfterUpdate event of the dataProcessor, it triggers after each update/delete/add operation
docs.dhtmlx.com/doku.php?id=dhtm … fterupdate

Hi and thanks,

I am not using the data processor…so I am guessing this won’t work?

I am thinking of using the following event handlers for Scheduler:

“onEventAdded”
“onEventSave”
“onEventPasted”
“onEventChanged”

Can you please let me know if you think this would work (and if so, if these are the ones to use to catch the possibility of add/edit/delete of events).

Also, since events are being created only from dnd from dhtmlxTree OR from copy 'n paste…do I need to include the handler “onExternalDragIn” or would “onEventAdded” handle that situation as well since the lightbox is opened after dropping the tree element.

Many thanks,

You can use onEventAdded and onEventChanged, any logic which creates or changes events will trigger them. From those events you can make an ajax call to custom server side script.

Thank you! And, I will also need “onEventDeleted” to handle deleted events…right?

Many thanks,

Yes onEventDelete or onBeforeEventDeleted, second one occurs a bit earlier, and is necessary if you need some other info about event besides its id.

Hello,

I have gotten “onEventAdded”, “onEventChanged” and “OnBeforeEventDelete” to work. I am having trouble with the instance where the event is pasted. I have the code below, but it is creating one event that shows “0:00” as the start time (however, when you double click the event it does have the correct times but hasn’t updated the time until you hit “save” in lightbox) AND it adds a second event that displays the correct start time. Any idea what I am doing wrong??

Thanks in advance!

[code] scheduler.attachEvent(“onEventPasted”, function(copy, e, origin){

 //restore hours, same as in original event
 e.start_date.setHours(origin.start_date.getHours());
 e.end_date.setHours(origin.end_date.getHours());

 //restore minutes, same as in original event
 e.start_date.setMinutes(origin.start_date.getMinutes());
 e.end_date.setMinutes(origin.end_date.getMinutes());

 //repaint event

// scheduler.updateEvent(e.id);
//add event to database
var startdate = e.start_date;
var enddate = e.end_date;
var activityid = e.activityID;
var myTeacher = document.getElementById(“thisid1”).value;
var myurl = “myurl.php”;
// alert(myurl);
dhtmlxAjax.post(myurl, “data=nothing”, function(loader){
// alert(“OK, that’s done!!!”);
scheduler.clearAll();
scheduler.load('myurl1.php);
$("#loading").hide();
});
return true;
});[/code]

Hello again,

I have changed the “onEventPasted” handler code to this. The event adds, but it always says “0:00” as the start time. When I double-click it the event to edit, it has the correct start and end times. If I hit ‘save’ then the correct time shows up on the month view calendar (instead of 0:00).

Thanks again for your help!

[code] scheduler.attachEvent(“onEventPasted”, function(copy, e, origin){

 //restore hours, same as in original event
 e.start_date.setHours(origin.start_date.getHours());
 e.end_date.setHours(origin.end_date.getHours());

 //restore minutes, same as in original event
 e.start_date.setMinutes(origin.start_date.getMinutes());
 e.end_date.setMinutes(origin.end_date.getMinutes());

 //repaint event
 scheduler.updateEvent(e.id);
  
 return true;

}); [/code]

Hello again,

If you have any ideas, please let me know. It seems that if I just have the handler “onEventPasted” all is well, but with the other handlers that I have now added, “onEventAdded” and “onEventChanged” the pasting of an event is no longer behaving correctly. I can paste the event and it is saved to the database (so it triggers “onEventAdded”) but it sets the start and end time to be 00:00 to 01:30 at the top of lightbox and 8:00 to 8:00 when the original event was from 8:00-9:30.

It also seems that I see for a second the correct event being pasted and then it is replaced by this one with incorrect information.

Thanks again.

Could it be that “onEventAdded” is being triggered at the same time as “onEventPasted” so it is adding the event to the database before the “onEventPasted” has completed??

Hello,

I have put the ‘onEventPasted’ handler first so it should execute first, well before the ‘onEventAdded’ handler. However, I added an alert to both and I can see that ‘onEventAdded’ is getting called first before ‘onEventPasted’, which means it is adding the ‘blank’ event to the database before the event is actually pasted from the ‘onEventPasted’ handler…hence the behavior of seeing the pasted event ‘flash’ on the screen with correct details to be replaced with the saved event upon reloading the scheduler.

Do you know how I can ensure that ‘onEventPasted’ executed first?

Perhaps there is something else that I am missing…

I would appreciate any help you could provide as this is crucial to my application.

Many thanks again!

Currently onEventAdded is called before onEventPasted, and it does look as a wrong behavior, as it doesn’t allow to modify the pasted event before data saving initiated.

As quick fix - try to update dhtmlxscheduler_key_nav.js with the attached one
It must fix issue with pasting, but still I see few other issues with copy-pasting and data saving. Final version of fixed file will be available on monday.
dhtmlxscheduler_key_nav.zip (2.86 KB)

Hello,

Thank you so much–this does solve my immediate problem!

I will wait for the final file on Monday.

Thank you again.

Cheers,

Hello again,

I am having another issue related to this. My code below works fine in FF and Safari but in IE it flashes the event in the right location and then it goes back to the original date/time (for example in the case of changing an event).

Any idea why this doesn’t work in IE?

scheduler.attachEvent("onEventChanged", function(id,e){ var startdate = e.start_date; var enddate = e.end_date; var activityid = e.activityID; var thisid = e.id; var myTeacher = document.getElementById("thisid").value; var myurl = baseURL+"data/AddDeleteUpdateEvents.php?thisTeacher="+myTeacher+"&startdate="+startdate+"&enddate="+enddate+"&activityid="+activityid+"&thisid="+thisid+"&what=2&"+Math.random()*1000; dhtmlxAjax.get(myurl, function(loader){ scheduler.clearAll(); scheduler.load('data/XML-PHP-1.php?thisTeacher='+myTeacher+"&"+Math.random()*1000); $("#loading").hide(); }); return true; });

Not quite sure, but IE7 has two specific behaviors

a) Agressive caching, it will try to cache the xml data for any ajax (GET) request. You have Math.random, which must fix the issue.

b) If server side response from server side is small and is already in cache - ajax request can be executed in sync mode ( callback will be processed while the main js code still paused )

You can add some code to server side feed ( current timestamp as text of some event for example ) and verify that issue in your case doesn’t caused by the data caching.