summaryrefslogtreecommitdiffstats
path: root/pyload/web/app/scripts/views/linkgrabber
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-18 17:01:17 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-18 17:01:17 +0200
commit9a6ea22616cf3cc67e292c908521b79764400faf (patch)
tree1924843f28d992490d867d0557da90dfb1da6404 /pyload/web/app/scripts/views/linkgrabber
parentfixed login (diff)
downloadpyload-9a6ea22616cf3cc67e292c908521b79764400faf.tar.xz
new linkgrabber
Diffstat (limited to 'pyload/web/app/scripts/views/linkgrabber')
-rw-r--r--pyload/web/app/scripts/views/linkgrabber/collectorView.js21
-rw-r--r--pyload/web/app/scripts/views/linkgrabber/modalView.js61
-rw-r--r--pyload/web/app/scripts/views/linkgrabber/packageView.js58
3 files changed, 140 insertions, 0 deletions
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