Recurring events - server side logic.

I have been updating my scheduler for recurring events and I have a few questions.

Note: I am using JSON to send the event information from the client to/from the server.
The server is Java using Spring MVC and Hibernate.

  1. Do I need to store (in additional to the basic information) ‘rec_pattern’ in the database and return it to the client or only store
    ‘rec_type’ / ‘event_length’ / ‘event_pid’ ?

  2. I understand that extra server side logic is needed based on the following text.

  1. if event with rec_type==none wad inserted - response must have “deleted” status
  2. if event with rec_type was updated or deleted - all records with event_pid equal to the master id must be deleted
  3. if event with event_pid value was deleted - it need to be updated with rec_type “none” instead of deleting.

But what does ‘response must have “deleted” status’ mean on case 1 ?

In my case on the client side I have used:

scheduler.attachEvent("onEventAdded", function(event_id,event_object){
                                   sendaddevent(event_id,’/AddEvent.json?userid=${user.id}&uid='+ scheduler.uid());
                                   return true;   
                                  });
scheduler.attachEvent("onEventChanged", function(event_id,event_object){
                                   sendchangedevent(event_id,'/ChangeEvent.json?userid=${user.id}&event_id='+ event_id + '&uid='+ scheduler.uid());
                                   return true;   
                                  });
scheduler.attachEvent("onBeforeEventDelete", function(event_id,event_object){
                                   senddeleteevent(event_id,’/DeleteEvent.json?userid=${user.id}&event_id='+ event_id + '&uid='+ scheduler.uid());
                                   return true;   
                                 });  
function sendaddevent(id,url){
	   
	     convert_date_time = scheduler.date.date_to_str("%Y-%m-%d %H:%i"); 
	      
	     var req = new XMLHttpRequest();  

	     req.open('POST', url , false);   
	     req.setRequestHeader("Content-Type","application/json");
	     req.setRequestHeader("Accept","application/json");
	      
	     var event = scheduler.getEvent(id);
	     
	 	     
	     var event_copy = {
	    	     
	                      text: event.text,
	    		          start_date: convert_date_time(event.start_date), 
	    		          end_date: convert_date_time(event.end_date) 
	    		         
	    		};  
	    		
		 var string = JSON.stringify(event_copy);
		  
		 req.send(string);   

		 var responseString = req.responseText;

		 var newEvent = JSON.parse(responseString);  

		 scheduler.changeEventId(event.id,newEvent.id);

		 return true; 		     
		};

Thanks for any help.

Hello,

‘rec_type’ / ‘event_length’ / ‘event_pid’ is enough.

When we have recurring event (say everyday) and we want to delete just one of them then actually we need to insert 1 record into the database but delete that event on client side.
DHTMLX data processor would delete event if ‘deleted’ status is returned but as you don’t use it then you simply need to implement logic described above.

Best regards,
Ilya

thanks

I am just implemented the server/client side logic for this and have a few other questions.

Note: I am using JSON to send the event information from the client to/from the server.
The server is Java using Spring MVC and Hibernate.

A) For the code below I am not sure where to place the equivalent logic inside the set of scheduler events itself.

Would it be ok to used onEventChanged for “updated” and onBeforeEventDelete for “deleted” ?
or should “beforeProcessing” happen earlier in the logic flow – if so on what ‘event’ ?


$scheduler->event->attach("beforeProcessing","delete_related");

B)

“....but delete that event on client side.”

I assume I need to implement some client side logic here to meet.

1. if event with rec_type==none wad inserted - response must have “deleted” status

I am not sure exactly what I need to do here ? and what ‘events’ it should be on (onEventChanged) ?

Thanks as usual for any help.

Hello,

That’s server side code. So just before processing your request you need to execute same code as in “delete_related” function.

For example you have series of recurring events which happen everyday. You want to delete just one of them. On the client side internally you simply need to delete it but on the server side - add additional record. So I believe you should use onBeforeEventDelete to send such request to the server.

Best regards,
Ilya

Thanks for the info:

I have one more questions to finish the implementation before testing it all.

  1. When I delete an individual event I am seeing onEventAdded called and an event added with rec_type = none.

However I am not seeing the ‘lightbox’ being deleted – unlike the ‘delete all occurrences’ case.

I am seeing an ‘A is undefined error’ in firebug

A is undefined
xxxx/scheduler/ext/dhtmlxscheduler_recurring.js
Line 1

Hello,

1) When I delete an individual event I am seeing onEventAdded called and an event added with rec_type = none. However I am not seeing the ‘lightbox’ being deleted – unlike the ‘delete all occurrences’ case.

Please provide your onBeforeEventDelete handler. Most likely you are adding there event with addEventNow function, try using addEvent. addEvent doesn’t display lightbox (which was causing your issues) and simply creates event.

Best regards,
Ilya

Thanks

It is interesting to note that onEventAdded must be being called as I am seeing “/AddEvent” in the firebug.

onBeforeEventDelete is:


scheduler.attachEvent("onBeforeEventDelete", function(event_id,event_object){
                                   senddeleteevent(event_id,'/DeleteEvent.json?userid=${user.id}&event_id='+ event_id + '&uid='+ scheduler.uid());
return true;   
                                 });  

Senddeleteevent is:


function senddeleteevent(id,url){
				   
	     convert_date_time = scheduler.date.date_to_str("%Y-%m-%d %H:%i"); 
			      
	     var req = new XMLHttpRequest();  

		 req.open('POST', url , false);   
	     req.setRequestHeader("Content-Type","application/json");
	     req.setRequestHeader("Accept","application/json");
			      
	     var event = scheduler.getEvent(id);

	     	     
	     // Copy event so can do time conversion without corrupting original start / end times.
	     	     
	     var event_copy = {
	    	     
	                      text: event.text,
	    		          start_date: convert_date_time(event.start_date), 
	    		          end_date: convert_date_time(event.end_date), 
	    		          rec_type: event.rec_type,
	    		          pid: event.event_pid,
	    		          length: event.event_length
	    		          	    		};  
	    		
		 var string = JSON.stringify(event_copy);
				  
		 req.send(string);  

		 if (req.status != 200) {
			 alert("Error sending data to network - Delete");
		     return false;
		 } 
					
		 return true; 		     
		};

Hello,

I am sorry, checked the code, actually it’s native recurring code creates new event:

[code]scheduler.attachEvent(“onBeforeEventDelete”,function(id){
var ev = this.getEvent(id);
if (id.toString().indexOf("#")!=-1) {
var id = id.split("#");
var nid = this.uid();

	var nev = this._copy_event(ev);
	nev.id = nid; 
	nev.event_pid = id[0];
	nev.event_length = id[1];
	nev.rec_type = nev.rec_pattern = "none";
	this.addEvent(nev);


return true;
});[/code]
Can you please use replace your current dhtmlxscheduler_recurring.js file with the recurring.js from the sources folder? It’s uncompressed version, would be easier to debug this issue.

Best regards,
Ilya

Hello,

It seems you haven’t actually replaced the file or it was cached. Try clearing the cache and make sure that you have replaced file and includes on the page are correct (points to the new file).
The goal here is to understand where exactly problem lies.

[code]A is undefined

http://localhost:8080/xxxx/scheduler/ex … curring.js

Line 1[/code]
That’s compressed version.

Best regards,
Ilya

Sorry my fault cannot type !!!

I have replace the file (with recurring.js) but now I do not even get as far as before I get
‘repeat event’ undefined in the lightbox when opened and you cannot click on ‘disabled’ to make it ‘enabled’.

All I have changed is I have replaced the original dhtmlxscheduler_recurring.js with the one from the ‘source’ directory.

Hello,

Not sure what the problem might be, try using attached file.

Best regards,
Ilya
dhtmlxscheduler_recurring.zip (5.14 KB)

Tried that file but same problem I get the following in firebug on opening lightbox with either the source version or your version.
I do not get this problem with the compressed version.

node.getElementsByTagName is not a function

localhost:8080/scheduler/ext/dht … curring.js

Line 11

My fault, following should work.
Reverted file to the base version. You were fast enough to download latest version, there may be some issues :slight_smile:

Kind regards,
Ilya
dhtmlxscheduler_recurring.zip (5.76 KB)

That has got me back to the original problem - thanks.

Information from firebug is:

ev is undefined

localhost:8080/scheduler/ext/dht … curring.js

Line 250

When I delete an individual recurring event.

I have not done this form of debugging before so just tell me if you need anything else.

I have just noticed another version you have placed on the site so I am a bit confused - sorry

tried your other version and I get the same issue.

ev is undefined

localhost:8080/scheduler/ext/dht … curring.js

Line 250

Hello,

Can’t tell you what is wrong for now, can you please make your sample available on the internet or create complete demo I would be able to run locally?
If you are familiar with debugging using firebug when put debugging point in the ‘onBeforeEventDelete’ event and check what’s happening there.

Best regards,
Ilya

At present my application is not available on the internet - though I could have a trial version very soon however I have had a look at Firebug and been able to get the stack trace.

I hope this is of use.


ev is undefined

_add_rec_marker()dhtmlx...ring.js (line 250)
ev = undefined
time = 1306894200000

(?)()dhtmlx...ring.js (line 298)
id = ["6", "1306894200"]
dhtmlx()dhtmlx...uler.js (line 9)

dhtmlx()dhtmlx...uler.js (line 9)
name = "ev_onbeforeeventdelete"
arg0 = ["6#1306894200", Object { start_date=Date, end_date=Date, more...}]

loadUpdate()dhtmlx...uler.js (line 39)
C = "6#1306894200"
A = undefined

loadUpdate()dhtmlx...uler.js (line 39)
B = "6#1306894200"

loadUpdate()dhtmlx...uler.js (line 39)
C = click clientX=581, clientY=94

 ev._pid_time = time; 

If you need anything else just let me know.

Hello,

Do you use any JS library (mootools, prototype.js and so on)?

Best regards,
Ilya

No I only use:

json2.js
jquery.jclock.js
jquery-1.5.2.min.js