Skip to content

Commit

Permalink
MediaView: inherit from MasterView, proper cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
pardo-bsso committed Feb 12, 2014
1 parent 56d94d6 commit 05dcf30
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions public/js/views/mediadetails.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
window.MediaView = function (options) {
var self = this;
options = options || {};
window.MediaView = MasterView.extend({
el: "#content",
initialize: function (options) {
// Parent initialize
MasterView.prototype.initialize.apply(this, arguments);

this.el = $('#content');
this.options = options || {};
this.el = options.el || $('#content');
_.bindAll(this, 'render', 'canNavigateAway');

this.render = function() {
this.model = options.model;
if (this.model !== undefined) {
this.render();
} else {
this.model = Media.Model.findOrCreate({ _id: options.id });
this.model.fetch({
success: this.render,
});
}
},

render: function() {
var self = this;
self.el.html(template.mediaview(self.model.toJSON()));

self.view_model = kb.viewModel(self.model);
Expand All @@ -16,16 +32,14 @@ window.MediaView = function (options) {
};

ko.applyBindings(self.view_model, self.el[0]);
}

this.model = options['model'];
if (this.model !== undefined) {
this.render();
} else {
this.model = Media.Model.findOrCreate({ _id: options["id"], });
this.model.fetch({
success: this.render,
});
}
}
},

canNavigateAway: function (options) {
var self = this;
kb.release(self.view_model);
// Clear element
ko.cleanNode(self.el[0]);
self.el.html('');
options['ok']();
},
});

0 comments on commit 05dcf30

Please sign in to comment.