diff options
Diffstat (limited to 'module/web/static/js/views')
-rw-r--r-- | module/web/static/js/views/fileView.js | 6 | ||||
-rw-r--r-- | module/web/static/js/views/headerView.js | 29 | ||||
-rw-r--r-- | module/web/static/js/views/linkGrabberModal.js | 29 | ||||
-rw-r--r-- | module/web/static/js/views/packageView.js | 5 | ||||
-rw-r--r-- | module/web/static/js/views/selectionView.js | 40 |
5 files changed, 66 insertions, 43 deletions
diff --git a/module/web/static/js/views/fileView.js b/module/web/static/js/views/fileView.js index 68e8df176..2d5d844c8 100644 --- a/module/web/static/js/views/fileView.js +++ b/module/web/static/js/views/fileView.js @@ -9,7 +9,8 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abst template: _.compile($("#template-file").html()), events: { 'click .checkbox': 'select', - 'click .iconf-trash': 'deleteItem' + 'click .btn-delete': 'deleteItem', + 'click .btn-restart': 'restart' }, initialize: function() { @@ -49,9 +50,8 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abst if (this.model.get('visible')) this.$el.show(); - else { + else this.$el.hide(); - } return this; }, diff --git a/module/web/static/js/views/headerView.js b/module/web/static/js/views/headerView.js index d9c56b332..49c3aa30e 100644 --- a/module/web/static/js/views/headerView.js +++ b/module/web/static/js/views/headerView.js @@ -7,7 +7,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'colle events: { 'click .iconf-list': 'toggle_taskList', - 'click .popover .close': 'hide_taskList', + 'click .popover .close': 'toggle_taskList', 'click .btn-grabber': 'open_grabber' }, @@ -26,6 +26,9 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'colle status: null, progressList: null, + // save if last progress was empty + wasEmpty: false, + initialize: function() { var self = this; this.notifications = this.$('#notification-area').calculateHeight().height(0); @@ -138,10 +141,6 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'colle this.$('.popover').animate({opacity: 'toggle'}); }, - hide_taskList: function() { - this.$('.popover').fadeOut(); - }, - open_grabber: function() { var self = this; _.requireOnce(['views/linkGrabberModal'], function(modalView) { @@ -180,14 +179,26 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'colle this.progressList.update(progress); // update currently open files with progress this.progressList.each(function(prog) { - if(prog.isDownload() && App.dashboard.files){ + if (prog.isDownload() && App.dashboard.files) { var file = App.dashboard.files.get(prog.get('download').fid); if (file) - file.set('progress', prog.getPercent()); + file.set({ + progress: prog.getPercent(), + eta: prog.get('eta') + }); } }); - // TODO: only render when changed - this.render(); + + if (progress.length === 0) { + // only render one time when last was not empty already + if (!this.wasEmpty) { + this.render(); + this.wasEmpty = true; + } + } else { + this.wasEmpty = false; + this.render(); + } }, onEvent: function(event, args) { diff --git a/module/web/static/js/views/linkGrabberModal.js b/module/web/static/js/views/linkGrabberModal.js index 71f97f0bf..3d9a886db 100644 --- a/module/web/static/js/views/linkGrabberModal.js +++ b/module/web/static/js/views/linkGrabberModal.js @@ -26,23 +26,22 @@ define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'text!tpl/def addPackage: function(e) { var self = this; - var settings = { - type: 'POST', - data: { - name: JSON.stringify($('#inputPackageName').val()), - links: JSON.stringify(['http://download.pyload.org/random.bin', 'http://download.pyload.org/random100.bin', - 'invalid link', 'invalid link 2', 'invalid link 3', 'inavlid link 4', - 'http://download.pyload.org/random.bin', 'http://download.pyload.org/random.bin', 'http://download.pyload.org/random.bin', - 'A really really long invalid url that should exceed length of most of the urls by far and split into two lines']) + var options = App.apiRequest('addPackage', + { + name: $('#inputPackageName').val(), + // TODO: better parsing / tokenization + links: $('#inputLinks').val().split("\n") }, - success: function() { - App.vent.trigger('package:added'); - self.hide(); - } - }; - - $.ajax('api/addPackage', settings); + { + success: function() { + App.vent.trigger('package:added'); + self.hide(); + } + }); + + $.ajax(options); $('#inputPackageName').val(''); + $('#inputLinks').val(''); }, onShow: function() { diff --git a/module/web/static/js/views/packageView.js b/module/web/static/js/views/packageView.js index 534fe2ad4..547c1470d 100644 --- a/module/web/static/js/views/packageView.js +++ b/module/web/static/js/views/packageView.js @@ -8,9 +8,10 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore'], className: 'package-view', template: _.compile($("#template-package").html()), events: { - 'click .package-name': 'open', + 'click .package-name, .btn-open': 'open', 'click .iconf-refresh': 'restart', - 'click .select': 'select' + 'click .select': 'select', + 'click .btn-delete': 'deleteItem' }, // Ul for child packages (unused) diff --git a/module/web/static/js/views/selectionView.js b/module/web/static/js/views/selectionView.js index 480b7127b..4f235b2f5 100644 --- a/module/web/static/js/views/selectionView.js +++ b/module/web/static/js/views/selectionView.js @@ -30,8 +30,10 @@ define(['jquery', 'backbone', 'underscore', 'app'], this.actionBar = $('.actionbar .btn-check'); this.actionBar.parent().click(_.bind(this.select_toggle, this)); - // TODO when something gets deleted -// this.tree.get('packages').on('delete', _.bind(this.render, this)); + + // API events, maybe better to rely on internal ones? + App.vent.on('package:deleted', render); + App.vent.on('file:deleted', render); }, get_files: function(all) { @@ -85,23 +87,33 @@ define(['jquery', 'backbone', 'underscore', 'app'], }, pause: function() { - _.confirm('default/confirmDialog.html', function() { - alert("Not implemented yet"); - this.deselect(); - }, this); + alert("Not implemented yet"); + this.deselect(); }, trash: function() { - // TODO: delete many at once, check if package is parent - this.get_files().map(function(file) { - file.destroy(); - }); + _.confirm('default/confirmDialog.html', function() { - this.get_packs().map(function(pack) { - pack.destroy(); - }); + var pids = []; + // TODO: delete many at once + this.get_packs().map(function(pack) { + pids.push(pack.get('pid')); + pack.destroy(); + }); - this.deselect(); + // get only the fids of non deleted packages + var fids = _.filter(this.get_files(),function(file) { + return !_.contains(pids, file.get('package')); + }).map(function(file) { + file.destroyLocal(); + return file.get('fid'); + }); + + if (fids.length > 0) + $.ajax(App.apiRequest('deleteFiles', {fids: fids})); + + this.deselect(); + }, this); }, restart: function() { |