Fix JS codestyle

This commit is contained in:
Romain Neutron
2013-11-12 12:49:23 +01:00
parent 51fb364d13
commit 9fa95db23c
78 changed files with 5184 additions and 6309 deletions

View File

@@ -19,19 +19,17 @@ define([
"apps/admin/fields/views/save",
"apps/admin/fields/views/fieldError",
"apps/admin/fields/errors/errorManager"
], function(
$, _, Backbone, i18n, FieldsCollection, VocabulariesCollection,
DcFieldsCollection, FieldListView, SaveView, FieldErrorView, ErrorManager) {
var initialize = function() {
], function ($, _, Backbone, i18n, FieldsCollection, VocabulariesCollection, 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),
fieldsToDelete : [],
lng : function() {
$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: [],
lng: function () {
return typeof p4 === "undefined" ? "en" : (p4.lng || "en");
},
resizeListBlock: function () {
@@ -56,7 +54,7 @@ define([
// initiliaze collections
AdminFieldApp.fieldsCollection = new FieldsCollection(null, {
sbas_id : AdminFieldApp.sbas_id
sbas_id: AdminFieldApp.sbas_id
});
AdminFieldApp.vocabularyCollection = new VocabulariesCollection();
AdminFieldApp.dcFieldsCollection = new DcFieldsCollection();
@@ -71,12 +69,12 @@ define([
AdminFieldApp.dcFieldsCollection.fetch(),
$.ajax({
url: '/available-languages',
success: function(languages) {
success: function (languages) {
AdminFieldApp.languages = languages;
}
})
]).done(
function() {
function () {
// register views
AdminFieldApp.saveView = new SaveView({
el: $(".save-block", AdminFieldApp.scope)
@@ -96,7 +94,7 @@ define([
AdminFieldApp.$window.trigger("resize");
// click on first item list
if (AdminFieldApp.fieldListView.itemViews.length > 0 ) {
if (AdminFieldApp.fieldListView.itemViews.length > 0) {
_.first(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
}
}

View File

@@ -11,13 +11,13 @@ define([
"underscore",
"backbone",
"models/dcField"
], function(_, Backbone, DcFieldModel) {
], function (_, Backbone, DcFieldModel) {
var DcFieldCollection = Backbone.Collection.extend({
model: DcFieldModel,
url: function() {
url: function () {
return "/admin/fields/dc-fields";
},
comparator: function(item) {
comparator: function (item) {
return item.get("label");
}
});

View File

@@ -11,9 +11,9 @@ define([
"underscore",
"backbone",
"models/field"
], function(_, Backbone, FieldModel) {
], function (_, Backbone, FieldModel) {
var FieldCollection = Backbone.Collection.extend({
initialize: function(models, options) {
initialize: function (models, options) {
options = options || {};
if (typeof options === "object" && false === "sbas_id" in options) {
throw "You must set a sbas id"
@@ -21,23 +21,23 @@ define([
this.sbasId = options.sbas_id;
},
model: FieldModel,
url: function() {
url: function () {
return "/admin/fields/" + this.sbasId + "/fields";
},
search: function(letters) {
search: function (letters) {
if (letters === "")
return this;
var pattern = new RegExp(letters, "gi");
return _(this.filter(function(data) {
return _(this.filter(function (data) {
return pattern.test(data.get("name"));
}));
},
comparator: function(item) {
comparator: function (item) {
return item.get("sorter");
},
nextIndex: function(model) {
nextIndex: function (model) {
var index = this.indexOf(model);
if (index < 0) {
@@ -50,7 +50,7 @@ define([
return index + 1;
},
previousIndex: function(model) {
previousIndex: function (model) {
var index = this.indexOf(model);
if (index < 0) {
@@ -64,7 +64,7 @@ define([
return index - 1;
},
// save all collection
save: function(options) {
save: function (options) {
return Backbone.sync("update", this, options || {});
}
});

View File

@@ -11,13 +11,13 @@ define([
"underscore",
"backbone",
"models/vocabulary"
], function(_, Backbone, VocabularyModel) {
], function (_, Backbone, VocabularyModel) {
var VocabularyCollection = Backbone.Collection.extend({
model: VocabularyModel,
url: function() {
url: function () {
return "/admin/fields/vocabularies";
},
comparator: function(item) {
comparator: function (item) {
return item.get("name");
}
});

View File

@@ -10,7 +10,7 @@
define([
"jquery",
"underscore"
], function($, _) {
], function ($, _) {
var Error = function (model, fieldId, message) {
this.model = model;

View File

@@ -12,9 +12,9 @@ define([
"underscore",
"backbone",
"apps/admin/fields/errors/errorModel"
], function($, _, Backbone, ErrorModel) {
], function ($, _, Backbone, ErrorModel) {
var ErrorManager = function() {
var ErrorManager = function () {
this.errors = {};
_.extend(this, Backbone.Events);
};
@@ -38,8 +38,8 @@ define([
containsModelError: function (model) {
return "undefined" !== typeof this.errors[model.get("id")];
},
addModelFieldError: function(error) {
if (! error instanceof Error) {
addModelFieldError: function (error) {
if (!error instanceof Error) {
throw "Item must be an error object";
}
@@ -56,7 +56,7 @@ define([
return this;
},
removeModelFieldError: function(model, fieldId) {
removeModelFieldError: function (model, fieldId) {
var modelError = this.getModelError(model);
if (modelError) {
@@ -72,7 +72,7 @@ define([
}
}
},
clearModelFieldErrors: function(model, fieldId) {
clearModelFieldErrors: function (model, fieldId) {
var modelError = this.getModelError(model);
if (modelError) {
@@ -93,7 +93,7 @@ define([
return false;
},
getModelFieldError: function(model, fieldId) {
getModelFieldError: function (model, fieldId) {
var modelError = this.getModelError(model);
if (modelError) {
@@ -102,7 +102,7 @@ define([
return null;
},
clearAll: function() {
clearAll: function () {
this.errors = {};
this.trigger("no-error");
},
@@ -120,8 +120,8 @@ define([
},
all: function () {
var errors = [];
_.each(this.errors, function(modelErrors) {
_.each(modelErrors.all(), function(error) {
_.each(this.errors, function (modelErrors) {
_.each(modelErrors.all(), function (error) {
errors.push(error);
});
});

View File

@@ -10,21 +10,21 @@
define([
"jquery",
"underscore"
], function($, _) {
var ErrorModel = function(id) {
], function ($, _) {
var ErrorModel = function (id) {
this.id = id;
this.errors = {};
};
ErrorModel.prototype = {
add: function(id, error) {
if (! error instanceof Error) {
add: function (id, error) {
if (!error instanceof Error) {
throw "Item must be an error object";
}
this.errors[id] = error;
},
get: function(id) {
get: function (id) {
if (this.has(id)) {
return this.errors[id];
}
@@ -33,12 +33,12 @@ define([
has: function (id) {
return "undefined" !== typeof this.errors[id];
},
remove: function(id) {
remove: function (id) {
if (this.has(id)) {
delete this.errors[id];
}
},
count: function() {
count: function () {
var count = 0;
for (var k in this.errors) {
if (this.errors.hasOwnProperty(k)) {

View File

@@ -19,7 +19,7 @@ require.config({
bootstrap: "../skins/build/bootstrap/js/bootstrap.min"
},
shim: {
bootstrap : ["jquery"],
bootstrap: ["jquery"],
jqueryui: {
deps: [ "jquery" ]
}
@@ -27,6 +27,6 @@ require.config({
});
// launch application
require(["apps/admin/fields/app"], function(App) {
require(["apps/admin/fields/app"], function (App) {
App.initialize();
});

View File

@@ -13,11 +13,11 @@ define([
"backbone",
"i18n",
"bootstrap"
], function($, _, Backbone, i18n, bootstrap) {
], function ($, _, Backbone, i18n, bootstrap) {
var AlertView = Backbone.View.extend({
tagName: "div",
className: "alert",
initialize: function(options) {
initialize: function (options) {
var self = this;
if (options) {
@@ -30,7 +30,7 @@ define([
self.remove();
});
},
render: function() {
render: function () {
var self = this;
var template = _.template($("#alert_template").html(), {
msg: this.message
@@ -39,7 +39,9 @@ define([
this.$el.addClass("alert-" + this.alert).html(template).alert();
if (this.delay > 0) {
window.setTimeout(function() { self.$el.alert('close') }, this.delay);
window.setTimeout(function () {
self.$el.alert('close')
}, this.delay);
}
$(".block-alert").empty().append(this.$el);

View File

@@ -15,31 +15,31 @@ define([
"bootstrap",
"apps/admin/fields/views/alert",
"models/field"
], function($, _, Backbone, i18n, bootstrap, AlertView, FieldModel) {
], function ($, _, Backbone, i18n, bootstrap, AlertView, FieldModel) {
var CreateView = Backbone.View.extend({
tagName: "div",
events: {
"click .btn-submit-field": "createAction",
"click .btn-add-field": "toggleCreateFormAction",
"click .btn-cancel-field": "toggleCreateFormAction",
"keyup input": "onKeyupInput"
"keyup input": "onKeyupInput"
},
render: function() {
render: function () {
var template = _.template($("#create_template").html());
this.$el.html(template);
$("#new-source", this.$el).autocomplete({
minLength: 2,
source: function(request, response) {
source: function (request, response) {
$.ajax({
url: "/admin/fields/tags/search",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
success: function (data) {
response($.map(data, function (item) {
return {
label: item.label,
value: item.value
@@ -59,7 +59,7 @@ define([
.find(".help-block")
.empty();
},
createAction: function(event) {
createAction: function (event) {
var self = this;
var formErrors = 0;
@@ -81,7 +81,7 @@ define([
}
// check for duplicate field name
if ("undefined" !== typeof AdminFieldApp.fieldsCollection.find(function(model){
if ("undefined" !== typeof AdminFieldApp.fieldsCollection.find(function (model) {
return model.get("name").toLowerCase() === fieldNameValue.toLowerCase();
})) {
fieldName
@@ -118,7 +118,7 @@ define([
formErrors++;
}
if (formErrors > 0 ) {
if (formErrors > 0) {
return;
}
@@ -126,15 +126,15 @@ define([
"sbas-id": AdminFieldApp.sbas_id,
"name": fieldNameValue,
"tag": fieldTagValue,
"label_en" : $("#new-label_en", this.$el).val(),
"label_fr" : $("#new-label_fr", this.$el).val(),
"label_de" : $("#new-label_de", this.$el).val(),
"label_nl" : $("#new-label_nl", this.$el).val(),
"label_en": $("#new-label_en", this.$el).val(),
"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")
});
field.save(null, {
success: function(field, response, options) {
success: function (field, response, options) {
AdminFieldApp.fieldsCollection.add(field);
_.last(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
@@ -144,7 +144,7 @@ define([
})
}).render();
},
error: function(xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")}
).render();
@@ -155,7 +155,7 @@ define([
return this;
},
toggleCreateFormAction: function(event) {
toggleCreateFormAction: function (event) {
var fieldBlock = $(".add-field-block", this.$el);
var addBtn = $(".btn-add-field", this.$el);

View File

@@ -17,22 +17,22 @@ define([
"apps/admin/fields/views/modal",
"apps/admin/fields/views/dcField",
"apps/admin/fields/errors/error"
], function($, _, Backbone, i18n, MultiViews, AlertView, ModalView, DcFieldView, Error) {
], function ($, _, Backbone, i18n, MultiViews, AlertView, ModalView, DcFieldView, Error) {
// Add multiview methods
var FieldEditView = Backbone.View.extend(_.extend({}, MultiViews, {
tagName: "div",
className: "field-edit",
initialize: function() {
initialize: function () {
this.model.on("change", this._onModelChange, this);
},
updateModel: function(model) {
updateModel: function (model) {
// unbind event to previous model
this.model.off("change");
this.model = model;
return this;
},
render: function() {
render: function () {
var self = this;
var template = _.template($("#edit_template").html(), {
lng: AdminFieldApp.lng(),
@@ -45,7 +45,7 @@ define([
this.$el.empty().html(template);
this._assignView({
".dc-fields-subview" : new DcFieldView({
".dc-fields-subview": new DcFieldView({
collection: AdminFieldApp.dcFieldsCollection,
field: this.model
})
@@ -53,15 +53,15 @@ define([
var completer = $("#tag", this.$el).autocomplete({
minLength: 2,
source: function(request, response) {
source: function (request, response) {
$.ajax({
url: "/admin/fields/tags/search",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
success: function (data) {
response($.map(data, function (item) {
return {
label: item.label,
value: item.value
@@ -70,7 +70,7 @@ define([
}
});
},
close: function(e) {
close: function (e) {
self.tagFieldChangedAction(e);
}
});
@@ -95,7 +95,7 @@ define([
"change select": "selectionChangedAction",
"click .lng-label a": "_toggleLabels"
},
triggerControlledVocabulary: function(e) {
triggerControlledVocabulary: function (e) {
if ($(e.target, this.$el).find("option:selected").val() === "") {
this.model.set("vocabulary-type", false);
this.render();
@@ -105,7 +105,7 @@ define([
this.render();
}
},
selectionChangedAction: function(e) {
selectionChangedAction: function (e) {
var field = $(e.target);
var data = {};
data[field.attr("id")] = $("option:selected", field).val();
@@ -113,7 +113,7 @@ define([
return this;
},
fieldChangedAction: function(e) {
fieldChangedAction: function (e) {
var field = $(e.target);
var fieldId = field.attr("id");
var data = {};
@@ -122,7 +122,7 @@ define([
return this;
},
labelChangedAction: function(e) {
labelChangedAction: function (e) {
var field = $(e.target);
var fieldId = field.attr("id");
var data = this.model.get("labels");
@@ -133,13 +133,13 @@ define([
return this;
},
tagFieldChangedAction: function(e) {
tagFieldChangedAction: function (e) {
var $this = this;
var fieldTag = $(e.target);
var fieldTagId = fieldTag.attr("id");
var fieldTagValue = fieldTag.val();
var onFieldValid = function() {
var onFieldValid = function () {
if (fieldTag.closest(".control-group").hasClass("error")) {
// remove error
AdminFieldApp.errorManager.removeModelFieldError(
@@ -157,7 +157,7 @@ define([
}
if ("" !== fieldTagValue) {
var jqxhr = $.get( "/admin/fields/tags/"+fieldTagValue, onFieldValid).fail(function() {
var jqxhr = $.get("/admin/fields/tags/" + fieldTagValue, onFieldValid).fail(function () {
fieldTag
.closest(".control-group")
.addClass("error")
@@ -173,7 +173,7 @@ define([
onFieldValid();
}
},
deleteAction: function() {
deleteAction: function () {
var self = this;
var modalView = new ModalView({
model: this.model,
@@ -191,7 +191,7 @@ define([
var index = previousIndex ? previousIndex : (nextIndex ? nextIndex - 1 : -1);
modalView.render();
modalView.on("modal:confirm", function() {
modalView.on("modal:confirm", function () {
AdminFieldApp.fieldsToDelete.push(self.model);
AdminFieldApp.fieldListView.collection.remove(self.model);
self._selectModelView(index);
@@ -200,19 +200,19 @@ define([
return this;
},
_onModelChange: function() {
_onModelChange: function () {
AdminFieldApp.fieldListView.collection.remove(this.model, {silent: true});
AdminFieldApp.fieldListView.collection.add(this.model, {silent: true});
AdminFieldApp.saveView.updateStateButton();
},
// select temView by index in itemList
_selectModelView: function(index) {
_selectModelView: function (index) {
// select previous or next itemview
if (index >= 0) {
AdminFieldApp.fieldListView.itemViews[index].select().animate().click();
}
},
_toggleLabels: function(event) {
_toggleLabels: function (event) {
event.preventDefault();
var curLabel = $(event.target);
$('.lng-label', this.$el).removeClass("select");

View File

@@ -12,20 +12,20 @@ define([
"underscore",
"backbone",
"i18n"
], function($, _, Backbone, i18n) {
], function ($, _, Backbone, i18n) {
var FieldErrorView = Backbone.View.extend({
initialize: function() {
initialize: function () {
AdminFieldApp.errorManager.on("add-error", this.render, this);
AdminFieldApp.errorManager.on("remove-error", this.render, this);
},
render: function() {
render: function () {
var messages = [];
var errors = AdminFieldApp.errorManager.all();
_.each(_.groupBy(errors, function(error) {
_.each(_.groupBy(errors, function (error) {
return error.model.get("name");
}), function(groupedErrors) {
_.each(groupedErrors, function(error) {
}), function (groupedErrors) {
_.each(groupedErrors, function (error) {
messages.push(i18n.t("field_error", {
postProcess: "sprintf",
sprintf: [error.model.get("name")]

View File

@@ -16,13 +16,13 @@ define([
"common/multiviews",
"apps/admin/fields/views/listRow",
"apps/admin/fields/views/create"
], function($, jqueryui, _, Backbone, i18n, MultiViews, FieldListRowView, CreateView) {
], function ($, jqueryui, _, Backbone, i18n, MultiViews, FieldListRowView, CreateView) {
var FieldListView = Backbone.View.extend(_.extend({}, MultiViews, {
events: {
"keyup #live_search": "searchAction",
"update-sort": "updateSortAction"
},
initialize: function() {
initialize: function () {
var self = this;
// store all single rendered views
this.itemViews = [];
@@ -40,9 +40,9 @@ define([
this.collection.bind("remove", this._onRemove, this);
this.collection.bind("remove", this.render, this);
AdminFieldApp.errorManager.on('add-error', function(error) {
AdminFieldApp.errorManager.on('add-error', function (error) {
var model = error.model;
var itemView = _.find(self.itemViews, function(view) {
var itemView = _.find(self.itemViews, function (view) {
return model.get('id') === view.model.get('id');
});
@@ -51,8 +51,8 @@ define([
}
});
AdminFieldApp.errorManager.on('remove-error', function(model) {
var itemView = _.find(self.itemViews, function(view) {
AdminFieldApp.errorManager.on('remove-error', function (model) {
var itemView = _.find(self.itemViews, function (view) {
return model.get('id') === view.model.get('id');
});
@@ -61,7 +61,7 @@ define([
}
});
},
render: function() {
render: function () {
var template = _.template($("#item_list_view_template").html());
this.$el.empty().html(template);
@@ -71,7 +71,7 @@ define([
this._renderList(this.collection);
this._assignView({
".create-subview" : new CreateView()
".create-subview": new CreateView()
});
AdminFieldApp.resizeListBlock();
@@ -79,13 +79,13 @@ define([
return this;
},
// render list by appending single item view, also fill itemViews
_renderList: function(fields) {
_renderList: function (fields) {
var that = this;
this.$listEl.empty();
this.itemViews = [];
fields.each(function(field) {
fields.each(function (field) {
var fieldErrors = AdminFieldApp.errorManager.getModelError(field);
var singleView = new FieldListRowView({
@@ -100,10 +100,10 @@ define([
this.$listEl.sortable({
handle: ".handle",
placeholder: "item-list-placeholder",
start: function(event, ui) {
start: function (event, ui) {
ui.item.addClass("border-bottom");
},
stop: function(event, ui) {
stop: function (event, ui) {
ui.firstItemPosition = $("li:first", $(this).sortable('widget')).position().top;
ui.item.trigger("drop", ui);
}
@@ -115,14 +115,14 @@ define([
return this;
},
searchAction: function(event) {
searchAction: function (event) {
this._renderList(this.collection.search($("#live_search", this.$el).val()));
return this;
},
_onRemove : function (model) {
_onRemove: function (model) {
var models = [];
this.collection.each(function(m) {
this.collection.each(function (m) {
if (m.get("sorter") > model.get("sorter")) {
m.set("sorter", m.get("sorter") - 1);
}
@@ -132,7 +132,7 @@ define([
this.collection.reset(models);
},
updateSortAction: function(event, model, ui) {
updateSortAction: function (event, model, ui) {
var newPosition = ui.item.index();
this.collection.remove(model, {silent: true});
this.collection.each(function (model, index) {
@@ -145,7 +145,7 @@ define([
this.itemViews[0].animate(Math.abs(ui.firstItemPosition));
// update edit view model
AdminFieldApp.fieldEditView.updateModel(this.collection.find(function(el) {
AdminFieldApp.fieldEditView.updateModel(this.collection.find(function (el) {
return el.get("id") === AdminFieldApp.fieldEditView.model.get("id");
}));

View File

@@ -12,18 +12,18 @@ define([
"underscore",
"backbone",
"apps/admin/fields/views/edit"
], function($, _, Backbone, FieldEditView) {
], function ($, _, Backbone, FieldEditView) {
var FieldListRowView = Backbone.View.extend({
tagName: "li",
className: "field-row",
initialize: function() {
initialize: function () {
// destroy view is model is deleted
this.model.on("change", this.onChange, this);
this.model.on("destroy", this.remove, this);
},
events : {
events: {
"click .trigger-click": "clickAction",
"drop" : "dropAction"
"drop": "dropAction"
},
clickAction: function (e) {
this.select();
@@ -33,7 +33,7 @@ define([
el: AdminFieldApp.$rightBlock,
model: this.model
});
} else {
} else {
AdminFieldApp.fieldEditView.updateModel(this.model).initialize();
}
@@ -41,17 +41,17 @@ define([
return this;
},
dropAction: function(event, ui) {
dropAction: function (event, ui) {
this.$el.trigger("update-sort", [this.model, ui]);
return this;
},
onChange: function() {
onChange: function () {
if (this.model.hasChanged("tag")) {
this.render();
}
},
render: function() {
render: function () {
var template = _.template($("#list_row_template").html(), {
id: this.model.get("id"),
position: this.model.get("sorter"),
@@ -76,7 +76,7 @@ define([
return this;
},
click: function() {
click: function () {
this.$el.find('.trigger-click').first().trigger('click');
return this;
},
@@ -96,7 +96,7 @@ define([
error: function (errored) {
if (errored) {
this.$el.addClass("error");
} else {
} else {
this.$el.removeClass("error");
}

View File

@@ -13,7 +13,7 @@ define([
"backbone",
"i18n",
"bootstrap"
], function($, _, Backbone, i18n, bootstrap) {
], function ($, _, Backbone, i18n, bootstrap) {
var ModalView = Backbone.View.extend({
tagName: "div",
className: "modal",
@@ -23,7 +23,7 @@ define([
initialize: function (options) {
var self = this;
// remove view when modal is closed
this.$el.on("hidden", function() {
this.$el.on("hidden", function () {
self.remove();
});
@@ -31,7 +31,7 @@ define([
this.message = options.message;
}
},
render: function() {
render: function () {
var template = _.template($("#modal_template").html(), {
msg: this.message || ""
});

View File

@@ -14,46 +14,46 @@ define([
"i18n",
"bootstrap",
"apps/admin/fields/views/alert"
], function($, _, Backbone, i18n, bootstrap, AlertView) {
], function ($, _, Backbone, i18n, bootstrap, AlertView) {
var SaveView = Backbone.View.extend({
initialize: function() {
initialize: function () {
var self = this;
this.previousAttributes = [];
this.$overlay = null;
AdminFieldApp.errorManager.on("add-error", function(errors) {
AdminFieldApp.errorManager.on("add-error", function (errors) {
self._disableSaveButton(true);
});
AdminFieldApp.errorManager.on("no-error", function() {
AdminFieldApp.errorManager.on("no-error", function () {
self._disableSaveButton(false);
});
},
events: {
"click button.save-all" : "clickSaveAction"
"click button.save-all": "clickSaveAction"
},
clickSaveAction: function(event) {
clickSaveAction: function (event) {
var self = this;
if (this._isModelDesync()) {
this._loadingState(true);
$.when.apply($, _.map(AdminFieldApp.fieldsToDelete, function(m){
$.when.apply($, _.map(AdminFieldApp.fieldsToDelete, function (m) {
return m.destroy({
success: function(model, response) {
AdminFieldApp.fieldsToDelete = _.filter(AdminFieldApp.fieldsToDelete, function(m){
success: function (model, response) {
AdminFieldApp.fieldsToDelete = _.filter(AdminFieldApp.fieldsToDelete, function (m) {
return model.get("id") !== m.get("id");
});
},
error: function(xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render();
}
});
})).done(
function() {
function () {
AdminFieldApp.fieldsCollection.save({
success: function(fields) {
success: function (fields) {
// reset collection with new one
AdminFieldApp.fieldsCollection.reset(fields);
@@ -63,12 +63,12 @@ define([
delay: 2000
}).render();
},
error: function(xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render();
}
}).done(function() {
}).done(function () {
self._loadingState(false);
});
}
@@ -84,18 +84,18 @@ define([
return this;
},
updateStateButton: function() {
updateStateButton: function () {
this._disableSaveButton(!this._isModelDesync());
},
// check whether model has changed or not
_isModelDesync: function () {
return "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function(model) {
return "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function (model) {
return !_.isEmpty(model.previousAttributes());
});
},
// create a transparent overlay on top of the application
_overlay: function(showOrHide) {
if(showOrHide && !this.$overlay) {
_overlay: function (showOrHide) {
if (showOrHide && !this.$overlay) {
this.$overlay = $("<div>").addClass("overlay");
AdminFieldApp.$bottom.append(this.$overlay);
} else if (!showOrHide && this.$overlay) {
@@ -107,7 +107,7 @@ define([
$("button.save-all", this.$el).attr("disabled", active);
},
// put application on loading state (add overlay, add spinner, disable global save button)
_loadingState: function(active) {
_loadingState: function (active) {
if (active) {
$(".save-block", AdminFieldApp.$top).addClass("loading");
$(".block-alert", AdminFieldApp.$top).empty();