diff options
Diffstat (limited to 'deluge/ui/web/js/deluge-all/add/AddWindow.js')
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/AddWindow.js | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/deluge/ui/web/js/deluge-all/add/AddWindow.js b/deluge/ui/web/js/deluge-all/add/AddWindow.js index 89803f3..f5f2fdf 100644 --- a/deluge/ui/web/js/deluge-all/add/AddWindow.js +++ b/deluge/ui/web/js/deluge-all/add/AddWindow.js @@ -12,7 +12,7 @@ Ext.namespace('Deluge.add'); // This override allows file upload buttons to contain icons Ext.override(Ext.ux.form.FileUploadField, { - onRender: function(ct, position) { + onRender: function (ct, position) { Ext.ux.form.FileUploadField.superclass.onRender.call( this, ct, @@ -58,26 +58,12 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { plain: true, iconCls: 'x-deluge-add-window-icon', - initComponent: function() { + initComponent: function () { Deluge.add.AddWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancelClick, this); this.addButton(_('Add'), this.onAddClick, this); - function torrentRenderer(value, p, r) { - if (r.data['info_hash']) { - return String.format( - '<div class="x-deluge-add-torrent-name">{0}</div>', - value - ); - } else { - return String.format( - '<div class="x-deluge-add-torrent-name-loading">{0}</div>', - value - ); - } - } - this.list = new Ext.list.ListView({ store: new Ext.data.SimpleStore({ fields: [ @@ -91,8 +77,10 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { id: 'torrent', width: 150, sortable: true, - renderer: torrentRenderer, dataIndex: 'text', + tpl: new Ext.XTemplate( + '<div class="x-deluge-add-torrent-name">{text:htmlEncode}</div>' + ), }, ], stripeRows: true, @@ -147,7 +135,7 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { }, { text: _('Infohash'), - iconCls: 'icon-add-magnet', + iconCls: 'icon-magnet-add', hidden: true, disabled: true, }, @@ -168,17 +156,17 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { this.on('show', this.onShow, this); }, - clear: function() { + clear: function () { this.list.getStore().removeAll(); this.optionsPanel.clear(); // Reset upload form so handler fires when a canceled file is reselected this.fileUploadForm.reset(); }, - onAddClick: function() { + onAddClick: function () { var torrents = []; if (!this.list) return; - this.list.getStore().each(function(r) { + this.list.getStore().each(function (r) { var id = r.get('info_hash'); torrents.push({ path: this.optionsPanel.getFilename(id), @@ -187,29 +175,29 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { }, this); deluge.client.web.add_torrents(torrents, { - success: function(result) {}, + success: function (result) {}, }); this.clear(); this.hide(); }, - onCancelClick: function() { + onCancelClick: function () { this.clear(); this.hide(); }, - onFile: function() { + onFile: function () { if (!this.file) this.file = new Deluge.add.FileWindow(); this.file.show(); }, - onHide: function() { + onHide: function () { this.optionsPanel.setActiveTab(0); this.optionsPanel.files.setDisabled(true); this.optionsPanel.form.setDisabled(true); }, - onRemove: function() { + onRemove: function () { if (!this.list.getSelectionCount()) return; var torrent = this.list.getSelectedRecords()[0]; if (!torrent) return; @@ -220,7 +208,7 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { delete this.torrents[torrent.id]; }, - onSelect: function(list, selections) { + onSelect: function (list, selections) { if (selections.length) { var record = this.list.getRecord(selections[0]); this.optionsPanel.setTorrent(record.get('info_hash')); @@ -230,24 +218,25 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { } }, - onShow: function() { + onShow: function () { if (!this.url) { this.url = new Deluge.add.UrlWindow(); this.url.on('beforeadd', this.onTorrentBeforeAdd, this); this.url.on('add', this.onTorrentAdd, this); + this.url.on('addfailed', this.onTorrentAddFailed, this); } this.optionsPanel.form.getDefaults(); }, - onFileSelected: function() { + onFileSelected: function () { if (this.fileUploadForm.isValid()) { var torrentIds = []; var files = this.fileUploadForm.findField('torrentFile').value; var randomId = this.createTorrentId(); Array.prototype.forEach.call( files, - function(file, i) { + function (file, i) { // Append index for batch of unique torrentIds. var torrentId = randomId + i.toString(); torrentIds.push(torrentId); @@ -258,20 +247,21 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { url: deluge.config.base + 'upload', waitMsg: _('Uploading your torrent...'), success: this.onUploadSuccess, + failure: this.onUploadFailure, scope: this, torrentIds: torrentIds, }); } }, - onUploadSuccess: function(fp, upload) { + onUploadSuccess: function (fp, upload) { if (!upload.result.success) { this.clear(); return; } upload.result.files.forEach( - function(filename, i) { + function (filename, i) { deluge.client.web.get_torrent_info(filename, { success: this.onGotInfo, scope: this, @@ -283,18 +273,31 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { this.fileUploadForm.reset(); }, - onGotInfo: function(info, obj, response, request) { + onUploadFailure: function (form, action) { + this.hide(); + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Failed to upload torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error', + }); + this.fireEvent('addfailed', this.torrentId); + }, + + onGotInfo: function (info, obj, response, request) { info.filename = request.options.filename; torrentId = request.options.torrentId; this.onTorrentAdd(torrentId, info); }, - onTorrentBeforeAdd: function(torrentId, text) { + onTorrentBeforeAdd: function (torrentId, text) { var store = this.list.getStore(); store.loadData([[torrentId, null, text]], true); }, - onTorrentAdd: function(torrentId, info) { + onTorrentAdd: function (torrentId, info) { var r = this.list.getStore().getById(torrentId); if (!info) { Ext.MessageBox.show({ @@ -315,7 +318,15 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { } }, - onUrl: function(button, event) { + onTorrentAddFailed: function (torrentId) { + var store = this.list.getStore(); + var torrentRecord = store.getById(torrentId); + if (torrentRecord) { + store.remove(torrentRecord); + } + }, + + onUrl: function (button, event) { this.url.show(); }, }); |