Fixed problem where draggables are moved on update during drags or before commit.
This commit is contained in:
parent
f633696e7e
commit
65fea73f85
|
@ -12,8 +12,10 @@ function setup_draggable(id) {
|
|||
old_endeffect(element);
|
||||
element.style.zIndex = new_ZIndex();
|
||||
}
|
||||
Draggables.addObserver(new DragRegObserver($(id)));
|
||||
$(id).appear({duration: 1.0});
|
||||
drag_obs = new DragRegObserver($(id));
|
||||
Draggables.addObserver(drag_obs);
|
||||
$(id).dirty = false;
|
||||
$(id).appear();
|
||||
}
|
||||
|
||||
// Observer for draggables that commits the drag changes to the server.
|
||||
|
@ -22,12 +24,17 @@ DragRegObserver.prototype = {
|
|||
initialize: function(element) {
|
||||
this.element = $(element);
|
||||
},
|
||||
onStart: function() {},
|
||||
onStart: function(eventName, draggable, event) {
|
||||
console.debug(event);
|
||||
draggable.element.dirty = true;
|
||||
},
|
||||
onEnd: function (eventName, draggable, event) {
|
||||
if (Draggables.activeDraggable.element == this.element) {
|
||||
elem = draggable.element;
|
||||
new Ajax.Request(document.baseURI + 'savepos/' + elem.id +
|
||||
'/' + elem.style.top + '/' + elem.style.left);
|
||||
'/' + elem.style.top + '/' + elem.style.left, {
|
||||
onSuccess: function(response) { elem.dirty = false; }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +44,7 @@ function key_handler(e) {
|
|||
var key_code = e.keyCode;
|
||||
|
||||
switch(key_code) {
|
||||
case 27:
|
||||
case 27: /* Escape */
|
||||
hide_add_dialog();
|
||||
break;
|
||||
}
|
||||
|
@ -65,13 +72,16 @@ function new_ZIndex() {
|
|||
return parseInt(max_index) + 1;
|
||||
}
|
||||
|
||||
// Moves a draggable with the given ID to a position if it is not already there.
|
||||
// Moves a draggable with the given ID to a position unless:
|
||||
// it is currently being dragged, or it has been dragged but not this is
|
||||
// not registered at the server side yet, or it is already on the right spot.
|
||||
function move_draggable_if_needed(id, left, top) {
|
||||
if ($(id).style.left != left || $(id).style.top != top) {
|
||||
var actDrag = Draggables.activeDraggable;
|
||||
if (!actDrag || actDrag.element != $(id)) {
|
||||
new Effect.Move(id, { x: left, y: top, mode: 'absolute' });
|
||||
if ($(id).dirty || (actDrag && actDrag.element == $(id))) {
|
||||
return false;
|
||||
}
|
||||
if ($(id).style.left != left || $(id).style.top != top) {
|
||||
new Effect.Move(id, { x: left, y: top, mode: 'absolute' });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue