mirror of https://github.com/Radarr/Radarr
much smarter binding,
auto-binding is only done when the element has binding attributes ('name') also now an error is throw in there are binding elements but view doesn't have a model
This commit is contained in:
parent
acb15d8e49
commit
979efb8354
|
@ -13,7 +13,6 @@ Marionette.TemplateCache.get = function (templateId) {
|
|||
return function (data) {
|
||||
|
||||
try {
|
||||
//console.log('rendering template ' + templateKey);
|
||||
return templateFunction(data);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
@ -10,7 +10,7 @@ Marionette.View.prototype.viewName = function () {
|
|||
|
||||
return this.template
|
||||
.toLocaleLowerCase()
|
||||
.replace('template','')
|
||||
.replace('template', '')
|
||||
.replace(regex, '-');
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,25 @@ Marionette.ItemView.prototype.render = function () {
|
|||
|
||||
var result = oldItemViewRender.apply(this, arguments);
|
||||
|
||||
this.$el.addClass('iv-' + this.viewName());
|
||||
|
||||
if (this.model) {
|
||||
NzbDrone.ModelBinder.bind(this.model, this.el);
|
||||
|
||||
//check to see if el has bindings (name attribute)
|
||||
// any element that has a name attribute and isn't child of another view.
|
||||
if (this.$('[name]').not("[class*='iv-'] [name]").length > 0) {
|
||||
if (!this.model) {
|
||||
throw 'view ' + this.viewName() + ' has binding attributes but model is not defined';
|
||||
}
|
||||
|
||||
if (!this._modelBinder) {
|
||||
this._modelBinder = new Backbone.ModelBinder();
|
||||
}
|
||||
|
||||
window.console.log('binding ' + this.viewName());
|
||||
|
||||
this._modelBinder.bind(this.model, this.el);
|
||||
}
|
||||
|
||||
this.$el.addClass('iv-' + this.viewName());
|
||||
return result;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue