From 0537c47cb430afa1770bc5bf8c757de867a276c0 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Sep 2013 21:32:03 +0200 Subject: improved link grabber --- .../app/scripts/views/dashboard/dashboardView.js | 4 ++-- .../app/scripts/views/linkgrabber/collectorView.js | 9 ++++++++- .../web/app/scripts/views/linkgrabber/modalView.js | 23 +++++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'pyload/web/app/scripts/views') diff --git a/pyload/web/app/scripts/views/dashboard/dashboardView.js b/pyload/web/app/scripts/views/dashboard/dashboardView.js index 8a0446203..d98e28fe3 100644 --- a/pyload/web/app/scripts/views/dashboard/dashboardView.js +++ b/pyload/web/app/scripts/views/dashboard/dashboardView.js @@ -28,12 +28,12 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'col var self = this; // When package is added we reload the data - App.vent.on('package:added', function() { + this.listenTo(App.vent, 'package:added', function() { console.log('Package tree caught, package:added event'); self.tree.fetch(); }); - App.vent.on('file:updated', _.bind(this.fileUpdated, this)); + this.listenTo(App.vent, 'file:updated', _.bind(this.fileUpdated, this)); // TODO: merge? this.init(); diff --git a/pyload/web/app/scripts/views/linkgrabber/collectorView.js b/pyload/web/app/scripts/views/linkgrabber/collectorView.js index a02023a30..08b426aff 100644 --- a/pyload/web/app/scripts/views/linkgrabber/collectorView.js +++ b/pyload/web/app/scripts/views/linkgrabber/collectorView.js @@ -21,7 +21,14 @@ define(['jquery', 'underscore', 'backbone', 'app', './packageView'], self.collection.add(pack); } - // TODO: remove links from all other packages than pack + // Remove links from other packages and delete empty ones + self.collection.each(function(pack2) { + console.log(pack2, links); + if (pack2 !== pack) + if (pack2.removeLinks(links)) + self.collection.remove(pack2); + }); + pack.updateLinks(links); }); } diff --git a/pyload/web/app/scripts/views/linkgrabber/modalView.js b/pyload/web/app/scripts/views/linkgrabber/modalView.js index 32730658c..808d67f59 100644 --- a/pyload/web/app/scripts/views/linkgrabber/modalView.js +++ b/pyload/web/app/scripts/views/linkgrabber/modalView.js @@ -6,7 +6,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'v className: 'modal linkgrabber', events: { - 'keypress #inputLinks': 'addOnEnter' + 'keyup #inputLinks': 'addOnKeyUp' }, template: template, @@ -14,18 +14,30 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'v // Holds the view that display the packages collectorView: null, + inputSize: 0, + initialize: function() { // Inherit parent events this.events = _.extend({}, modalView.prototype.events, this.events); this.listenTo(App.vent, 'package:added', _.bind(this.onAdded, this)); }, - addOnEnter: function(e) { - if (e.keyCode !== 13) return; - this.addPackage(e); + addOnKeyUp: function(e) { + // Enter adds the links + if (e.keyCode === 13) + this.parseLinks(); + + var inputSize = this.$('#inputLinks').val().length; + + // TODO: checkbox to disable this + // add links when several characters was pasted into box + if (inputSize > this.inputSize + 4) + this.parseLinks(); + else + this.inputSize = inputSize; }, - addPackage: function(e) { + parseLinks: function() { var self = this; // split, trim and remove empty links var links = _.filter(_.map(this.$('#inputLinks').val().split('\n'), function(link) { @@ -44,6 +56,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'v $.ajax(options); this.$('#inputLinks').val(''); + this.inputSize = 0; }, // Hide when there are no more packages -- cgit v1.2.3