diff options
Diffstat (limited to 'module/web/static/js/views/linkGrabberModal.js')
-rw-r--r-- | module/web/static/js/views/linkGrabberModal.js | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/module/web/static/js/views/linkGrabberModal.js b/module/web/static/js/views/linkGrabberModal.js index b5c91baa6..13900f222 100644 --- a/module/web/static/js/views/linkGrabberModal.js +++ b/module/web/static/js/views/linkGrabberModal.js @@ -1,9 +1,11 @@ -define(['jquery', 'underscore', 'views/abstract/modalView', 'text!tpl/default/linkgrabber.html'], - function($, _, modalView, template) { - +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), @@ -15,6 +17,29 @@ define(['jquery', 'underscore', 'views/abstract/modalView', 'text!tpl/default/li renderContent: function() { return $('<h1>Content!</h1>'); + }, + + addOnEnter: function(e) { + if (e.keyCode != 13) return; + this.addPackage(e); + }, + + addPackage: function(e) { + var self = this; + var settings = { + type: 'POST', + data: { + name: JSON.stringify($('#inputPackageName').val()), + links: JSON.stringify(['http://download.pyload.org/random.bin', 'invalid link']) + }, + success: function() { + App.vent.trigger('package:added'); + self.hide(); + } + }; + + $.ajax('api/addPackage', settings); + $('#inputPackageName').val(''); } }); |