mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 12:33:26 +00:00
Fix #1267 List is not renumbered after delete & Fix #1264 Can not add field, if there is no field in database
This commit is contained in:
@@ -30,6 +30,7 @@ define([
|
||||
// rerender whenever there is a change on the collection
|
||||
this.collection.bind("reset", this.render, this);
|
||||
this.collection.bind("add", this.render, this);
|
||||
this.collection.bind("remove", this._onRemove, this);
|
||||
this.collection.bind("remove", this.render, this);
|
||||
|
||||
AdminFieldApp.errorManager.on('add-error', function(error) {
|
||||
@@ -112,15 +113,27 @@ define([
|
||||
|
||||
return this;
|
||||
},
|
||||
_onRemove : function (model) {
|
||||
var models = [];
|
||||
this.collection.each(function(m) {
|
||||
if (m.get("sorter") > model.get("sorter")) {
|
||||
m.set("sorter", m.get("sorter") - 1);
|
||||
}
|
||||
|
||||
models.push(m);
|
||||
});
|
||||
|
||||
this.collection.reset(models);
|
||||
},
|
||||
updateSortAction: function(event, model, ui) {
|
||||
var newPosition = ui.item.index();
|
||||
this.collection.remove(model, {silent: true});
|
||||
this.collection.each(function (model, index) {
|
||||
var ordinal = index;
|
||||
if (index >= newPosition) ordinal += 1;
|
||||
if (index >= newPosition) ordinal += 2; else ordinal += 1;
|
||||
model.set({'sorter': ordinal}, {silent: true});
|
||||
});
|
||||
model.set({'sorter': newPosition}, {silent: true});
|
||||
model.set({'sorter': newPosition + 1}, {silent: true});
|
||||
this.collection.add(model, {at: newPosition});
|
||||
|
||||
this.itemViews[0].animate(Math.abs(ui.firstItemPosition));
|
||||
|
Reference in New Issue
Block a user