how to read values of new event

I need to evaluate the values of a new event, I tried
$$(“scheduler”).$$(“calendar”).attachEvent(“onEventSave”, function(){});
$$(“scheduler”).attachEvent(“onEventSave”, function(){});

and also with onEventAdded instead of onEventSave, with no luck, the events don’t seem to fire up. Any advice would be welcome.

Uwe

onEventSave event is not supported in mobile scheduler. You may use onAfterAdd event:

$$(“scheduler”).data.attachEvent(“onAfterAdd”,function(id){
var data = this.item(id);
//
});

Here is the sample
dhtmlxScheduler/samples/07_mobile/08_events.htm

Thanks for the information, Alexandra. But the 3 events listed in the sample don’t reallyt help me. What I want to achieve is (based on all events are full day events): an event can only be added to the calendar if there is no event already in place for the selected day/days. I will look what $$(“scheduler”).data has in it, but would appreciate any advice or direction. Uwe

Please provide more details about the issue. What should happen if List view is active and a user clicks add button ? And what if Day or Month ?

Which view is in place does not really matter - I think. When a user clicks the add button he has to provide the event details and either take the default current date or select a new one. On clicking “save” the date/s selected by the user need to be compared against against events already in place, and if there is one for the same day in place the user get’s an alert and the event does not get submitted (or at least not stored in the database). As in theory other users might have submitted new events after the current user reteived his event list (but before he tried to submit the new event) the best would be if I could validate a return value from the dhx.ui “save” target. I.E. if the script returns -1 I trigger an alert to the user telling him the date is not available, otherwise just go ahead with the normal procedure.

Right now I store the results from the $$(“scheduler”).load target in a javascript array, on “save” for a new event I read the selected dates with

var e = $$('scheduler').$$('editForm').elements;
var start_date = e.start_date.valueOf().Md;
var end_date = e.end_date.valueOf().Md;

compare this values against the dates stored in the javascript array, if a match is found I trigger the warning alert and I prevent the submitting of the “save” script. So the result is the new event does not get stored in the database, the user get’s a warning, all good - but: the event get’s displayed in the user browser as if it were created properly. So fare I did not find a way to prevent this to happen (it disappears on refresh, because the event list is created from the database again, but obvious this does not help). But even if there is a way to prevent this it would not solve the issue of “somebody else might meanwhile have insert an event” - so the cleanest way in my opinion would be to validate the return value of the “save” target. Any advice would be much appreciate.

Due to the lack of other ideas I consider right now to make the “add event” feature independend from the scheduler. Basically if creating and submitting a new event succeeds refresh the scheduler part, otherwise display a warning.

Uwe

Alexandra, before you read all the stuff in my last posting - I think

$$(“scheduler”).data.attachEvent(“onBeforeAdd”,function(id){});

migh solve my issue, but any comments/advice would still be very appreciated.

Uwe

If you want to send the new event data to server and compare with existent records in database, you may use another approach:

Mobile scheduler uses DataProcessor to save data. And it calls onAfterInsert event after the response for “insert” request is received. For the events that are not inserted in database you may set additional parameter - “fail” for example:

<?xml version='1.0' ?>

And if the parameter of the onAfterinsert handler contains this parameter, you may remove the event:

dhx.dp("scheduler").attachEvent("onAfterinsert", function(obj){ if(obj.fail){ this.off(); $$("scheduler").remove(obj.tid); this.on(); } return true });

There is off() method in the event handler. It blocks DataProcessor and its “delete” request (event was not added in database, so there is not need to remove event there). So, event will be delete in scheduler and DP won’t send request to server.

Thank you very much, very helpful indeed. One more question, if you don’t mind: can I disable dates in the past in the datepicker for the new event form. I found in dhx.ready on option to turn the time selector off, is there an option to disable the selection of dates in the past available? Thanks, Uwe

There is not such a possibility in the current version. But we’ll try to add in the next one.