mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
Reorder forms organisation add a way to custom view & add callback once error is rendered
This commit is contained in:
63
www/scripts/common/forms/views/error.js
Normal file
63
www/scripts/common/forms/views/error.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"backbone"
|
||||
], function($, _, Backbone) {
|
||||
var ErrorView = Backbone.View.extend({
|
||||
tagName: "div",
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
|
||||
if (! "name" in options) {
|
||||
throw "Missing name attribute in error view";
|
||||
}
|
||||
|
||||
if (! "errorTemplate" in options) {
|
||||
throw "Missing errorTemplate attribute in error view";
|
||||
}
|
||||
|
||||
this.name = options.name;
|
||||
this.errorTemplate = options.errorTemplate;
|
||||
|
||||
this.errors = options.errors || {};
|
||||
this.onRenderError = options.onRenderError || null;
|
||||
},
|
||||
render: function() {
|
||||
if (this.errors.length > 0 ) {
|
||||
var template = _.template($(this.errorTemplate).html(), {
|
||||
errors: this.errors
|
||||
});
|
||||
|
||||
this.$el.html(template);
|
||||
|
||||
if (_.isFunction(this.onRenderError)) {
|
||||
this.onRenderError(this.name, this.$el);
|
||||
}
|
||||
} else {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
renderErrors: function (errors) {
|
||||
this.errors = errors;
|
||||
this.render();
|
||||
|
||||
return this;
|
||||
},
|
||||
reset: function() {
|
||||
this.$el.empty();
|
||||
}
|
||||
});
|
||||
|
||||
return ErrorView;
|
||||
});
|
Reference in New Issue
Block a user