search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

On event resize

Asked by Marios
10 years ago.

When onEventResized is called in some cases depending on the server response I want to cancel the moving and revert the event back to its old start/end dates. What is the recommended way of doing this ?

Thanks in advance

Answer posted by Dan Letecky [DayPilot]
10 years ago.

There are two ways to do it:

1. Store the old event start and end in the args object in onEventResize (which is fired before the default action). The same object will be passed to onEventResized. Then use the old values to revert the operation if needed.

dp.onEventResize = function(args) {
  args.original ={
    start: args.e.start(),
    end: args.e.end()
  };
};
dp.onEventResized  = function(args) {
  $.post("/update", function(result) {
    if (result.rollback) {  // your object returned by the server
      args.e.start(args.original.start);
      args.e.end(args.original.end);
      dp.events.update(args.e);
    }
  });
};

2. Do it the other way around - postpone the update until it's confirmed by the server. Call the server from onEventResize instead of onEventResized and cancel the default action using args.preventDefault().

dp.onEventResize = function(args) {
  args.preventDefault();
  $.post("/update", function(result) {
    if (result.commit) {  // your object returned by the server
      args.e.start(args.newStart);
      args.e.end(args.newEnd);
      dp.events.update(args.e);
    }
};
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.