From 62d916b3300747e395f025f36a19c178e7d36dd2 Mon Sep 17 00:00:00 2001 From: Adrian Pardini Date: Thu, 21 Mar 2013 00:05:29 -0300 Subject: [PATCH] MediaListView: inherit from kb.ViewModel, add function to enable editing of name field if not set. It is editListName() called from EditView.save() Signed-off-by: Adrian Pardini --- public/js/views/medialist.js | 66 ++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index 9061212..e84b128 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -49,46 +49,54 @@ window.MediaListView2 = function(options){ var sortable = 'sortable' in options ? options['sortable'] : false; + this.model = model; + //XXX: there has to be a better way to pre render this el.html(template.medialist({sortable: sortable})); console.log('ML2'); //XXX: We need to put this on SearchView2 - var MediaListViewModel = function(collection) { - var _this = this; + var MediaListViewModel = kb.ViewModel.extend({ + constructor: function(model) { + kb.ViewModel.prototype.constructor.apply(this, arguments); + + this.editingName = ko.observable(false); + this.nameClick = function () { + this.editingName(true); + } + + this.changeFocus = function () { + if(_this.name().length<=0) + return false; + _this.editingName(false); + } + + this.filter = ko.observable(''); + var _this = this; + this.collection = kb.collectionObservable( collection, { + view_model: kb.viewModel, + sort_attribute: 'file', + filters: function(model) { + var filter; + filter = _this.filter(); + if (!filter) return false; + return model.get('file').search(filter) < 0; + }, + }); - this.name = ko.observable(model.get('name')); - this.editingName = ko.observable(false); - this.nameClick = function () { - this.editingName(true); - } + }, - this.changeFocus = function () { - if(_this.name().length<=0) - return false; - _this.editingName(false); - } + allowDrop: sortable, + }); - this.filter = ko.observable(''); - this.collection = kb.collectionObservable( collection, { - view_model: kb.viewModel, - sort_attribute: 'file', - filters: function(model) { - var filter; - filter = _this.filter(); - if (!filter) return false; - return model.get('file').search(filter) < 0; - }, - }); + new SearchView2({el: $('#media-search',el) }); + this.view_model = new MediaListViewModel(model); - this.allowDrop = sortable; + this.editListName = function () { + this.view_model.editingName(true); }; - this.model = model; - - new SearchView2({el: $('#media-search',el) }); - var view_model = new MediaListViewModel(collection); - ko.applyBindings(view_model, el[0]); + ko.applyBindings(this.view_model, el[0]); } window.MediaListView = Backbone.View.extend({