mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
Add global register feature
Tweak admin field app Fix typo Tweaks Fix typo
This commit is contained in:

committed by
Romain Neutron

parent
9a9235a15e
commit
0539db7598
13
www/scripts/apps/admin/fields/errors/error.js
Normal file
13
www/scripts/apps/admin/fields/errors/error.js
Normal file
@@ -0,0 +1,13 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore"
|
||||
], function($, _) {
|
||||
|
||||
var Error = function (model, fieldId, message) {
|
||||
this.model = model;
|
||||
this.fieldId = fieldId;
|
||||
this.message = message;
|
||||
};
|
||||
|
||||
return Error;
|
||||
});
|
125
www/scripts/apps/admin/fields/errors/errorManager.js
Normal file
125
www/scripts/apps/admin/fields/errors/errorManager.js
Normal file
@@ -0,0 +1,125 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"backbone",
|
||||
"apps/admin/fields/errors/errorModel"
|
||||
], function($, _, Backbone, ErrorModel) {
|
||||
|
||||
var ErrorManager = function() {
|
||||
this.errors = {};
|
||||
_.extend(this, Backbone.Events);
|
||||
};
|
||||
|
||||
ErrorManager.prototype = {
|
||||
addModelError: function (model) {
|
||||
return this.errors[model.get("id")] = new ErrorModel(model.get("id"));
|
||||
},
|
||||
getModelError: function (model) {
|
||||
if (this.containsModelError(model)) {
|
||||
return this.errors[model.get("id")];
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
removeModelError: function (model) {
|
||||
if (this.containsModelError(model)) {
|
||||
delete this.errors[model.get("id")];
|
||||
}
|
||||
},
|
||||
containsModelError: function (model) {
|
||||
return "undefined" !== typeof this.errors[model.get("id")];
|
||||
},
|
||||
addModelFieldError: function(error) {
|
||||
if (! error instanceof Error) {
|
||||
throw "Item must be an error object";
|
||||
}
|
||||
|
||||
var model = error.model;
|
||||
var fieldId = error.fieldId;
|
||||
|
||||
if (!this.containsModelError(model)) {
|
||||
this.addModelError(model);
|
||||
}
|
||||
|
||||
this.getModelError(model).add(fieldId, error);
|
||||
|
||||
this.trigger("add-error", error);
|
||||
|
||||
return this;
|
||||
},
|
||||
removeModelFieldError: function(model, fieldId) {
|
||||
var modelError = this.getModelError(model);
|
||||
|
||||
if (modelError) {
|
||||
modelError.remove(fieldId);
|
||||
this.trigger("remove-error", model, fieldId);
|
||||
|
||||
if (modelError.count() === 0) {
|
||||
this.removeModelError(model);
|
||||
|
||||
if (!this.hasErrors()) {
|
||||
this.trigger("no-error");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
clearModelFieldErrors: function(model, fieldId) {
|
||||
var modelError = this.getModelError(model);
|
||||
|
||||
if (modelError) {
|
||||
modelError.clear();
|
||||
this.removeModelError(model);
|
||||
}
|
||||
|
||||
if (!this.hasErrors()) {
|
||||
this.trigger("no-error");
|
||||
}
|
||||
},
|
||||
containsModelFieldError: function (model, fieldId) {
|
||||
var modelError = this.getModelError(model);
|
||||
|
||||
if (modelError) {
|
||||
return modelError.has(fieldId);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
getModelFieldError: function(model, fieldId) {
|
||||
var modelError = this.getModelError(model);
|
||||
|
||||
if (modelError) {
|
||||
return modelError.get(fieldId);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
clearAll: function() {
|
||||
this.errors = {};
|
||||
this.trigger("no-error");
|
||||
},
|
||||
hasErrors: function () {
|
||||
return !_.isEmpty(this.errors);
|
||||
},
|
||||
count: function () {
|
||||
var count = 0;
|
||||
for (var k in this.errors) {
|
||||
if (this.errors.hasOwnProperty(k)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
},
|
||||
all: function () {
|
||||
var errors = [];
|
||||
_.each(this.errors, function(modelErrors) {
|
||||
_.each(modelErrors.all(), function(error) {
|
||||
errors.push(error);
|
||||
});
|
||||
});
|
||||
|
||||
return errors;
|
||||
}
|
||||
};
|
||||
|
||||
return ErrorManager;
|
||||
});
|
50
www/scripts/apps/admin/fields/errors/errorModel.js
Normal file
50
www/scripts/apps/admin/fields/errors/errorModel.js
Normal file
@@ -0,0 +1,50 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore"
|
||||
], function($, _) {
|
||||
var ErrorModel = function(id) {
|
||||
this.id = id;
|
||||
this.errors = {};
|
||||
};
|
||||
|
||||
ErrorModel.prototype = {
|
||||
add: function(id, error) {
|
||||
if (! error instanceof Error) {
|
||||
throw "Item must be an error object";
|
||||
}
|
||||
|
||||
this.errors[id] = error;
|
||||
},
|
||||
get: function(id) {
|
||||
if (this.has(id)) {
|
||||
return this.errors[id];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
has: function (id) {
|
||||
return "undefined" !== typeof this.errors[id];
|
||||
},
|
||||
remove: function(id) {
|
||||
if (this.has(id)) {
|
||||
delete this.errors[id];
|
||||
}
|
||||
},
|
||||
count: function() {
|
||||
var count = 0;
|
||||
for (var k in this.errors) {
|
||||
if (this.errors.hasOwnProperty(k)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
},
|
||||
clear: function () {
|
||||
this.errors = {};
|
||||
},
|
||||
all: function () {
|
||||
return this.errors;
|
||||
}
|
||||
};
|
||||
|
||||
return ErrorModel;
|
||||
});
|
Reference in New Issue
Block a user