Our pure JavaScript Scheduler component


Post by niravf22 »

Hi team,

I am looking for a solution where I can check the response from my backend (server) when creating/updating/deleting an event on the scheduler. If the backend response is not 200 or some validation error, I would like to delete that event from the scheduler (and notify user that appointment was not scheduled).

Please note that I am using the event store to load all the events and manage CRUD.
Thanks

sample code snippet
    eventStore: {
        createUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/events.json',
        readUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/events.json',
        updateUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/update-events.json',
        deleteUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/delete-event.json',
        // Load and save automatically
        autoLoad: true,
        autoCommit: true,
        
        onBeforeCommit: function onBeforeCommit() {
            // Make it read only since it only allows one commit at the time
            scheduler.readOnly = true;
        },
        onCommit: function onCommit() {
            scheduler.readOnly = false;
        }
    }

Post by mats »

You can listen for the 'exception' event on Store, docs here: https://bryntum.com/docs/scheduler/#Com ... -exception

Post by niravf22 »

Mats,
Thanks for pointing out. I am able to add this as a listener but not sure how to handle it gracefully. I get a console error as follows and the dashboard becomes non-functional.

Uncaught (in promise) -> {action: "commit", exception: true, changes: {…}, create: {…}, source: EventStore, …}

Is there a way I can delete the event if it was not created on the backend?
Or not update it if it wasn't updated on the backend? Basically, rolling back the changes made.
    eventStore: {
        createUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/events.json',
        readUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/events.json',
        updateUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/update-events.json',
        deleteUrl: '/practice/clinics/'+clinic_id+'/clinic_appointments/delete-event.json',
        // Load and save automatically
        autoLoad: true,
        autoCommit: true,
        
        onBeforeCommit: function onBeforeCommit() {
            // Make it read only since it only allows one commit at the time
            scheduler.readOnly = true;
        },
        onCommit: function onCommit() {
            scheduler.readOnly = false;
        },
        listeners:{
            exception: function (source){
                
            }
        }
    }
Appreciate the help.

Post by mats »

The promise rejection warning will be removed in the next release.

Is there a way I can delete the event if it was not created on the backend?
Sure, just delete the events in your store which are `phantom` (in next release, there will be a new getter `isPhantom` on the Model class.

Post Reply