2013-06-19 03:02:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
define(
|
|
|
|
['backbone.modelbinder'],
|
|
|
|
function (ModelBinder) {
|
|
|
|
|
|
|
|
return function () {
|
|
|
|
|
|
|
|
var originalOnRender = this.prototype.onRender,
|
|
|
|
originalBeforeClose = this.prototype.onBeforeClose;
|
|
|
|
|
|
|
|
this.prototype.onRender = function () {
|
2013-06-19 03:10:32 +02:00
|
|
|
|
|
|
|
if (!this.model) {
|
|
|
|
throw 'View has no model for binding';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._modelBinder) {
|
2013-06-19 03:02:23 +02:00
|
|
|
this._modelBinder = new ModelBinder();
|
|
|
|
}
|
2013-06-19 03:10:32 +02:00
|
|
|
|
|
|
|
this._modelBinder.bind(this.model, this.el);
|
|
|
|
|
2013-06-19 03:02:23 +02: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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|