Collision between events

Hi All,

Is there any way to prevent collision between events in mobile?
Maybe with a data base query.



you can set validation rules for scheduler form. If the validation function returns false, the data won’t be saved. Here is the default form_rules:

scheduler.config.form_rules = { end_date:function(value,obj){ return (obj.start_date.valueOf() < value.valueOf()); } }

It prevents saving events with with incorrect end_date - when end_date< start_date. You may modify the function and added the validation for the events occur between obj.start_date and value:

scheduler.config.form_rules = { end_date:function(value,obj){ if((obj.start_date.valueOf() >= value.valueOf())) return false; // an array with events var events = $$("scheduler").getEvents(obj.start_date,value); // removes edited event from the array for(var i =0; i < events.length; i++){ if(events[i].id == events.splice(i,1); } return events.length>0; } }

Excelent! This works fine with one user. If I needed to prevent collision from multiple users…

It is possible to do this in the DB validation by a Select?
It is possible to update the event from DB before saving?


Yes, you can use server-side validation. And if collision occurs, you may send corresponding response on client and inform a user that event was not saved.

Are you using connector ? If you are, You can set onBeforeUpdate and onBeforeInsert event

function validate($data){ // you code that checks for collision if(...){ //if collision $data->set_response_attribute("details","collision"); $data->error(); } } $scheduler->event->attach("beforeUpdate","validate"); $scheduler->event->attach("beforeInsert","validate"); $scheduler->render_table(...);

The “error” response can be easily processed in onDBError of DataProcessor:

dhx.dp($$("scheduler")).attachEvent("onDBError",function(errorData){ if(errorData.details == "collision") dhx.alert("The event has not been saved due to collision"); });

Yes, that is what I was looking for, now it works and don’t save the event.

Just a little question, it is possible to do a “deleteEvent” so the collision event is not shown.

				if(errorData.details == "collision")
					dhx.alert("Ya existe un evento similar");
					var eventId = $$("scheduler").getCursor();

I am having an error because the deleteEvent is not available here.


Mobile scheduler does not have removeEvent method. Try to use remove(eventId) method:


However, remove will cause datastore updating with request to the servers-side script. And you do not need this request as the event was saved in database. You can use silent method as the solution:


Note that this solution can be applied only if an event was added. If an event (there were not collisions) was edited and caused a collision, it would not be be good solution to delete such an event, as this event still exists in database. Possibly it would be better to make an update from server.

It helps me a lot, thanks!