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

Automatically moving later events when inserting new event

Asked by David
7 years ago.

Is there a way to auto-shift future events when inserting a new event in between two events. The use case would be two events back to back where I then want to drag an event between them. I would like all remaining events on that resource to be shifted back in time corresponding to the duration of the new event.

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

This is a nice feature but it's not implemented at the moment because it would lead to bad app design (allowing inconsistencies).

1. Let's say you have scheduled one event per day for a given resource for the next year. When you display the current month in the scheduler and use this (hypothetical) feature to insert a new event in the middle it would shift all events that it knows about - i.e. events until the end of this month. It would leave all events from the following months unshifted.

2. Another thing - you don't want to rely on such a feature to be implemented purely on the client-side (the new dates need to be checked on the server side to prevent invalid input from being processed).

This means you have to re-implement it on the server side anyway. When you have the server-side implementation, you can simply send the updated events back and reload the Scheduler with the same effect.

Comment posted by David
7 years ago.

Thanks for the answer. I certainly understand the complexity that would go into this. We are looking to use this as a scheduler that would only schedule a week at a time. You are correct that I would have to implement this on the backend anyway, I was just hoping for a visual indication as to what is about to occur, by visually moving the items out during dragging. Thanks again for the help.

Comment posted by Dan Letecky [DayPilot]
7 years ago.

This is a poor replacement but you can use onEventMoving to provide a context-dependent hint to the user during dragging:

dp.onEventMoving = function(args) {
  var existingEvents = args.row.events.forRange(args.start, args.end);
  if (existingEvents.length > 0) {
    args.right.html = "Existing events will be shifted";
    args.right.enabled = true;
  }
};

See also:
https://api.daypilot.org/daypilot-scheduler-oneventmoving/

This is not an uncommon request and a better solution might come in the future but unfortunately it's not available at the moment.

Comment posted by David
7 years ago.

Just thought I'd share what I ended up coming up with. This will auto adjust the later events in the row after moving an event. It fits what I needed, and might be useful as a springboard for a future enhancement.

dp.onEventMoved = function (args) {
                    row_events = dp.rows.find(args.e.row()).events.all();
                    var duration = 0;
                    var events_to_edit = [];
                    var previous_end = "";
                    $.each(row_events, function(key, event) {
                        event.data.start = new DayPilot.Date(event.data.start);
                        event.data.end = new DayPilot.Date(event.data.end);
                        if (((args.e.data.start >= event.data.start && args.e.data.start <= event.data.end) || (args.e.data.start <= event.data.start && args.e.data.end >= event.data.start && args.e.data.end <= event.data.end)) && duration == 0 && event.data.id != args.e.data.id) {
                            duration = args.e.data.end.getTotalTicks() - event.data.start.getTotalTicks();
                        }
                        if (duration != 0 && event.data.id != args.e.data.id && (previous_end >= event.data.start || previous_end == "")) {
                            event.data.start = event.data.start.addMilliseconds(duration);
                            event.data.end = event.data.end.addMilliseconds(duration);
                            previous_end = event.data.end;
                            events_to_edit.push(event);
                        }
                    });
                    dp.update();
                };
Comment posted by David
7 years ago.

With that, I am able to fire a request to the server to update the events on the back-end based on the events_to_edit array.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.