summaryrefslogtreecommitdiffstats
path: root/module/web/static/js/views/linkGrabberModal.js
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/static/js/views/linkGrabberModal.js')
-rw-r--r--module/web/static/js/views/linkGrabberModal.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/module/web/static/js/views/linkGrabberModal.js b/module/web/static/js/views/linkGrabberModal.js
new file mode 100644
index 000000000..e2b6e985d
--- /dev/null
+++ b/module/web/static/js/views/linkGrabberModal.js
@@ -0,0 +1,48 @@
+define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'text!tpl/default/linkgrabber.html'],
+ function($, _, App, modalView, template) {
+ // Modal dialog for package adding - triggers package:added when package was added
+ return modalView.extend({
+
+ events: {
+ 'click .btn-success': 'addPackage',
+ 'keypress #inputPackageName': 'addOnEnter'
+ },
+
+ template: _.compile(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