diff options
Diffstat (limited to 'pyload/web/app/scripts/views/linkgrabber/modalView.js')
-rw-r--r-- | pyload/web/app/scripts/views/linkgrabber/modalView.js | 61 |
1 files changed, 61 insertions, 0 deletions
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 |