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:
Nicolas Le Goff
2013-07-10 19:24:19 +02:00
parent 14949cb619
commit 68ebcfddb5
8 changed files with 73 additions and 50 deletions

View File

@@ -970,8 +970,9 @@ class databox_field implements cache_cacheableInterface
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
if ($row) if ($row) {
$sorter = (int) $row['sorter']; $sorter = max(1, (int) $row['sorter']);
}
$sql = "INSERT INTO metadatas_structure $sql = "INSERT INTO metadatas_structure
(`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`, (`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`,

View File

@@ -4,7 +4,7 @@
</script> </script>
<script type="text/template" id="save_template"> <script type="text/template" id="save_template">
<button type="button" class="btn btn-large btn-success save-all"> <button type="button" class="btn btn-success save-all">
<i class="icon-hdd icon-white"></i> {% trans %}Save all changes{% endtrans %} <i class="icon-hdd icon-white"></i> {% trans %}Save all changes{% endtrans %}
</button> </button>
</script> </script>
@@ -248,7 +248,7 @@
</tr> </tr>
<tr> <tr>
<td class="position"> <td class="position">
<%= position + 1 %> <%= position %>
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -24,12 +24,13 @@ define([
DcFieldsCollection, FieldListView, SaveView, FieldErrorView, ErrorManager) { DcFieldsCollection, FieldListView, SaveView, FieldErrorView, ErrorManager) {
var initialize = function() { var initialize = function() {
AdminFieldApp = { AdminFieldApp = {
$window : $(window), $window : $(window),
$scope : $("#admin-field-app"), $scope : $("#admin-field-app"),
$top : $(".row-top", this.$scope), $top : $(".row-top", this.$scope),
$bottom : $(".row-bottom", this.$scope), $bottom : $(".row-bottom", this.$scope),
$leftBlock : $(".left-block", this.$bottom), $leftBlock : $(".left-block", this.$bottom),
$rightBlock : $(".right-block", this.$bottom), $rightBlock : $(".right-block", this.$bottom),
fieldsToDelete : [],
resizeListBlock: function () { resizeListBlock: function () {
var listBlock = $(".list-block", AdminFieldApp.$leftBlock); var listBlock = $(".list-block", AdminFieldApp.$leftBlock);
listBlock.height(AdminFieldApp.$window.height() - listBlock.offset().top - 10); listBlock.height(AdminFieldApp.$window.height() - listBlock.offset().top - 10);
@@ -92,7 +93,9 @@ define([
AdminFieldApp.$window.trigger("resize"); AdminFieldApp.$window.trigger("resize");
// click on first item list // click on first item list
_.first(AdminFieldApp.fieldListView.itemViews).clickAction().animate(); if (AdminFieldApp.fieldListView.itemViews.length > 0 ) {
_.first(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
}
} }
); );
}; };

View File

@@ -122,10 +122,7 @@ define([
"label_fr" : $("#new-label_fr", this.$el).val(), "label_fr" : $("#new-label_fr", this.$el).val(),
"label_de" : $("#new-label_de", this.$el).val(), "label_de" : $("#new-label_de", this.$el).val(),
"label_nl" : $("#new-label_nl", this.$el).val(), "label_nl" : $("#new-label_nl", this.$el).val(),
"multi": $("#new-multivalued", this.$el).is(":checked"), "multi": $("#new-multivalued", this.$el).is(":checked")
"sorter": AdminFieldApp.fieldsCollection.max(function(model) {
return model.get("sorter");
}).get("sorter") + 1
}); });
field.save(null, { field.save(null, {

View File

@@ -183,23 +183,10 @@ define([
modalView.render(); modalView.render();
modalView.on("modal:confirm", function() { modalView.on("modal:confirm", function() {
self.model.destroy({ AdminFieldApp.fieldsToDelete.push(self.model);
success: function(model, response) { AdminFieldApp.fieldListView.collection.remove(self.model);
AdminFieldApp.fieldListView.collection.remove(self.model); self._selectModelView(index);
self._selectModelView(index); AdminFieldApp.saveView.updateStateButton();
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();
}
});
}); });
return this; return this;

View File

@@ -30,6 +30,7 @@ define([
// rerender whenever there is a change on the collection // rerender whenever there is a change on the collection
this.collection.bind("reset", this.render, this); this.collection.bind("reset", this.render, this);
this.collection.bind("add", this.render, this); this.collection.bind("add", this.render, this);
this.collection.bind("remove", this._onRemove, this);
this.collection.bind("remove", this.render, this); this.collection.bind("remove", this.render, this);
AdminFieldApp.errorManager.on('add-error', function(error) { AdminFieldApp.errorManager.on('add-error', function(error) {
@@ -112,15 +113,27 @@ define([
return this; 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) { updateSortAction: function(event, model, ui) {
var newPosition = ui.item.index(); var newPosition = ui.item.index();
this.collection.remove(model, {silent: true}); this.collection.remove(model, {silent: true});
this.collection.each(function (model, index) { this.collection.each(function (model, index) {
var ordinal = 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': ordinal}, {silent: true});
}); });
model.set({'sorter': newPosition}, {silent: true}); model.set({'sorter': newPosition + 1}, {silent: true});
this.collection.add(model, {at: newPosition}); this.collection.add(model, {at: newPosition});
this.itemViews[0].animate(Math.abs(ui.firstItemPosition)); this.itemViews[0].animate(Math.abs(ui.firstItemPosition));

View File

@@ -37,24 +37,41 @@ define([
if (this._isModelDesync()) { if (this._isModelDesync()) {
this._loadingState(true); this._loadingState(true);
AdminFieldApp.fieldsCollection.save({ $.when.apply($, _.map(AdminFieldApp.fieldsToDelete, function(m){
success: function(fields) { return m.destroy({
// reset collection with new one success: function(model, response) {
AdminFieldApp.fieldsCollection.reset(fields); 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({ new AlertView({
alert: "success", alert: "success",
message: i18n.t("fields_save") message: i18n.t("fields_save")
}).render(); }).render();
}, },
error: function(xhr, textStatus, errorThrown) { error: function(xhr, textStatus, errorThrown) {
new AlertView({ new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong") alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render(); }).render();
}
}).done(function() {
self._loadingState(false);
});
} }
}).done(function() { );
self._loadingState(false);
});
} }
return this; return this;

View File

@@ -53,6 +53,7 @@
#admin-field-app #collection-fields li table { #admin-field-app #collection-fields li table {
table-layout: fixed; table-layout: fixed;
width: 100%; width: 100%;
height: 100%;
} }
#admin-field-app #collection-fields li .field-name { #admin-field-app #collection-fields li .field-name {
@@ -221,6 +222,10 @@
font-weight: bold font-weight: bold
} }
#admin-field-app .save-all{
padding: 15px;
}
#admin-field-app .overlay { #admin-field-app .overlay {
zoom: 1; zoom: 1;
filter: alpha(opacity=50); filter: alpha(opacity=50);