Support faster deletes of sections

This commit is contained in:
Andy Armstrong
2014-07-15 08:37:23 -04:00
committed by cahrens
parent 20782f04e5
commit d2b61f146f
5 changed files with 45 additions and 17 deletions

View File

@@ -117,6 +117,19 @@ define(["jquery", "underscore", "js/views/xblock_outline", "js/views/utils/view_
}
},
onChildDeleted: function(childView) {
var xblockInfo = this.model,
childCategory = childView.model.get('category'),
children = xblockInfo.get('child_info') && xblockInfo.get('child_info').children;
// If deleting a section that isn't the final one, just remove it for efficiency
// as it cannot visually effect the other sections.
if (childCategory === 'chapter' && children && children.length > 1) {
childView.$el.remove();
} else {
this.refresh();
}
},
createNewItemViewState: function(locator, scrollOffset) {
return {
locator_to_show: locator,

View File

@@ -135,10 +135,7 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
*/
addButtonActions: function(element) {
var self = this;
element.find('.delete-button').click(function(event) {
event.preventDefault();
self.deleteXBlock($(event.target));
});
element.find('.delete-button').click(_.bind(this.handleDeleteEvent, this));
element.find('.add-button').click(_.bind(this.handleAddEvent, this));
},
@@ -203,6 +200,14 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
this.initialState = null;
},
/**
* Refresh the view's model from the server, which will cause the view to refresh.
* @returns {jQuery promise} A promise representing the refresh operation.
*/
refresh: function() {
return this.model.fetch();
},
onChildAdded: function(locator, category) {
// For units, redirect to the new page, and for everything else just refresh inline.
if (category === 'vertical') {
@@ -220,23 +225,17 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
this.refresh();
},
deleteXBlock: function() {
var parentView = this.parentView;
handleDeleteEvent: function(event) {
var self = this,
parentView = this.parentView;
event.preventDefault();
XBlockViewUtils.deleteXBlock(this.model).done(function() {
if (parentView) {
parentView.onChildDeleted();
parentView.onChildDeleted(self, event);
}
});
},
/**
* Refresh the view's model from the server, which will cause the view to refresh.
* @returns {jQuery promise} A promise representing the refresh operation.
*/
refresh: function() {
return this.model.fetch();
},
handleAddEvent: function(event) {
var self = this,
target = $(event.target),