Skip to content

Commit

Permalink
MediaListView: inherit from kb.ViewModel, add function to enable edit…
Browse files Browse the repository at this point in the history
…ing of name field if not set.

It is editListName() called from EditView.save()

Signed-off-by: Adrian Pardini <publico@tangopardo.com.ar>
  • Loading branch information
pardo-bsso committed Mar 21, 2013
1 parent 5ea07b0 commit 62d916b
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions public/js/views/medialist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 62d916b

Please sign in to comment.