mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 04:53: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:
@@ -24,12 +24,13 @@ define([
|
||||
DcFieldsCollection, FieldListView, SaveView, FieldErrorView, ErrorManager) {
|
||||
var initialize = function() {
|
||||
AdminFieldApp = {
|
||||
$window : $(window),
|
||||
$scope : $("#admin-field-app"),
|
||||
$top : $(".row-top", this.$scope),
|
||||
$bottom : $(".row-bottom", this.$scope),
|
||||
$leftBlock : $(".left-block", this.$bottom),
|
||||
$rightBlock : $(".right-block", this.$bottom),
|
||||
$window : $(window),
|
||||
$scope : $("#admin-field-app"),
|
||||
$top : $(".row-top", this.$scope),
|
||||
$bottom : $(".row-bottom", this.$scope),
|
||||
$leftBlock : $(".left-block", this.$bottom),
|
||||
$rightBlock : $(".right-block", this.$bottom),
|
||||
fieldsToDelete : [],
|
||||
resizeListBlock: function () {
|
||||
var listBlock = $(".list-block", AdminFieldApp.$leftBlock);
|
||||
listBlock.height(AdminFieldApp.$window.height() - listBlock.offset().top - 10);
|
||||
@@ -92,7 +93,9 @@ define([
|
||||
AdminFieldApp.$window.trigger("resize");
|
||||
|
||||
// click on first item list
|
||||
_.first(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
|
||||
if (AdminFieldApp.fieldListView.itemViews.length > 0 ) {
|
||||
_.first(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
@@ -122,10 +122,7 @@ define([
|
||||
"label_fr" : $("#new-label_fr", this.$el).val(),
|
||||
"label_de" : $("#new-label_de", this.$el).val(),
|
||||
"label_nl" : $("#new-label_nl", this.$el).val(),
|
||||
"multi": $("#new-multivalued", this.$el).is(":checked"),
|
||||
"sorter": AdminFieldApp.fieldsCollection.max(function(model) {
|
||||
return model.get("sorter");
|
||||
}).get("sorter") + 1
|
||||
"multi": $("#new-multivalued", this.$el).is(":checked")
|
||||
});
|
||||
|
||||
field.save(null, {
|
||||
|
@@ -183,23 +183,10 @@ define([
|
||||
|
||||
modalView.render();
|
||||
modalView.on("modal:confirm", function() {
|
||||
self.model.destroy({
|
||||
success: function(model, response) {
|
||||
AdminFieldApp.fieldListView.collection.remove(self.model);
|
||||
self._selectModelView(index);
|
||||
|
||||
new AlertView({alert: "info", message: i18n.t("deleted_success", {
|
||||
postProcess: "sprintf",
|
||||
sprintf: [model.get("name")]
|
||||
})
|
||||
}).render();
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
new AlertView({
|
||||
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
|
||||
}).render();
|
||||
}
|
||||
});
|
||||
AdminFieldApp.fieldsToDelete.push(self.model);
|
||||
AdminFieldApp.fieldListView.collection.remove(self.model);
|
||||
self._selectModelView(index);
|
||||
AdminFieldApp.saveView.updateStateButton();
|
||||
});
|
||||
|
||||
return this;
|
||||
|
@@ -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));
|
||||
|
@@ -37,24 +37,41 @@ define([
|
||||
|
||||
if (this._isModelDesync()) {
|
||||
this._loadingState(true);
|
||||
AdminFieldApp.fieldsCollection.save({
|
||||
success: function(fields) {
|
||||
// reset collection with new one
|
||||
AdminFieldApp.fieldsCollection.reset(fields);
|
||||
$.when.apply($, _.map(AdminFieldApp.fieldsToDelete, function(m){
|
||||
return m.destroy({
|
||||
success: function(model, response) {
|
||||
AdminFieldApp.fieldsToDelete = _.filter(AdminFieldApp.fieldsToDelete, function(m){
|
||||
return model.get("id") !== m.get("id");
|
||||
});
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
new AlertView({
|
||||
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
|
||||
}).render();
|
||||
}
|
||||
});
|
||||
})).done(
|
||||
function() {
|
||||
AdminFieldApp.fieldsCollection.save({
|
||||
success: function(fields) {
|
||||
// reset collection with new one
|
||||
AdminFieldApp.fieldsCollection.reset(fields);
|
||||
|
||||
new AlertView({
|
||||
alert: "success",
|
||||
message: i18n.t("fields_save")
|
||||
}).render();
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
new AlertView({
|
||||
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
|
||||
}).render();
|
||||
new AlertView({
|
||||
alert: "success",
|
||||
message: i18n.t("fields_save")
|
||||
}).render();
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
new AlertView({
|
||||
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
|
||||
}).render();
|
||||
}
|
||||
}).done(function() {
|
||||
self._loadingState(false);
|
||||
});
|
||||
}
|
||||
}).done(function() {
|
||||
self._loadingState(false);
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
Reference in New Issue
Block a user