Commit 21ddc7db by Nimisha Asthagiri Committed by Calen Pennington

Fixed DeleteComponent on Container Page.

parent 29f7fe14
...@@ -218,10 +218,15 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers ...@@ -218,10 +218,15 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers
clickDelete(componentIndex); clickDelete(componentIndex);
create_sinon.respondWithJson(requests, {}); create_sinon.respondWithJson(requests, {});
// expect request URL to contain given component's id // first request contains given component's id (to delete the component)
expect(lastRequest().url).toMatch( expect(requests[requests.length - 2].url).toMatch(
new RegExp("locator-component-" + GROUP_TO_TEST + (componentIndex + 1)) new RegExp("locator-component-" + GROUP_TO_TEST + (componentIndex + 1))
); );
// second request contains parent's id (to remove as child)
expect(lastRequest().url).toMatch(
new RegExp("locator-group-" + GROUP_TO_TEST)
);
}; };
deleteComponentWithSuccess = function(componentIndex) { deleteComponentWithSuccess = function(componentIndex) {
......
...@@ -41,12 +41,12 @@ define(["jquery", "underscore", "js/views/xblock", "js/utils/module", "gettext", ...@@ -41,12 +41,12 @@ define(["jquery", "underscore", "js/views/xblock", "js/utils/module", "gettext",
// avoid creating an orphan if the addition fails. // avoid creating an orphan if the addition fails.
if (newParent) { if (newParent) {
removeFromParent = oldParent; removeFromParent = oldParent;
self.reorder(newParent, function () { self.updateChildren(newParent, function () {
self.reorder(removeFromParent, hideSaving); self.updateChildren(removeFromParent, hideSaving);
}); });
} else { } else {
// No new parent, only reordering within same container. // No new parent, only reordering within same container.
self.reorder(oldParent, hideSaving); self.updateChildren(oldParent, hideSaving);
} }
oldParent = undefined; oldParent = undefined;
...@@ -79,7 +79,7 @@ define(["jquery", "underscore", "js/views/xblock", "js/utils/module", "gettext", ...@@ -79,7 +79,7 @@ define(["jquery", "underscore", "js/views/xblock", "js/utils/module", "gettext",
}); });
}, },
reorder: function (targetParent, successCallback) { updateChildren: function (targetParent, successCallback) {
var children, childLocators; var children, childLocators;
// Find descendants with class "studio-xblock-wrapper" whose parent === targetParent. // Find descendants with class "studio-xblock-wrapper" whose parent === targetParent.
......
...@@ -152,9 +152,12 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", ...@@ -152,9 +152,12 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification",
type: 'DELETE', type: 'DELETE',
url: self.getURLRoot() + "/" + url: self.getURLRoot() + "/" +
xblockElement.data('locator') + "?" + xblockElement.data('locator') + "?" +
$.param({recurse: true, all_versions: true}) $.param({recurse: true, all_versions: false})
}).success(function() { }).success(function() {
// get the parent so we can remove this component from its parent.
var parent = self.findXBlockElement(xblockElement.parent());
xblockElement.remove(); xblockElement.remove();
self.xblockView.updateChildren(parent);
}); });
}); });
}); });
......
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