mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
@@ -114,25 +114,22 @@ define([
|
|||||||
},
|
},
|
||||||
updateSortAction: function(event, model, ui) {
|
updateSortAction: function(event, model, ui) {
|
||||||
var newPosition = ui.item.index();
|
var newPosition = ui.item.index();
|
||||||
var curPosition = this.collection.indexOf(model);
|
this.collection.remove(model, {silent: true});
|
||||||
|
this.collection.each(function (model, index) {
|
||||||
// reorder all collection model
|
var ordinal = index;
|
||||||
this.collection.each(function(el, index) {
|
if (index >= newPosition) ordinal += 1;
|
||||||
if (newPosition > curPosition && (index > curPosition && index <= curPosition)) index -= 1;
|
model.set({'sorter': ordinal}, {silent: true});
|
||||||
else if (newPosition < curPosition && (index >= curPosition && index < curPosition)) index += 1;
|
|
||||||
|
|
||||||
el.set("sorter", index);
|
|
||||||
});
|
});
|
||||||
|
model.set({'sorter': newPosition}, {silent: true});
|
||||||
this.render();
|
this.collection.add(model, {at: newPosition});
|
||||||
|
|
||||||
this.itemViews[0].animate(Math.abs(ui.firstItemPosition));
|
this.itemViews[0].animate(Math.abs(ui.firstItemPosition));
|
||||||
|
|
||||||
// update edit view model
|
// update edit view model
|
||||||
AdminFieldApp.fieldEditView.model = this.collection.find(function(el) {
|
AdminFieldApp.fieldEditView.updateModel(this.collection.find(function(el) {
|
||||||
return el.get("id") === AdminFieldApp.fieldEditView.model.get("id");
|
return el.get("id") === AdminFieldApp.fieldEditView.model.get("id");
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
AdminFieldApp.fieldEditView.render();
|
||||||
AdminFieldApp.saveView.updateStateButton();
|
AdminFieldApp.saveView.updateStateButton();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@@ -304,7 +304,7 @@ define([
|
|||||||
it("should reorder collection on drop action", function() {
|
it("should reorder collection on drop action", function() {
|
||||||
var ui = {item: {index: function() {return 2;}}};
|
var ui = {item: {index: function() {return 2;}}};
|
||||||
AdminFieldApp.fieldListView.itemViews[0].dropAction({},ui);
|
AdminFieldApp.fieldListView.itemViews[0].dropAction({},ui);
|
||||||
assert.equal(AdminFieldApp.fieldListView.collection.last().get('sorter'), 3, 'model is updated');
|
assert.equal(AdminFieldApp.fieldListView.collection.last().get('sorter'), 2, 'model is updated');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user