diff options
Diffstat (limited to 'pyload/web/app/scripts')
-rw-r--r-- | pyload/web/app/scripts/models/Package.js | 20 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/dashboardView.js | 11 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/packageView.js | 5 |
3 files changed, 30 insertions, 6 deletions
diff --git a/pyload/web/app/scripts/models/Package.js b/pyload/web/app/scripts/models/Package.js index a34ec1c69..555d5b7d6 100644 --- a/pyload/web/app/scripts/models/Package.js +++ b/pyload/web/app/scripts/models/Package.js @@ -1,5 +1,5 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'require'], - function($, Backbone, _, App, FileList, require) { +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collections/FileList', 'require'], + function($, Backbone, _, App, Api, FileList, require) { 'use strict'; return Backbone.Model.extend({ @@ -36,6 +36,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'requ toJSON: function(options) { var obj = Backbone.Model.prototype.toJSON.call(this, options); obj.percent = Math.round(obj.stats.linksdone * 100 / obj.stats.linkstotal); + obj.paused = obj.status === Api.PackageStatus.Paused; return obj; }, @@ -64,6 +65,21 @@ define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'requ // TODO }, + togglePaused: function() { + var self = this; + var paused = this.get('status') === Api.PackageStatus.Paused; + + $.ajax(App.apiRequest('setPackagePaused', { + pid: this.get('pid'), + paused: !paused + }, { + success: function(data) { + console.log('New package status', data); + self.set('status', data); + } + })); + }, + destroy: function(options) { // TODO: Not working when using data?, array seems to break it options = App.apiRequest( diff --git a/pyload/web/app/scripts/views/dashboard/dashboardView.js b/pyload/web/app/scripts/views/dashboard/dashboardView.js index d98e28fe3..6a263bf03 100644 --- a/pyload/web/app/scripts/views/dashboard/dashboardView.js +++ b/pyload/web/app/scripts/views/dashboard/dashboardView.js @@ -28,10 +28,8 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'col var self = this; // When package is added we reload the data - this.listenTo(App.vent, 'package:added', function() { - console.log('Package tree caught, package:added event'); - self.tree.fetch(); - }); + this.listenTo(App.vent, 'package:added', _.bind(this.fetch, this)); + this.listenTo(App.vent, 'package:inserted', _.bind(this.fetch, this)); this.listenTo(App.vent, 'file:updated', _.bind(this.fileUpdated, this)); @@ -59,6 +57,11 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'col this.$('.input').select2({tags: ['a', 'b', 'sdf']}); }, + fetch: function() { + console.log('Fetching package tree'); + this.tree.fetch(); + }, + update: function() { console.log('Update package list'); diff --git a/pyload/web/app/scripts/views/dashboard/packageView.js b/pyload/web/app/scripts/views/dashboard/packageView.js index 1bb250f27..243ebac9b 100644 --- a/pyload/web/app/scripts/views/dashboard/packageView.js +++ b/pyload/web/app/scripts/views/dashboard/packageView.js @@ -11,6 +11,7 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb events: { 'click .package-name, .btn-open': 'open', 'click .icon-refresh': 'restart', + 'click .toggle-paused': 'pause', 'click .select': 'select', 'click .icon-chevron-down': 'loadMenu', 'click .btn-delete': 'deleteItem', @@ -68,6 +69,10 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb App.dashboard.openPackage(this.model); }, + pause: function(e) { + this.model.togglePaused(); + }, + select: function(e) { e.preventDefault(); var checked = this.$('.select').hasClass('icon-check'); |