function save(event_id){
var req = new XMLHttpRequest();
req.open('POST', '/UpdateEvents.json', false);
req.setRequestHeader("Content-Type","application/json");
var string = JSON.stringify(scheduler.getEvent(event_id));
req.send(string);
}
You have the wrong event (onAfterLigtbox).
Use onEventSave instead
scheduler.attachEvent("onEventSave", function (id, data, is_new_event) {
// call save(id) here
// also this must return true on successful save or false on failure
}
It’s just a matter of wrapping your head around the event model.
All events are listed here docs.dhtmlx.com/doku.php?id=dhtm … ler:events. Look at the “data” parameter above too as this holds the lightbox form data
I was expecting the start_date / end_date to be in the format of the
scheduler.config.xml_date="%Y-%m-%d %H:%i" I had set - is there any configuration over this format ?
id - is this an internal id ? At present my ‘events’ received from the server do not have an ‘id’. If it is only internal can I set any data to not send it in the PUT ?
_timer / _sday / _inner / _sorder / _count - It is not clear to me what these are / if they are needed ? and if not can they be removed easily ?
(1)
start_date and end_date are actually the js Date objects, not the strings
You can use scheduler’s formatting ability to convert them to necessary string docs.dhtmlx.com/doku.php?id=dhtm … te_formats
(2) yep, this id is necessary for the internal operation. Basically if you have some kind of DB you need to have ids to be able to store data back in DB ( to know which DB record need to be updated when some event was updated in the scheduler )
(3) they are related to the rendering of events, and not necessary for data storing ( that data is calculated on the fly , by the scheduler )
and if not can they be removed easily ?
The simplest way to achieve it - construct your own js object with necessary properties only, and send it to the server side
Thanks I have move forward but a few other questions - sorry.
On the date/time logic I have changed using the scheduler.date.date_to_str the date/time in the event - and it is output in the JSON correctly - I assume this will not cause any issues to the event logic.
At present I am sending the JSON data on ‘onEventSave’ but reading the documentation I am a little confused which are the correct ‘events’ to be saving on.
For example ‘oneventchanged’ / ‘oneventsave’ - do I need to work on both or just one ? Are there others I should handle ? What about ‘deletion’ ?
Removal of the unnecessary properties - I am not sure how this would be achieved in Javascript.
(1)
When used against data in onEventSave handler - it is safe to modify data object
(2)
Normally there are 3 events for custom saving logic
onEventCreated
onEventUpdated
onBeforeEventDelete
onEventSave fires only when save button pressed in the lightbox form, but there are other ways to modify event ( dnd for example ) , so onEventChanged is more safe
onEventChanged does not seem to cover ‘saving’
Saving can trigger oneventadded if it is a new event.
it is not clear to me how the DB is mean to know this event is a deletion
The event handler provides ID of event which is deleted on client side, normally it is expected that DB record has the same ID, so you can sync deleting operation.
But the display is cleared of the ‘lightbox’ summary if I have the ‘onEventAdded’ section above - if I remove this trigger the box is left displayed but (of course) my sendevent logic is not triggered.
Can you provide the code, which is attached to onEventAdded handler ?
Most probably it still corrupts original date objects, which result in event disappearing.