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:
kay.one 2013-04-20 11:59:01 -07:00
parent acb15d8e49
commit 979efb8354
3 changed files with 17 additions and 7 deletions

View File

@ -13,7 +13,6 @@ Marionette.TemplateCache.get = function (templateId) {
return function (data) {
try {
//console.log('rendering template ' + templateKey);
return templateFunction(data);
}
catch (error) {

View File

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

View File

@ -71,8 +71,6 @@ define('app', function () {
console.log('starting application');
NzbDrone.ModelBinder = new Backbone.ModelBinder();
//TODO: move this out of here
Handlebars.registerHelper("formatStatus", function (status, monitored) {
if (!monitored) {