From bd015ab580645f2cb9af70be64973a425e5f1552 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Dec 2013 15:19:49 +0100 Subject: updated some deps, button to add links to existing packages --- pyload/web/app/scripts/models/CollectorPackage.js | 40 ++++++++++++++++------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'pyload/web/app/scripts/models') diff --git a/pyload/web/app/scripts/models/CollectorPackage.js b/pyload/web/app/scripts/models/CollectorPackage.js index 9582c6af8..17a3a1551 100644 --- a/pyload/web/app/scripts/models/CollectorPackage.js +++ b/pyload/web/app/scripts/models/CollectorPackage.js @@ -8,7 +8,8 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collection name: 'Unnamed package', password: null, new_name: null, - links: null + links: null, + pid: null }, initialize: function() { @@ -39,16 +40,33 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collection add: function() { var self = this; var links = this.get('links').pluck('url'); - - $.ajax(App.apiRequest('addPackage', - {name: this.getName(), - links: links, - password: this.get('password')}, - {success: function() { - self.destroy(); - App.vent.trigger('package:added'); - }})); - + var pid = this.get('pid'); + + if (pid !== null && _.isNumber(pid)) { + console.log('Adding links to package', pid); + $.ajax(App.apiRequest('addLinks', + { + pid: pid, + links: links + }, + { + success: function() { + self.destroy(); + App.vent.trigger('collectorPackage:added'); + }})); + } + else + $.ajax(App.apiRequest('addPackage', + { + name: this.getName(), + links: links, + password: this.get('password') + }, + { + success: function() { + self.destroy(); + App.vent.trigger('collectorPackage:added'); + }})); }, updateLinks: function(links) { -- cgit v1.2.3