1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 17:59:14 +00:00
Radarr/UI/Mixins/AsModelBoundView.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2013-06-19 01:02:23 +00:00
'use strict';
define(
['backbone.modelbinder'],
function (ModelBinder) {
return function () {
var originalOnRender = this.prototype.onRender,
originalBeforeClose = this.prototype.onBeforeClose;
this.prototype.onRender = function () {
if (!this.model) {
throw 'View has no model for binding';
}
if (!this._modelBinder) {
2013-06-19 01:02:23 +00:00
this._modelBinder = new ModelBinder();
}
this._modelBinder.bind(this.model, this.el);
2013-06-19 01:02:23 +00:00
if (originalOnRender) {
originalOnRender.call(this);
}
};
this.prototype.beforeClose = function () {
if (this._modelBinder) {
this._modelBinder.unbind();
delete this._modelBinder;
}
if (originalBeforeClose) {
originalBeforeClose.call(this);
}
};
return this;
};
}
);