Fix #1623 Can not display empty admin fields list

This commit is contained in:
Nicolas Le Goff
2013-12-16 14:10:03 +01:00
parent 816a53a54e
commit 060d6d9fdb
3 changed files with 20 additions and 5 deletions

View File

@@ -189,12 +189,16 @@ define([
// get previous index if exists else next index - 1 as item is being deleted // get previous index if exists else next index - 1 as item is being deleted
var index = previousIndex ? previousIndex : (nextIndex ? nextIndex - 1 : -1); var index = previousIndex ? previousIndex : (nextIndex ? nextIndex - 1 : -1);
modalView.render(); modalView.render();
modalView.on("modal:confirm", function () { modalView.on("modal:confirm", function () {
AdminFieldApp.fieldsToDelete.push(self.model); AdminFieldApp.fieldsToDelete.push(self.model);
AdminFieldApp.fieldListView.collection.remove(self.model); AdminFieldApp.fieldListView.collection.remove(self.model);
self._selectModelView(index); // last item is deleted
if (index < 0) {
self.remove();
} else {
self._selectModelView(index);
}
// Enable state button, models is out of sync // Enable state button, models is out of sync
AdminFieldApp.saveView.updateStateButton(false); AdminFieldApp.saveView.updateStateButton(false);
}); });

View File

@@ -28,7 +28,7 @@ define([
this.itemViews = []; this.itemViews = [];
// force base 1 indexed // force base 1 indexed
if (this.collection.first().get("sorter") === 0) { if (this.collection.length > 0 && this.collection.first().get("sorter") === 0) {
this.collection.each(function (model) { this.collection.each(function (model) {
model.set({'sorter': model.get("sorter") + 1}, {silent: true}); model.set({'sorter': model.get("sorter") + 1}, {silent: true});
}); });

View File

@@ -85,14 +85,25 @@ define([
return this; return this;
}, },
updateStateButton: function (disable) { updateStateButton: function (disable) {
var toDisable = disable || !this._isModelDesync(); var toDisable = !this._isModelDesync();
if ("undefined" !== typeof disable) {
toDisable = disable;
}
this._disableSaveButton(toDisable); this._disableSaveButton(toDisable);
}, },
// check whether model has changed or not // check whether model has changed or not
_isModelDesync: function () { _isModelDesync: function () {
return "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function (model) { var fieldToDelete = false;
var fieldToUpdate = false;
fieldToUpdate = "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function (model) {
return !_.isEmpty(model.previousAttributes()); return !_.isEmpty(model.previousAttributes());
}); });
fieldToDelete = AdminFieldApp.fieldsToDelete.length > 0;
return fieldToUpdate || fieldToDelete;
}, },
// create a transparent overlay on top of the application // create a transparent overlay on top of the application
_overlay: function (showOrHide) { _overlay: function (showOrHide) {