case 'file':
return new Filex.File(attrs, options);
default:
- console.log('Unknown model type:', attrs['type']);
+ console.error('Unknown model type:', attrs['type']);
}
},
tagName: 'tr',
events: {
- 'click .link': 'selected',
- 'click input[type=checkbox]': 'toggle'
+ 'click': 'click'
},
initialize: function(options) {
this.$el.toggleClass('hidden', this.model.isHidden() && !this.view.showHidden());
},
- selected: function(e) {
- e.preventDefault();
- if (this.model.isDir()) {
- this.model.trigger('selected:dir', this.model);
- }
- else {
- this.model.trigger('selected:file', this.model);
- this.toggle();
+ click: function(e) {
+ if (e.target.className == 'link') {
+ if (this.model.isDir()) {
+ e.preventDefault();
+ this.model.trigger('selected:dir', this.model);
+ }
+
+ return;
}
- },
- toggle: function() {
this.model.toggle();
}
});
events: {
'change #show-hidden': 'toggleHidden',
- 'click #host-controls .view': 'hostEdit',
- 'click #select-all': 'selectAll'
+ 'click #select-all': 'selectAll',
+ 'click #btn-refresh': 'reloadFiles'
},
initialize: function(options) {
this.$noItems = $('#no-items');
this.$error = $('#error');
this.$showHidden = $('#show-hidden');
- this.$host = $('#host-controls');
this.$selectAll = $('#select-all');
this.host = options.host;
this.listenTo(this.path, 'selected', this.selectedPath);
this.listenTo(this.files, 'reset', this.resetFiles);
this.listenTo(this.files, 'selected:dir', this.selectedDir);
- this.listenTo(this.files, 'selected:file', this.selectedFile);
this.listenTo(this.files, 'change:checked', this.updateSelectAll);
// used in selectize callbacks
this.blur();
},
onBlur: function() {
- view.$host.toggleClass('editing');
-
var value = this.getValue();
if (!value) {
this.addItem(view.host, true);
render: function() {
this.updateSelectAll();
- this.$host.find('.view').text(this.host);
this.$noItems.toggle(!Boolean(this.visibleFiles().length));
this.$error.hide();
},
this.path.add({'text': dir.get('name'), 'path': dir.get('name')});
},
- selectedFile: function(file) {
- this.trigger('selected:file', this.host + this.path.full() + '/' + file.get('name'));
- },
-
selectedPath: function(bit) {
var newPath = this.path.slice(0, this.path.indexOf(bit) + 1);
this.path.set(newPath);
return this.$showHidden[0].checked;
},
- hostEdit: function() {
- this.$host.toggleClass('editing');
- this.hostSelectize.focus();
- },
-
busy: function() {
this.$el.addClass('busy');
},
updateSelectAll: function() {
this.$selectAll.prop('checked', this.selectedFiles().length == this.visibleFiles().length);
+ },
+
+ clearSelection: function() {
+ _.each(this.visibleFiles(), function(item) {
+ item.set('checked', false);
+ });
+
+ this.updateSelectAll();
}
});
});