From: Maciej Tronowski Date: Mon, 23 Mar 2015 12:41:28 +0000 (+0100) Subject: checkboxes for selecting multiple files X-Git-Tag: v1.0~116 X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=commitdiff_plain;h=2a2a8a89e502704bd708daf8a5ac830fa6e41433;hp=73e8a4e152c693adff71a4252d8e623419be31c7;p=qcg-portal.git checkboxes for selecting multiple files --- diff --git a/filex/static/filex/filex.js b/filex/static/filex/filex.js index e1dc50f..81b401c 100644 --- a/filex/static/filex/filex.js +++ b/filex/static/filex/filex.js @@ -15,6 +15,10 @@ $(function(){ }); Filex.File = OfflineModel.extend({ + defaults: { + checked: false + }, + isDir: function() { return false; }, @@ -25,6 +29,10 @@ $(function(){ isHidden: function() { return this.get('name')[0] == '.'; + }, + + toggle: function() { + this.set('checked', !this.get('checked')); } }); @@ -113,12 +121,14 @@ $(function(){ tagName: 'tr', events: { - 'click .link': 'selected' + 'click .link': 'selected', + 'click input[type=checkbox]': 'toggle' }, initialize: function(options) { this.view = options.view; + this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'remove', this.remove); this.listenTo(this.model, 'hidden', this.toggleHidden); }, @@ -136,6 +146,7 @@ $(function(){ path: this.view.path.full(), name: this.model.get('name') }); + data['cid'] = this.model.cid; this.$el.html(this.template()(data)); this.toggleHidden(); @@ -149,7 +160,17 @@ $(function(){ selected: function(e) { e.preventDefault(); - this.model.trigger(this.model.isDir() ? 'selected:dir' : 'selected:file', this.model); + if (this.model.isDir()) { + this.model.trigger('selected:dir', this.model); + } + else { + this.model.trigger('selected:file', this.model); + this.toggle(); + } + }, + + toggle: function() { + this.model.toggle(); } }); @@ -191,7 +212,8 @@ $(function(){ events: { 'change #show-hidden': 'toggleHidden', - 'click #host-controls .view': 'hostEdit' + 'click #host-controls .view': 'hostEdit', + 'click #select-all': 'selectAll' }, initialize: function(options) { @@ -199,6 +221,7 @@ $(function(){ this.$error = $('#error'); this.$showHidden = $('#show-hidden'); this.$host = $('#host-controls'); + this.$selectAll = $('#select-all'); this.host = options.host; this.path = new Filex.Path(); @@ -211,6 +234,7 @@ $(function(){ 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 var view = this, @@ -258,8 +282,9 @@ $(function(){ }, render: function() { + this.updateSelectAll(); this.$host.find('.view').text(this.host); - this.$noItems.toggle((this.showHidden() ? !Boolean(this.files.length) : !Boolean(this.files.visible().length))); + this.$noItems.toggle(!Boolean(this.visibleFiles().length)); this.$error.hide(); }, @@ -358,6 +383,28 @@ $(function(){ idle: function() { this.$el.removeClass('busy'); + }, + + visibleFiles: function() { + return this.showHidden() ? this.files.models : this.files.visible(); + }, + + selectedFiles: function() { + return _.filter(this.visibleFiles(), function(item) { + return item.get('checked'); + }); + }, + + selectAll: function() { + var checked = this.$selectAll[0].checked; + + _.each(this.visibleFiles(), function(item) { + item.set('checked', checked); + }) + }, + + updateSelectAll: function() { + this.$selectAll.prop('checked', this.selectedFiles().length == this.visibleFiles().length); } }); }); diff --git a/filex/templates/filex/source.html b/filex/templates/filex/source.html index 3f49241..1558f0c 100644 --- a/filex/templates/filex/source.html +++ b/filex/templates/filex/source.html @@ -26,6 +26,10 @@ + diff --git a/filex/templates/filex/source.js.html b/filex/templates/filex/source.js.html index 4942015..2b5c1ab 100644 --- a/filex/templates/filex/source.js.html +++ b/filex/templates/filex/source.js.html @@ -26,6 +26,10 @@
+ + + Nazwa Rozmiar