Possible bug with timelineView and onBeforeEventChanged

Hi,

I think I found a bug in the timelineView-extension.
I wanted to add a confirm-dialog for drag-operations in my timelineView with renderMode set to “bar”. I initially used this code:

scheduler.attachEvent("onBeforeEventChanged", function (event, native_event, is_new) { if (!is_new) { //only drag-operations return confirm("Save new location?"); } return true; });This only worked partially. start_date and end_date were correctly set back to the pre-drag-values. But not the section, which was still the new value.

I eventually got a workaround by modifying my code, so that the old section gets saved at drag-start:

[code]
oldSectionID = 0;
scheduler.attachEvent(“onBeforeDrag”, function (event_id, mode, native_event_object) {
if (mode == “move”) { //only drag-operations
oldSectionID = scheduler.getEvent(event_id).section;
}
return true;
});

scheduler.attachEvent(“onBeforeEventChanged”, function (event, native_event, is_new) {
if (!is_new) { //only drag-operations
if (confirm(“Save new location?”)) {
return true;
}
else {
event.section = oldSectionID;
return false;
}
}
return true;
});[/code]
I also could reproduce the bug in /samples/06_timeline/02_lines.html, to make sure the bug wasn’t introduced with my previous customizations.

I tried to locate the error in the source-files but couldn’t find it.

Hello,

First of all thank your for your valuable feedback. :slight_smile:
We have verified this problem and it will be fixed in the upcoming version.
Most likely I will post here what should be changed to fix it (no source file as fixes will involve dhtmlxscheduler.js itself).

Best regards
Ilya

Following changes should be made to resolve this issue in dhtmlxscheduler_debug.js (working with the uncompressed version as it’s easier to navigate there).

  1. At the end of the file add

scheduler._lame_copy=function(target, source){ for(var key in source) target[key] = source[key]; return target; };
2. Locate following string:

this._drag_event=this._copy_event(this.getEvent(this._drag_id)||{});

Replace it with:

this._drag_event=scheduler._lame_copy({},this._copy_event(this.getEvent(this._drag_id)||{}));
  1. Locate following part:

ev.start_date = this._drag_event.start_date; ev.end_date = this._drag_event.end_date; this.updateEvent(ev.id);
Replace it with:

scheduler._lame_copy(ev, this._drag_event) this.updateEvent(ev.id);
Best regards,
Ilya

Hi again,

thanks for your bugfix. It did solve my problem.

Unfortunately it also introduced a new bug :smiley:
Normally one left-click (no double-click, no dragging) should trigger no action. But after you drag an event, choose the “no”/“abort” answer in the following confirm-dialog and the event then gets reverted to its original position, then a single left-click does trigger action, if you click the same event again. It seems, the software now thinks that this click is also a drag-operation therefore triggering the onBeforeEventChanged-listeners. This also prevents you from double-clicking the event.
I looked a bit in the code and in the function scheduler._on_mouse_up I found the following code-snippet:

if (this._drag_event._dhx_changed || [...]) { [...] if (!this.callEvent("onBeforeEventChanged", [ev, B, C])) { [...] } }
I think the problem is your new function scheduler._lame_copy. It copies all properties of _drag_event, including “_dhx_changed”, which now is true.
I fixed this on my system by setting this property to false if the onBeforeEventChanged-listener returns false, changing:

scheduler._lame_copy(ev, this._drag_event) this.updateEvent(ev.id);to

this._drag_event._dhx_changed = false; //fix for new bug scheduler._lame_copy(ev, this._drag_event) this.updateEvent(ev.id);
Bye

Hello,

Unfortunately that function was really a lame copy.
Thank you for information. Similar fix will be applied.

Have a nice day.

Best regards,
Ilya