Commit 0083cfc4 by cahrens

Always call refresh on parent of drag and drop operation.

STUD-2048
parent b392e96d
...@@ -241,7 +241,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel ...@@ -241,7 +241,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
}); });
it("calls handleReorder on a successful drag", function () { it("calls handleReorder on a successful drag", function () {
ContentDragger.dragState.dropDestination = $('#unit-2'); ContentDragger.dragState.dropDestination = $('#unit-2');
ContentDragger.dragState.attachMethod = "before"; ContentDragger.dragState.attachMethod = "after";
ContentDragger.dragState.parentList = $('#subsection-1'); ContentDragger.dragState.parentList = $('#subsection-1');
$('#unit-1').offset({ $('#unit-1').offset({
top: $('#unit-1').offset().top + 10, top: $('#unit-1').offset().top + 10,
...@@ -298,7 +298,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel ...@@ -298,7 +298,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
afterEach(function () { afterEach(function () {
this.clock.restore(); this.clock.restore();
}); });
it("should send an update on reorder", function () { it("should send an update on reorder from one parent to another", function () {
var requests, savingOptions; var requests, savingOptions;
requests = create_sinon["requests"](this); requests = create_sinon["requests"](this);
ContentDragger.dragState.dropDestination = $('#unit-4'); ContentDragger.dragState.dropDestination = $('#unit-4');
...@@ -333,6 +333,31 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel ...@@ -333,6 +333,31 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
// target // target
expect($('#subsection-2').data('refresh')).toHaveBeenCalled(); expect($('#subsection-2').data('refresh')).toHaveBeenCalled();
}); });
it("should send an update on reorder within the same parent", function () {
var requests = create_sinon["requests"](this);
ContentDragger.dragState.dropDestination = $('#unit-2');
ContentDragger.dragState.attachMethod = "after";
ContentDragger.dragState.parentList = $('#subsection-1');
$('#unit-1').offset({
top: $('#unit-1').offset().top + 10,
left: $('#unit-1').offset().left
});
ContentDragger.onDragEnd({
element: $('#unit-1')
}, null, {
clientX: $('#unit-1').offset().left
});
expect(requests.length).toEqual(1);
expect($('#unit-1')).toHaveClass('was-dropped');
expect(requests[0].requestBody).toEqual(
'{"children":["second-unit-id","first-unit-id","third-unit-id"]}'
);
requests[0].respond(200);
this.clock.tick(1001);
expect($('#unit-1')).not.toHaveClass('was-dropped');
// parent
expect($('#subsection-1').data('refresh')).toHaveBeenCalled();
});
}); });
}); });
}); });
......
...@@ -273,7 +273,13 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif ...@@ -273,7 +273,13 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
newParentEle = element.parents(parentSelector).first(), newParentEle = element.parents(parentSelector).first(),
newParentLocator = newParentEle.data('locator'), newParentLocator = newParentEle.data('locator'),
oldParentLocator = element.data('parent'), oldParentLocator = element.data('parent'),
oldParentEle, saving; oldParentEle, saving, refreshParent;
refreshParent = function (element) {
var refresh = element.data('refresh');
if (_.isFunction(refresh)) { refresh(); }
};
// If the parent has changed, update the children of the old parent. // If the parent has changed, update the children of the old parent.
if (newParentLocator !== oldParentLocator) { if (newParentLocator !== oldParentLocator) {
// Find the old parent element. // Find the old parent element.
...@@ -282,10 +288,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif ...@@ -282,10 +288,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
}); });
this.saveItem(oldParentEle, childrenSelector, function () { this.saveItem(oldParentEle, childrenSelector, function () {
element.data('parent', newParentLocator); element.data('parent', newParentLocator);
_.each([oldParentEle, newParentEle], function (element) { refreshParent(oldParentEle);
var refresh = element.data('refresh');
if (_.isFunction(refresh)) { refresh(); }
});
}); });
} }
saving = new NotificationView.Mini({ saving = new NotificationView.Mini({
...@@ -299,6 +302,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif ...@@ -299,6 +302,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
}, 1000); }, 1000);
this.saveItem(newParentEle, childrenSelector, function () { this.saveItem(newParentEle, childrenSelector, function () {
saving.hide(); saving.hide();
refreshParent(newParentEle);
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment