2013-04-11 03:24:34 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var oldItemViewRender = Marionette.ItemView.prototype.render;
|
|
|
|
var oldItemCollectionViewRender = Marionette.CollectionView.prototype.render;
|
|
|
|
|
2013-04-11 06:28:17 +02:00
|
|
|
|
|
|
|
Marionette.View.prototype.viewName = function () {
|
|
|
|
if (this.template) {
|
|
|
|
var regex = new RegExp('\/', 'g');
|
|
|
|
|
|
|
|
return this.template
|
|
|
|
.toLocaleLowerCase()
|
2013-04-20 20:59:01 +02:00
|
|
|
.replace('template', '')
|
2013-04-11 06:28:17 +02:00
|
|
|
.replace(regex, '-');
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
2013-04-21 00:51:39 +02:00
|
|
|
Marionette.ItemView.prototype.self$ = function (selector) {
|
|
|
|
return this.$(selector).not("[class*='iv-'] " + selector);
|
|
|
|
};
|
|
|
|
|
2013-04-11 03:24:34 +02:00
|
|
|
Marionette.ItemView.prototype.render = function () {
|
|
|
|
|
2013-04-12 07:00:48 +02:00
|
|
|
var result = oldItemViewRender.apply(this, arguments);
|
|
|
|
|
|
|
|
|
2013-04-20 20:59:01 +02:00
|
|
|
//check to see if el has bindings (name attribute)
|
|
|
|
// any element that has a name attribute and isn't child of another view.
|
2013-04-21 00:51:39 +02:00
|
|
|
if (this.self$('[name]').length > 0) {
|
2013-04-20 20:59:01 +02:00
|
|
|
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);
|
2013-04-11 03:24:34 +02:00
|
|
|
}
|
|
|
|
|
2013-04-20 20:59:01 +02:00
|
|
|
this.$el.addClass('iv-' + this.viewName());
|
2013-04-21 00:51:39 +02:00
|
|
|
|
|
|
|
|
2013-04-12 07:00:48 +02:00
|
|
|
return result;
|
2013-04-11 03:24:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Marionette.CollectionView.prototype.render = function () {
|
|
|
|
|
|
|
|
if (this.model) {
|
|
|
|
NzbDrone.ModelBinder.bind(this.model, this.el);
|
|
|
|
}
|
|
|
|
|
|
|
|
return oldItemCollectionViewRender.apply(this, arguments);
|
2013-04-11 06:28:17 +02:00
|
|
|
};
|