diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-18 17:01:17 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-18 17:01:17 +0200 |
commit | 9a6ea22616cf3cc67e292c908521b79764400faf (patch) | |
tree | 1924843f28d992490d867d0557da90dfb1da6404 /pyload/web/app/scripts/views | |
parent | fixed login (diff) | |
download | pyload-9a6ea22616cf3cc67e292c908521b79764400faf.tar.xz |
new linkgrabber
Diffstat (limited to 'pyload/web/app/scripts/views')
6 files changed, 146 insertions, 51 deletions
diff --git a/pyload/web/app/scripts/views/abstract/modalView.js b/pyload/web/app/scripts/views/abstract/modalView.js index b6d9f0eab..61016a9fb 100644 --- a/pyload/web/app/scripts/views/abstract/modalView.js +++ b/pyload/web/app/scripts/views/abstract/modalView.js @@ -117,10 +117,14 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, }, destroy: function() { + this.onDestroy(); this.$el.remove(); this.dialog = null; this.remove(); - } + }, + onDestroy: function() { + + } }); });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/headerView.js b/pyload/web/app/scripts/views/headerView.js index 3fdfe32ba..60a47ad62 100644 --- a/pyload/web/app/scripts/views/headerView.js +++ b/pyload/web/app/scripts/views/headerView.js @@ -172,7 +172,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'colle open_grabber: function() { var self = this; - _.requireOnce(['views/linkGrabberModal'], function(ModalView) { + _.requireOnce(['views/linkgrabber/modalView'], function(ModalView) { if (self.grabber === null) self.grabber = new ModalView(); diff --git a/pyload/web/app/scripts/views/linkGrabberModal.js b/pyload/web/app/scripts/views/linkGrabberModal.js deleted file mode 100644 index e6f59c134..000000000 --- a/pyload/web/app/scripts/views/linkGrabberModal.js +++ /dev/null @@ -1,49 +0,0 @@ -define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'hbs!tpl/dialogs/linkgrabber'], - function($, _, App, modalView, template) { - 'use strict'; - // Modal dialog for package adding - triggers package:added when package was added - return modalView.extend({ - - events: { - 'click .btn-success': 'addPackage', - 'keypress #inputPackageName': 'addOnEnter' - }, - - template: template, - - initialize: function() { - // Inherit parent events - this.events = _.extend({}, modalView.prototype.events, this.events); - }, - - addOnEnter: function(e) { - if (e.keyCode !== 13) return; - this.addPackage(e); - }, - - addPackage: function(e) { - var self = this; - 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(options); - $('#inputPackageName').val(''); - $('#inputLinks').val(''); - }, - - onShow: function() { - this.$('#inputPackageName').focus(); - } - - }); - });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/linkgrabber/collectorView.js b/pyload/web/app/scripts/views/linkgrabber/collectorView.js new file mode 100644 index 000000000..d2b43f699 --- /dev/null +++ b/pyload/web/app/scripts/views/linkgrabber/collectorView.js @@ -0,0 +1,21 @@ +define(['jquery', 'underscore', 'backbone', 'app', './packageView'], + function($, _, Backbone, App, packageView) { + 'use strict'; + return Backbone.Marionette.CollectionView.extend({ + itemView: packageView, + updateData: function(result) { + var self = this; + _.each(result.data, function(links, name) { + var pack = self.collection.get(name); + if (!pack) { + pack = new self.collection.model({name: name}); + self.collection.add(pack); + } + + // TODO: remove links from all other packages than pack + pack.updateLinks(links); + }); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/linkgrabber/modalView.js b/pyload/web/app/scripts/views/linkgrabber/modalView.js new file mode 100644 index 000000000..6e4781ac2 --- /dev/null +++ b/pyload/web/app/scripts/views/linkgrabber/modalView.js @@ -0,0 +1,61 @@ +define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'views/abstract/modalView', './collectorView', 'hbs!tpl/linkgrabber/modal'], + function($, _, Backbone, App, CollectorPackage, modalView, CollectorView, template) { + 'use strict'; + // Modal dialog for package adding - triggers package:added when package was added + return modalView.extend({ + + events: { + 'keypress #inputLinks': 'addOnEnter' + }, + + template: template, + + // Holds the view that display the packages + collectorView: null, + + initialize: function() { + // Inherit parent events + this.events = _.extend({}, modalView.prototype.events, this.events); + }, + + addOnEnter: function(e) { + if (e.keyCode !== 13) return; + this.addPackage(e); + }, + + addPackage: function(e) { + var self = this; + // split, trim and remove empty links + var links = _.filter(_.map(this.$('#inputLinks').val().split('\n'), function(link) { + return $.trim(link); + }), function(link) { + return link.length > 0; + }); + + var options = App.apiRequest('checkLinks', + {links: links}, + { + success: function(data) { + self.collectorView.updateData(data); + } + }); + + $.ajax(options); + this.$('#inputLinks').val(''); + }, + + onRender: function() { + // anonymous collection + this.collectorView = new CollectorView({collection: new (Backbone.Collection.extend({ + model: CollectorPackage + }))()}); + this.collectorView.setElement(this.$('.prepared-packages')); + }, + + onDestroy: function() { + if (this.collectorView) + this.collectorView.close(); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/linkgrabber/packageView.js b/pyload/web/app/scripts/views/linkgrabber/packageView.js new file mode 100644 index 000000000..97d00f722 --- /dev/null +++ b/pyload/web/app/scripts/views/linkgrabber/packageView.js @@ -0,0 +1,58 @@ +define(['jquery', 'underscore', 'backbone', 'app', 'hbs!tpl/linkgrabber/package'], + function($, _, Backbone, App, template) { + 'use strict'; + return Backbone.Marionette.ItemView.extend({ + + tagName: 'div', + className: 'row-fluid package', + template: template, + + modelEvents: { + change: 'render' + }, + + ui: { + 'table': 'table' + }, + + events: { + 'click .btn-expand': 'expand', + 'click .btn-add': 'addPackage', + 'click .btn-delete': 'deletePackage', + 'click .btn-mini': 'deleteLink' + }, + + expanded: false, + + serializeData: function() { + var data = this.model.toJSON(); + data.expanded = this.expanded; + return data; + }, + + addPackage: function() { + this.model.add(); + }, + + deletePackage: function() { + this.model.destroy(); + }, + + deleteLink: function(e) { + var el = $(e.target); + var id = parseInt(el.data('index'), 10); + + var model = this.model.get('links').at(id); + if (model) + model.destroy(); + + this.render(); + }, + + expand: function() { + this.expanded ^= true; + this.ui.table.toggle(); + } + + }); + });
\ No newline at end of file |