Restore deleted event if operation fails on DB

I’m using dhtmlxScheduler v3.7

How can I restore a deleted event (text appears red and striked) if operations returns an error from the DB?

My web service is returning:

<?xml version="1.0" encoding="utf-8"?><data><action type="error" sid="1" tid="1" oper="deleted" message="Some error."></action></data>

the code to handle the error:

   [code] // if update fails restore event to original position or delete if it's new
    dp.attachEvent("onAfterUpdate", function(sid, action, tid, response){
        if (action == "error"){                          
              
            switch(response.getAttribute("oper"))
            {
            case "updated":
                break;
            case "inserted":
                break;
            case "deleted":
                break;                  
            default:
                // event unknown operation (do nothing)
                break;                  
            }                  
                                
        }
    });[/code]

I tried using scheduler.updateEvent(sid) but it seems the object containing the data of the deleted event is no longer present and I don’t know which event to use to cancel the delete operation.

Thanks in advance.

Try to use

dp.setUpdated(sid, false);

It will remove visual marking from the event and will not try to remove it from DB anymore
( event object is not deleted from scheduler until confirmation, it only marked as “need-to-be-deleted” )

thanks for the reply but it didn’t worked (the event stays the same way).

The events are executed in the following order:

  • deleteEvent
  • onConfirmedBeforeEventDelete
  • setUpdated
  • markRow: inside this function [after the callEvent(“onRowMark”) if] the text appears striked and black
  • _sendData
  • loadXML:
  • POST Response:
<?xml version="1.0" encoding="utf-8"?><data><action type="error" sid="1" tid="1" oper="deleted" message="Some error."></action></data>
  • afterUpdateCallback
  • setUpdated
  • markRow: inside this function [after the callEvent(“onRowMark”) if] the text turns red
  • onAfterUpdate: inside this function I try to restore the event to the normal state since delete failed in DB as described in the first post.

After I added dp.setUpdated(sid, false); in onAfterUpdate function

  • deleteEvent
  • onConfirmedBeforeEventDelete
  • setUpdated
  • markRow
  • _sendData
  • loadXML
  • afterUpdateCallback
  • setUpdated
  • markRow
  • onAfterUpdate
    [u]* setUpdated
  • markRow[/u]

I forgot to add that I’m not using the dataProcessor :blush:

A solution I found is to parse the deleted event again. I coudn’t see any problem yet, as the deleted event is being replaced with the new parsed event (with the same attributes as id, start_date, etc) and functionality is not affected. for example I can drag and drop the event to a new spot. Anyway if someone came up with a better solution please let me know.

[code]// if update fails restore event to original position or delete if it’s new
dp.attachEvent(“onAfterUpdate”, function(sid, action, tid, response){
if (action == “error”){

            switch(response.getAttribute("oper"))
            {
            case "updated":
                break;
            case "inserted":
                break;
            case "deleted":					
				scheduler.parse([{
					"id":sid,
					"start_date":$.fn.formatDateTime(scheduler.getEventStartDate(sid)),
					"end_date":$.fn.formatDateTime(scheduler.getEventEndDate(sid)),
					"text":scheduler.getEventText(sid)}] ,
					"json");						
				break;                 
            default:
                // event unknown operation (do nothing)
                break;                 
            }                 
                               
        }
    });[/code]