Files
Phraseanet/www/scripts/apps/admin/fields/errors/errorModel.js
Nicolas Le Goff 0539db7598 Add global register feature
Tweak admin field app

Fix typo

Tweaks

Fix typo
2013-05-27 23:26:48 +02:00

51 lines
1.1 KiB
JavaScript

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;
});