diff options
Diffstat (limited to 'deluge/ui/web/js/deluge-all-debug.js')
-rw-r--r-- | deluge/ui/web/js/deluge-all-debug.js | 1477 |
1 files changed, 789 insertions, 688 deletions
diff --git a/deluge/ui/web/js/deluge-all-debug.js b/deluge/ui/web/js/deluge-all-debug.js index afbbabe..67bb83a 100644 --- a/deluge/ui/web/js/deluge-all-debug.js +++ b/deluge/ui/web/js/deluge-all-debug.js @@ -15,15 +15,15 @@ Ext.ns('Deluge.add'); * Base class for an add Window */ Deluge.add.Window = Ext.extend(Ext.Window, { - initComponent: function() { + initComponent: function () { Deluge.add.Window.superclass.initComponent.call(this); - this.addEvents('beforeadd', 'add'); + this.addEvents('beforeadd', 'add', 'addfailed'); }, /** * Create an id for the torrent before we have any info about it. */ - createTorrentId: function() { + createTorrentId: function () { return new Date().getTime().toString(); }, }); @@ -41,7 +41,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, @@ -87,26 +87,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: [ @@ -120,8 +106,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, @@ -176,7 +164,7 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { }, { text: _('Infohash'), - iconCls: 'icon-add-magnet', + iconCls: 'icon-magnet-add', hidden: true, disabled: true, }, @@ -197,17 +185,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), @@ -216,29 +204,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; @@ -249,7 +237,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')); @@ -259,24 +247,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); @@ -287,20 +276,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, @@ -312,18 +302,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({ @@ -344,7 +347,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(); }, }); @@ -378,13 +389,14 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { header: _('Filename'), width: 295, dataIndex: 'filename', + tpl: new Ext.XTemplate('{filename:htmlEncode}'), }, { header: _('Size'), width: 60, dataIndex: 'size', tpl: new Ext.XTemplate('{size:this.fsize}', { - fsize: function(v) { + fsize: function (v) { return fsize(v); }, }), @@ -394,7 +406,7 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { width: 65, dataIndex: 'download', tpl: new Ext.XTemplate('{download:this.format}', { - format: function(v) { + format: function (v) { return ( '<div rel="chkbox" class="x-grid3-check-col' + (v ? '-on' : '') + @@ -405,21 +417,21 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { }, ], - initComponent: function() { + initComponent: function () { Deluge.add.FilesTab.superclass.initComponent.call(this); this.on('click', this.onNodeClick, this); }, - clearFiles: function() { + clearFiles: function () { var root = this.getRootNode(); if (!root.hasChildNodes()) return; - root.cascade(function(node) { + root.cascade(function (node) { if (!node.parentNode || !node.getOwnerTree()) return; node.remove(); }); }, - setDownload: function(node, value, suppress) { + setDownload: function (node, value, suppress) { node.attributes.download = value; node.ui.updateColumns(); @@ -429,7 +441,7 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { } } else { var nodes = [node]; - node.cascade(function(n) { + node.cascade(function (n) { n.attributes.download = value; n.ui.updateColumns(); nodes.push(n); @@ -440,7 +452,7 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { } }, - onNodeClick: function(node, e) { + onNodeClick: function (node, e) { var el = new Ext.Element(e.target); if (el.getAttribute('rel') == 'chkbox') { this.setDownload(node, !node.attributes.download); @@ -477,7 +489,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { activeTab: 0, height: 265, - initComponent: function() { + initComponent: function () { Deluge.add.OptionsPanel.superclass.initComponent.call(this); this.files = this.add(new Deluge.add.FilesTab()); this.form = this.add(new Deluge.add.OptionsTab()); @@ -485,12 +497,12 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { this.files.on('fileschecked', this.onFilesChecked, this); }, - addTorrent: function(torrent) { + addTorrent: function (torrent) { this.torrents[torrent['info_hash']] = torrent; var fileIndexes = {}; this.walkFileTree( torrent['files_tree'], - function(filename, type, entry, parent) { + function (filename, type, entry, parent) { if (type != 'file') return; fileIndexes[entry.index] = entry.download; }, @@ -498,7 +510,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { ); var priorities = []; - Ext.each(Ext.keys(fileIndexes), function(index) { + Ext.each(Ext.keys(fileIndexes), function (index) { priorities[index] = fileIndexes[index]; }); @@ -510,26 +522,26 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { this.form.optionsManager.changeId(oldId, true); }, - clear: function() { + clear: function () { this.files.clearFiles(); this.form.optionsManager.resetAll(); }, - getFilename: function(torrentId) { + getFilename: function (torrentId) { return this.torrents[torrentId]['filename']; }, - getOptions: function(torrentId) { + getOptions: function (torrentId) { var oldId = this.form.optionsManager.changeId(torrentId, true); var options = this.form.optionsManager.get(); this.form.optionsManager.changeId(oldId, true); - Ext.each(options['file_priorities'], function(priority, index) { + Ext.each(options['file_priorities'], function (priority, index) { options['file_priorities'][index] = priority ? 1 : 0; }); return options; }, - setTorrent: function(torrentId) { + setTorrent: function (torrentId) { if (!torrentId) return; this.torrentId = torrentId; @@ -544,7 +556,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { if (this.torrents[torrentId]['files_tree']) { this.walkFileTree( this.torrents[torrentId]['files_tree'], - function(filename, type, entry, parentNode) { + function (filename, type, entry, parentNode) { var node = new Ext.tree.TreeNode({ download: entry.index ? priorities[entry.index] : true, filename: filename, @@ -568,7 +580,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { } }, - walkFileTree: function(files, callback, scope, parentNode) { + walkFileTree: function (files, callback, scope, parentNode) { for (var filename in files.contents) { var entry = files.contents[filename]; var type = entry.type; @@ -588,14 +600,13 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { } }, - onFilesChecked: function(nodes, newValue, oldValue) { + onFilesChecked: function (nodes, newValue, oldValue) { Ext.each( nodes, - function(node) { + function (node) { if (node.attributes.fileindex < 0) return; - var priorities = this.form.optionsManager.get( - 'file_priorities' - ); + var priorities = + this.form.optionsManager.get('file_priorities'); priorities[node.attributes.fileindex] = newValue; this.form.optionsManager.update('file_priorities', priorities); }, @@ -626,7 +637,7 @@ Deluge.add.OptionsTab = Ext.extend(Ext.form.FormPanel, { disabled: true, labelWidth: 1, - initComponent: function() { + initComponent: function () { Deluge.add.OptionsTab.superclass.initComponent.call(this); this.optionsManager = new Deluge.MultiOptionsManager(); @@ -779,7 +790,7 @@ Deluge.add.OptionsTab = Ext.extend(Ext.form.FormPanel, { ); }, - getDefaults: function() { + getDefaults: function () { var keys = [ 'add_paused', 'pre_allocate_storage', @@ -795,7 +806,7 @@ Deluge.add.OptionsTab = Ext.extend(Ext.form.FormPanel, { ]; deluge.client.core.get_config_values(keys, { - success: function(config) { + success: function (config) { var options = { file_priorities: [], add_paused: config.add_paused, @@ -844,7 +855,7 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { bodyStyle: 'padding: 10px 5px;', iconCls: 'x-deluge-add-url-window-icon', - initComponent: function() { + initComponent: function () { Deluge.add.UrlWindow.superclass.initComponent.call(this); this.addButton(_('Add'), this.onAddClick, this); @@ -872,7 +883,7 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { this.cookieField.on('specialkey', this.onAdd, this); }, - onAddClick: function(field, e) { + onAddClick: function (field, e) { if ( (field.id == 'url' || field.id == 'cookies') && e.getKey() != e.ENTER @@ -894,6 +905,7 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { } else { deluge.client.web.download_torrent_from_url(url, cookies, { success: this.onDownload, + failure: this.onDownloadFailed, scope: this, torrentId: torrentId, }); @@ -904,16 +916,29 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { this.fireEvent('beforeadd', torrentId, url); }, - onDownload: function(filename, obj, resp, req) { + onDownload: function (filename, obj, resp, req) { deluge.client.web.get_torrent_info(filename, { success: this.onGotInfo, + failure: this.onDownloadFailed, scope: this, filename: filename, torrentId: req.options.torrentId, }); }, - onGotInfo: function(info, obj, response, request) { + onDownloadFailed: function (obj, resp, req) { + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Failed to download torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error', + }); + this.fireEvent('addfailed', req.options.torrentId); + }, + + onGotInfo: function (info, obj, response, request) { info['filename'] = request.options.filename; this.fireEvent('add', request.options.torrentId, info); }, @@ -947,11 +972,11 @@ Deluge.data.SortTypes = { return ((+d[1] * 256 + (+d[2])) * 256 + (+d[3])) * 256 + (+d[4]); }, - asQueuePosition: function(value) { + asQueuePosition: function (value) { return value > -1 ? value : Number.MAX_VALUE; }, - asName: function(value) { + asName: function (value) { return String(value).toLowerCase(); }, }; @@ -1147,7 +1172,7 @@ Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, { id: 'torrentDetails', activeTab: 0, - initComponent: function() { + initComponent: function () { Deluge.details.DetailsPanel.superclass.initComponent.call(this); this.add(new Deluge.details.StatusTab()); this.add(new Deluge.details.DetailsTab()); @@ -1156,8 +1181,8 @@ Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, { this.add(new Deluge.details.OptionsTab()); }, - clear: function() { - this.items.each(function(panel) { + clear: function () { + this.items.each(function (panel) { if (panel.clear) { panel.clear.defer(100, panel); panel.disable(); @@ -1165,14 +1190,14 @@ Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, { }); }, - update: function(tab) { + update: function (tab) { var torrent = deluge.torrents.getSelected(); if (!torrent) { this.clear(); return; } - this.items.each(function(tab) { + this.items.each(function (tab) { if (tab.disabled) tab.enable(); }); @@ -1183,7 +1208,7 @@ Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, { /* Event Handlers */ // We need to add the events in onRender since Deluge.Torrents has not been created yet. - onRender: function(ct, position) { + onRender: function (ct, position) { Deluge.details.DetailsPanel.superclass.onRender.call( this, ct, @@ -1195,18 +1220,18 @@ Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, { deluge.torrents.getSelectionModel().on( 'selectionchange', - function(selModel) { + function (selModel) { if (!selModel.hasSelection()) this.clear(); }, this ); }, - onTabChange: function(panel, tab) { + onTabChange: function (panel, tab) { this.update(tab); }, - onTorrentsClick: function(grid, rowIndex, e) { + onTorrentsClick: function (grid, rowIndex, e) { this.update(); }, }); @@ -1230,7 +1255,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { oldData: {}, - initComponent: function() { + initComponent: function () { Deluge.details.DetailsTab.superclass.initComponent.call(this); this.addItem('torrent_name', _('Name:')); this.addItem('hash', _('Hash:')); @@ -1243,7 +1268,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { this.addItem('creator', _('Created By:')); }, - onRender: function(ct, position) { + onRender: function (ct, position) { Deluge.details.DetailsTab.superclass.onRender.call(this, ct, position); this.body.setStyle('padding', '10px'); this.dl = Ext.DomHelper.append(this.body, { tag: 'dl' }, true); @@ -1253,7 +1278,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { } }, - addItem: function(id, label) { + addItem: function (id, label) { if (!this.rendered) { this.queuedItems[id] = label; } else { @@ -1262,7 +1287,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { }, // private - doAddItem: function(id, label) { + doAddItem: function (id, label) { Ext.DomHelper.append(this.dl, { tag: 'dt', cls: id, html: label }); this.fields[id] = Ext.DomHelper.append( this.dl, @@ -1271,7 +1296,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { ); }, - clear: function() { + clear: function () { if (!this.fields) return; for (var k in this.fields) { this.fields[k].dom.innerHTML = ''; @@ -1279,7 +1304,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { this.oldData = {}; }, - update: function(torrentId) { + update: function (torrentId) { deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Details, { success: this.onRequestComplete, scope: this, @@ -1287,7 +1312,7 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { }); }, - onRequestComplete: function(torrent, request, response, options) { + onRequestComplete: function (torrent, request, response, options) { var data = { torrent_name: torrent.name, hash: options.options.torrentId, @@ -1303,7 +1328,9 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { for (var field in this.fields) { if (!Ext.isDefined(data[field])) continue; // This is a field we are not responsible for. if (data[field] == this.oldData[field]) continue; - this.fields[field].dom.innerHTML = Ext.escapeHTML(data[field]); + this.fields[field].dom.innerHTML = Ext.util.Format.htmlEncode( + data[field] + ); } this.oldData = data; }, @@ -1328,13 +1355,14 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { header: _('Filename'), width: 330, dataIndex: 'filename', + tpl: new Ext.XTemplate('{filename:htmlEncode}'), }, { header: _('Size'), width: 150, dataIndex: 'size', tpl: new Ext.XTemplate('{size:this.fsize}', { - fsize: function(v) { + fsize: function (v) { return fsize(v); }, }), @@ -1344,7 +1372,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { header: _('Progress'), width: 150, dataIndex: 'progress', - renderer: function(v) { + renderer: function (v) { var progress = v * 100; return Deluge.progressBar( progress, @@ -1364,11 +1392,11 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { '{priority:this.getName}' + '</div></tpl>', { - getClass: function(v) { + getClass: function (v) { return FILE_PRIORITY_CSS[v]; }, - getName: function(v) { + getName: function (v) { return _(FILE_PRIORITY[v]); }, } @@ -1378,15 +1406,15 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { selModel: new Ext.tree.MultiSelectionModel(), - initComponent: function() { + initComponent: function () { Deluge.details.FilesTab.superclass.initComponent.call(this); this.setRootNode(new Ext.tree.TreeNode({ text: _('Files') })); }, - clear: function() { + clear: function () { var root = this.getRootNode(); if (!root.hasChildNodes()) return; - root.cascade(function(node) { + root.cascade(function (node) { var parentNode = node.parentNode; if (!parentNode) return; if (!parentNode.ownerTree) return; @@ -1394,7 +1422,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { }); }, - createFileTree: function(files) { + createFileTree: function (files) { function walk(files, parentNode) { for (var file in files.contents) { var item = files.contents[file]; @@ -1433,7 +1461,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { root.firstChild.expand(); }, - update: function(torrentId) { + update: function (torrentId) { if (this.torrentId != torrentId) { this.clear(); this.torrentId = torrentId; @@ -1446,7 +1474,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { }); }, - updateFileTree: function(files) { + updateFileTree: function (files) { function walk(files, parentNode) { for (var file in files.contents) { var item = files.contents[file]; @@ -1463,7 +1491,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { walk(files, this.getRootNode()); }, - onRender: function(ct, position) { + onRender: function (ct, position) { Deluge.details.FilesTab.superclass.onRender.call(this, ct, position); deluge.menus.filePriorities.on('itemclick', this.onItemClick, this); this.on('contextmenu', this.onContextMenu, this); @@ -1472,7 +1500,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { }); }, - onContextMenu: function(node, e) { + onContextMenu: function (node, e) { e.stopEvent(); var selModel = this.getSelectionModel(); if (selModel.getSelectedNodes().length < 2) { @@ -1482,14 +1510,14 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { deluge.menus.filePriorities.showAt(e.getPoint()); }, - onItemClick: function(baseItem, e) { + onItemClick: function (baseItem, e) { switch (baseItem.id) { case 'expandAll': this.expandAll(); break; default: var indexes = {}; - var walk = function(node) { + var walk = function (node) { if (Ext.isEmpty(node.attributes.fileIndex)) return; indexes[node.attributes.fileIndex] = node.attributes.priority; @@ -1497,9 +1525,9 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { this.getRootNode().cascade(walk); var nodes = this.getSelectionModel().getSelectedNodes(); - Ext.each(nodes, function(node) { + Ext.each(nodes, function (node) { if (!node.isLeaf()) { - var setPriorities = function(node) { + var setPriorities = function (node) { if (Ext.isEmpty(node.attributes.fileIndex)) return; indexes[node.attributes.fileIndex] = baseItem.filePriority; @@ -1521,8 +1549,8 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { [this.torrentId], { file_priorities: priorities }, { - success: function() { - Ext.each(nodes, function(node) { + success: function () { + Ext.each(nodes, function (node) { node.setColumnValue(3, baseItem.filePriority); }); }, @@ -1533,7 +1561,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { } }, - onRequestComplete: function(files, options) { + onRequestComplete: function (files, options) { if (!this.getRootNode().hasChildNodes()) { this.createFileTree(files); } else { @@ -1552,7 +1580,7 @@ Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { */ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { autoScroll: true, @@ -1573,7 +1601,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { Deluge.details.OptionsTab.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.details.OptionsTab.superclass.initComponent.call(this); (this.fieldsets = {}), (this.fields = {}); @@ -1882,7 +1910,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { }); }, - onRender: function(ct, position) { + onRender: function (ct, position) { Deluge.details.OptionsTab.superclass.onRender.call(this, ct, position); // This is another hack I think, so keep an eye out here when upgrading. @@ -1891,17 +1919,17 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { this.doLayout(); }, - clear: function() { + clear: function () { if (this.torrentId == null) return; this.torrentId = null; this.optionsManager.changeId(null); }, - reset: function() { + reset: function () { if (this.torrentId) this.optionsManager.reset(); }, - update: function(torrentId) { + update: function (torrentId) { if (this.torrentId && !torrentId) this.clear(); // we want to clear the pane if we get a null torrent torrentIds if (!torrentId) return; // We do not care about null torrentIds. @@ -1916,33 +1944,33 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { }); }, - onApply: function() { + onApply: function () { var changed = this.optionsManager.getDirty(); deluge.client.core.set_torrent_options([this.torrentId], changed, { - success: function() { + success: function () { this.optionsManager.commit(); }, scope: this, }); }, - onEditTrackers: function() { + onEditTrackers: function () { deluge.editTrackers.show(); }, - onMoveCompletedChecked: function(checkbox, checked) { + onMoveCompletedChecked: function (checkbox, checked) { this.fields.move_completed_path.setDisabled(!checked); if (!checked) return; this.fields.move_completed_path.focus(); }, - onStopRatioChecked: function(checkbox, checked) { + onStopRatioChecked: function (checkbox, checked) { this.fields.remove_at_ratio.setDisabled(!checked); this.fields.stop_ratio.setDisabled(!checked); }, - onRequestComplete: function(torrent, options) { + onRequestComplete: function (torrent, options) { this.fields['private'].setValue(torrent['private']); this.fields['private'].setDisabled(true); delete torrent['private']; @@ -1968,13 +1996,13 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { * See LICENSE for more details. */ -(function() { +(function () { function flagRenderer(value) { if (!value.replace(' ', '').replace(' ', '')) { return ''; } return String.format( - '<img src="{0}flag/{1}" />', + '<img alt="{1}" title="{1}" src="{0}flag/{1}" />', deluge.config.base, value ); @@ -2000,7 +2028,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { // fast way to figure out if we have a peer already. peers: {}, - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { title: _('Peers'), @@ -2033,7 +2061,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { header: _('Client'), width: 125, sortable: true, - renderer: fplain, + renderer: 'htmlEncode', dataIndex: 'client', }, { @@ -2067,19 +2095,19 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { Deluge.details.PeersTab.superclass.constructor.call(this, config); }, - clear: function() { + clear: function () { this.getStore().removeAll(); this.peers = {}; }, - update: function(torrentId) { + update: function (torrentId) { deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Peers, { success: this.onRequestComplete, scope: this, }); }, - onRequestComplete: function(torrent, options) { + onRequestComplete: function (torrent, options) { if (!torrent) return; var store = this.getStore(); @@ -2089,7 +2117,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { // Go through the peers updating and creating peer records Ext.each( torrent.peers, - function(peer) { + function (peer) { if (this.peers[peer.ip]) { var record = store.getById(peer.ip); record.beginEdit(); @@ -2110,7 +2138,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { store.add(newPeers); // Remove any peers that should not be left in the store. - store.each(function(record) { + store.each(function (record) { if (!addresses[record.id]) { store.remove(record); delete this.peers[record.id]; @@ -2143,7 +2171,7 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, { title: _('Status'), autoScroll: true, - onRender: function(ct, position) { + onRender: function (ct, position) { Deluge.details.StatusTab.superclass.onRender.call(this, ct, position); this.progressBar = this.add({ @@ -2159,7 +2187,7 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, { width: 1000, listeners: { render: { - fn: function(panel) { + fn: function (panel) { panel.load({ url: deluge.config.base + 'render/tab_status.html', text: _('Loading') + '...', @@ -2174,14 +2202,14 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, { }); }, - clear: function() { + clear: function () { this.progressBar.updateProgress(0, ' '); for (var k in this.fields) { this.fields[k].innerHTML = ''; } }, - update: function(torrentId) { + update: function (torrentId) { if (!this.fields) this.getFields(); deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Status, { success: this.onRequestComplete, @@ -2189,18 +2217,18 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, { }); }, - onPanelUpdate: function(el, response) { + onPanelUpdate: function (el, response) { this.fields = {}; Ext.each( Ext.query('dd', this.status.body.dom), - function(field) { + function (field) { this.fields[field.className] = field; }, this ); }, - onRequestComplete: function(status) { + onRequestComplete: function (status) { seeds = status.total_seeds > -1 ? status.num_seeds + ' (' + status.total_seeds + ')' @@ -2295,7 +2323,7 @@ Ext.namespace('Deluge.preferences'); * @extends Ext.form.FormPanel */ Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { border: false, @@ -2309,7 +2337,7 @@ Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, { Deluge.preferences.Bandwidth.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.preferences.Bandwidth.superclass.initComponent.call(this); var om = deluge.preferences.getOptionsManager(); @@ -2398,8 +2426,7 @@ Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, { border: false, title: '', defaultType: 'checkbox', - style: - 'padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;', + style: 'padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;', autoHeight: true, }); om.bind( @@ -2503,7 +2530,7 @@ Deluge.preferences.Cache = Ext.extend(Ext.form.FormPanel, { header: false, layout: 'form', - initComponent: function() { + initComponent: function () { Deluge.preferences.Cache.superclass.initComponent.call(this); var om = deluge.preferences.getOptionsManager(); @@ -2564,7 +2591,7 @@ Deluge.preferences.Daemon = Ext.extend(Ext.form.FormPanel, { header: false, layout: 'form', - initComponent: function() { + initComponent: function () { Deluge.preferences.Daemon.superclass.initComponent.call(this); var om = deluge.preferences.getOptionsManager(); @@ -2644,7 +2671,7 @@ Ext.namespace('Deluge.preferences'); * @extends Ext.form.FormPanel */ Deluge.preferences.Downloads = Ext.extend(Ext.FormPanel, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { border: false, @@ -2659,7 +2686,7 @@ Deluge.preferences.Downloads = Ext.extend(Ext.FormPanel, { Deluge.preferences.Downloads.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.preferences.Downloads.superclass.initComponent.call(this); var optMan = deluge.preferences.getOptionsManager(); @@ -2772,7 +2799,7 @@ Deluge.preferences.Encryption = Ext.extend(Ext.form.FormPanel, { title: _('Encryption'), header: false, - initComponent: function() { + initComponent: function () { Deluge.preferences.Encryption.superclass.initComponent.call(this); var optMan = deluge.preferences.getOptionsManager(); @@ -2879,7 +2906,7 @@ Deluge.preferences.InstallPluginWindow = Ext.extend(Ext.Window, { modal: true, plain: true, - initComponent: function() { + initComponent: function () { Deluge.preferences.InstallPluginWindow.superclass.initComponent.call( this ); @@ -2906,7 +2933,7 @@ Deluge.preferences.InstallPluginWindow = Ext.extend(Ext.Window, { }); }, - onInstall: function(field, e) { + onInstall: function (field, e) { this.form.getForm().submit({ url: deluge.config.base + 'upload', waitMsg: _('Uploading your plugin...'), @@ -2915,11 +2942,11 @@ Deluge.preferences.InstallPluginWindow = Ext.extend(Ext.Window, { }); }, - onUploadPlugin: function(info, obj, response, request) { + onUploadPlugin: function (info, obj, response, request) { this.fireEvent('pluginadded'); }, - onUploadSuccess: function(fp, upload) { + onUploadSuccess: function (fp, upload) { this.hide(); if (upload.result.success) { var filename = this.form.getForm().getFieldValues().file; @@ -2955,7 +2982,7 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { header: false, layout: 'form', - initComponent: function() { + initComponent: function () { Deluge.preferences.Interface.superclass.initComponent.call(this); var om = (this.optionsManager = new Deluge.OptionsManager()); @@ -3125,7 +3152,7 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { ); }, - onApply: function() { + onApply: function () { var changed = this.optionsManager.getDirty(); if (!Ext.isObjectEmpty(changed)) { deluge.client.web.set_config(changed, { @@ -3147,7 +3174,7 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { no: _('Close'), }, multiline: false, - fn: function(btnText) { + fn: function (btnText) { if (btnText === 'yes') location.reload(); }, icon: Ext.MessageBox.QUESTION, @@ -3159,21 +3186,21 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { } }, - onOk: function() { + onOk: function () { this.onApply(); }, - onGotConfig: function(config) { + onGotConfig: function (config) { this.optionsManager.set(config); }, - onGotLanguages: function(info, obj, response, request) { + onGotLanguages: function (info, obj, response, request) { info.unshift(['', _('System Default')]); this.language.store.loadData(info); this.language.setValue(this.optionsManager.get('language')); }, - onPasswordChange: function() { + onPasswordChange: function () { var newPassword = this.newPassword.getValue(); if (newPassword != this.confirmPassword.getValue()) { Ext.MessageBox.show({ @@ -3189,7 +3216,7 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { var oldPassword = this.oldPassword.getValue(); deluge.client.auth.change_password(oldPassword, newPassword, { - success: function(result) { + success: function (result) { if (!result) { Ext.MessageBox.show({ title: _('Password'), @@ -3218,11 +3245,11 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { }); }, - onSetConfig: function() { + onSetConfig: function () { this.optionsManager.commit(); }, - onPageShow: function() { + onPageShow: function () { deluge.client.web.get_config({ success: this.onGotConfig, scope: this, @@ -3233,7 +3260,7 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { }); }, - onSSLCheck: function(e, checked) { + onSSLCheck: function (e, checked) { this.pkeyField.setDisabled(!checked); this.certField.setDisabled(!checked); }, @@ -3251,7 +3278,7 @@ Ext.namespace('Deluge.preferences'); // custom Vtype for vtype:'IPAddress' Ext.apply(Ext.form.VTypes, { - IPAddress: function(v) { + IPAddress: function (v) { return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v); }, IPAddressText: 'Must be a numeric IP address', @@ -3268,7 +3295,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { title: _('Network'), header: false, - initComponent: function() { + initComponent: function () { Deluge.preferences.Network.superclass.initComponent.call(this); var optMan = deluge.preferences.getOptionsManager(); @@ -3311,7 +3338,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { height: 22, listeners: { check: { - fn: function(e, checked) { + fn: function (e, checked) { this.listenPort.setDisabled(checked); }, scope: this, @@ -3373,7 +3400,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { height: 22, listeners: { check: { - fn: function(e, checked) { + fn: function (e, checked) { this.outgoingPorts.setDisabled(checked); }, scope: this, @@ -3511,7 +3538,7 @@ Ext.namespace('Deluge.preferences'); * @extends Ext.form.FormPanel */ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { border: false, @@ -3524,7 +3551,7 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { Deluge.preferences.Other.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.preferences.Other.superclass.initComponent.call(this); var optMan = deluge.preferences.getOptionsManager(); @@ -3637,7 +3664,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { '</dl>' ), - initComponent: function() { + initComponent: function () { Deluge.preferences.Plugins.superclass.initComponent.call(this); this.defaultValues = { version: '', @@ -3647,7 +3674,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { }; this.pluginTemplate.compile(); - var checkboxRenderer = function(v, p, record) { + var checkboxRenderer = function (v, p, record) { p.css += ' x-grid3-check-col-td'; return ( '<div class="x-grid3-check-col' + (v ? '-on' : '') + '"> </div>' @@ -3669,7 +3696,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { width: 0.2, sortable: true, tpl: new Ext.XTemplate('{enabled:this.getCheckbox}', { - getCheckbox: function(v) { + getCheckbox: function (v) { return ( '<div class="x-grid3-check-col' + (v ? '-on' : '') + @@ -3738,23 +3765,23 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { deluge.events.on('PluginEnabledEvent', this.onPluginEnabled, this); }, - disablePlugin: function(plugin) { + disablePlugin: function (plugin) { deluge.client.core.disable_plugin(plugin); }, - enablePlugin: function(plugin) { + enablePlugin: function (plugin) { deluge.client.core.enable_plugin(plugin); }, - setInfo: function(plugin) { + setInfo: function (plugin) { if (!this.pluginInfo.rendered) return; var values = plugin || this.defaultValues; this.pluginInfo.body.dom.innerHTML = this.pluginTemplate.apply(values); }, - updatePlugins: function() { - var onGotAvailablePlugins = function(plugins) { - this.availablePlugins = plugins.sort(function(a, b) { + updatePlugins: function () { + var onGotAvailablePlugins = function (plugins) { + this.availablePlugins = plugins.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); @@ -3764,7 +3791,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { }); }; - var onGotEnabledPlugins = function(plugins) { + var onGotEnabledPlugins = function (plugins) { this.enabledPlugins = plugins; this.onGotPlugins(); }; @@ -3775,11 +3802,11 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { }); }, - updatePluginsGrid: function() { + updatePluginsGrid: function () { var plugins = []; Ext.each( this.availablePlugins, - function(plugin) { + function (plugin) { if (this.enabledPlugins.indexOf(plugin) > -1) { plugins.push([true, plugin]); } else { @@ -3791,7 +3818,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { this.list.getStore().loadData(plugins); }, - onNodeClick: function(dv, index, node, e) { + onNodeClick: function (dv, index, node, e) { var el = new Ext.Element(e.target); if (el.getAttribute('rel') != 'chkbox') return; @@ -3806,16 +3833,16 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { } }, - onFindMorePlugins: function() { + onFindMorePlugins: function () { window.open('http://dev.deluge-torrent.org/wiki/Plugins'); }, - onGotPlugins: function() { + onGotPlugins: function () { this.setInfo(); this.updatePluginsGrid(); }, - onGotPluginInfo: function(info) { + onGotPluginInfo: function (info) { var values = { author: info['Author'], version: info['Version'], @@ -3827,7 +3854,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { delete info; }, - onInstallPluginWindow: function() { + onInstallPluginWindow: function () { if (!this.installWindow) { this.installWindow = new Deluge.preferences.InstallPluginWindow(); this.installWindow.on('pluginadded', this.onPluginInstall, this); @@ -3835,7 +3862,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { this.installWindow.show(); }, - onPluginEnabled: function(pluginName) { + onPluginEnabled: function (pluginName) { var index = this.list.getStore().find('plugin', pluginName); if (index == -1) return; var plugin = this.list.getStore().getAt(index); @@ -3843,7 +3870,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { plugin.commit(); }, - onPluginDisabled: function(pluginName) { + onPluginDisabled: function (pluginName) { var index = this.list.getStore().find('plugin', pluginName); if (index == -1) return; var plugin = this.list.getStore().getAt(index); @@ -3851,11 +3878,11 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { plugin.commit(); }, - onPluginInstall: function() { + onPluginInstall: function () { this.updatePlugins(); }, - onPluginSelect: function(dv, selections) { + onPluginSelect: function (dv, selections) { if (selections.length == 0) return; var r = dv.getRecords(selections)[0]; deluge.client.web.get_plugin_info(r.get('plugin'), { @@ -3864,11 +3891,11 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { }); }, - onPreferencesShow: function() { + onPreferencesShow: function () { this.updatePlugins(); }, - onPluginInfoRender: function(ct, position) { + onPluginInfoRender: function (ct, position) { this.setInfo(); }, }); @@ -3910,7 +3937,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { pages: {}, - initComponent: function() { + initComponent: function () { Deluge.preferences.PreferencesWindow.superclass.initComponent.call( this ); @@ -3920,7 +3947,6 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { columns: [ { id: 'name', - renderer: fplain, dataIndex: 'name', }, ], @@ -3968,7 +3994,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { this.initPages(); }, - initPages: function() { + initPages: function () { deluge.preferences = this; this.addPage(new Deluge.preferences.Downloads()); this.addPage(new Deluge.preferences.Network()); @@ -3983,7 +4009,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { this.addPage(new Deluge.preferences.Plugins()); }, - onApply: function(e) { + onApply: function (e) { var changed = this.optionsManager.getDirty(); if (!Ext.isObjectEmpty(changed)) { // Workaround for only displaying single listen port but still pass array to core. @@ -4008,7 +4034,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { * Return the options manager for the preferences window. * @returns {Deluge.OptionsManager} the options manager */ - getOptionsManager: function() { + getOptionsManager: function () { return this.optionsManager; }, @@ -4016,7 +4042,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { * Adds a page to the preferences window. * @param {Mixed} page */ - addPage: function(page) { + addPage: function (page) { var store = this.list.getStore(); var name = page.title; store.add([new PreferencesRecord({ name: name })]); @@ -4031,7 +4057,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { * Removes a preferences page from the window. * @param {mixed} name */ - removePage: function(page) { + removePage: function (page) { var name = page.title; var store = this.list.getStore(); store.removeAt(store.find('name', name)); @@ -4043,7 +4069,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { * Select which preferences page is displayed. * @param {String} page The page name to change to */ - selectPage: function(page) { + selectPage: function (page) { if (this.pages[page].index < 0) { this.pages[page].index = this.configPanel.items.indexOf( this.pages[page] @@ -4053,7 +4079,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { }, // private - doSelectPage: function(page) { + doSelectPage: function (page) { if (this.pages[page].index < 0) { this.pages[page].index = this.configPanel.items.indexOf( this.pages[page] @@ -4064,23 +4090,23 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { }, // private - onGotConfig: function(config) { + onGotConfig: function (config) { this.getOptionsManager().set(config); }, // private - onPageSelect: function(list, selections) { + onPageSelect: function (list, selections) { var r = list.getRecord(selections[0]); this.doSelectPage(r.get('name')); }, // private - onSetConfig: function() { + onSetConfig: function () { this.getOptionsManager().commit(); }, // private - onAfterRender: function() { + onAfterRender: function () { if (!this.list.getSelectionCount()) { this.list.select(0); } @@ -4088,7 +4114,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { }, // private - onShow: function() { + onShow: function () { if (!deluge.client.core) return; deluge.client.core.get_config({ success: this.onGotConfig, @@ -4097,12 +4123,12 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { }, // private - onClose: function() { + onClose: function () { this.hide(); }, // private - onOk: function() { + onOk: function () { var changed = this.optionsManager.getDirty(); if (!Ext.isObjectEmpty(changed)) { deluge.client.core.set_config(changed, { @@ -4138,7 +4164,7 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { autoHeight: true, labelWidth: 70, - initComponent: function() { + initComponent: function () { Deluge.preferences.ProxyField.superclass.initComponent.call(this); this.proxyType = this.add({ xtype: 'combo', @@ -4265,11 +4291,11 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { this.setting = false; }, - getName: function() { + getName: function () { return this.initialConfig.name; }, - getValue: function() { + getValue: function () { return { type: this.proxyType.getValue(), hostname: this.hostname.getValue(), @@ -4285,7 +4311,7 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { }, // Set the values of the proxies - setValue: function(value) { + setValue: function (value) { this.setting = true; this.proxyType.setValue(value['type']); var index = this.proxyType.getStore().find('id', value['type']); @@ -4305,7 +4331,7 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { this.setting = false; }, - onFieldChange: function(field, newValue, oldValue) { + onFieldChange: function (field, newValue, oldValue) { if (this.setting) return; var newValues = this.getValue(); var oldValues = Ext.apply({}, newValues); @@ -4314,7 +4340,7 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { this.fireEvent('change', this, newValues, oldValues); }, - onTypeSelect: function(combo, record, index) { + onTypeSelect: function (combo, record, index) { var typeId = record.get('id'); if (typeId > 0) { this.hostname.show(); @@ -4359,7 +4385,7 @@ Ext.namespace('Deluge.preferences'); * @extends Ext.form.FormPanel */ Deluge.preferences.Proxy = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { border: false, @@ -4373,7 +4399,7 @@ Deluge.preferences.Proxy = Ext.extend(Ext.form.FormPanel, { Deluge.preferences.Proxy.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.preferences.Proxy.superclass.initComponent.call(this); this.proxy = this.add( new Deluge.preferences.ProxyField({ @@ -4385,19 +4411,19 @@ Deluge.preferences.Proxy = Ext.extend(Ext.form.FormPanel, { deluge.preferences.getOptionsManager().bind('proxy', this.proxy); }, - getValue: function() { + getValue: function () { return { proxy: this.proxy.getValue(), }; }, - setValue: function(value) { + setValue: function (value) { for (var proxy in value) { this[proxy].setValue(value[proxy]); } }, - onProxyChange: function(field, newValue, oldValue) { + onProxyChange: function (field, newValue, oldValue) { var newValues = this.getValue(); var oldValues = Ext.apply({}, newValues); oldValues[field.getName()] = oldValue; @@ -4426,7 +4452,7 @@ Deluge.preferences.Queue = Ext.extend(Ext.form.FormPanel, { header: false, layout: 'form', - initComponent: function() { + initComponent: function () { Deluge.preferences.Queue.superclass.initComponent.call(this); var om = deluge.preferences.getOptionsManager(); @@ -4634,7 +4660,7 @@ Deluge.preferences.Queue = Ext.extend(Ext.form.FormPanel, { om.bind('remove_seed_at_ratio', this.removeAtRatio); }, - onStopRatioCheck: function(e, checked) { + onStopRatioCheck: function (e, checked) { this.stopRatio.setDisabled(!checked); this.removeAtRatio.setDisabled(!checked); }, @@ -4656,13 +4682,13 @@ Ext.ns('Deluge'); * @extends Ext.menu.Menu */ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, { - initComponent: function() { + initComponent: function () { Deluge.StatusbarMenu.superclass.initComponent.call(this); this.otherWin = new Deluge.OtherLimitWindow( this.initialConfig.otherWin || {} ); - this.items.each(function(item) { + this.items.each(function (item) { if (item.getXType() != 'menucheckitem') return; if (item.value == 'other') { item.on('click', this.onOtherClicked, this); @@ -4672,14 +4698,14 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, { }, this); }, - setValue: function(value) { + setValue: function (value) { var beenSet = false; // set the new value this.value = value = value == 0 ? -1 : value; var other = null; // uncheck all items - this.items.each(function(item) { + this.items.each(function (item) { if (item.setChecked) { item.suspendEvents(); if (item.value == value) { @@ -4701,18 +4727,18 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, { other.resumeEvents(); }, - onLimitChanged: function(item, checked) { + onLimitChanged: function (item, checked) { if (!checked || item.value == 'other') return; // We do not care about unchecked or other. var config = {}; config[item.group] = item.value; deluge.client.core.set_config(config, { - success: function() { + success: function () { deluge.ui.update(); }, }); }, - onOtherClicked: function(item, e) { + onOtherClicked: function (item, e) { this.otherWin.group = item.group; this.otherWin.setValue(this.value); this.otherWin.show(); @@ -4738,7 +4764,7 @@ Ext.namespace('Deluge'); * @param {Object} config Configuration options */ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { - constructor: function(config) { + constructor: function (config) { config = config || {}; this.binds = {}; this.changed = {}; @@ -4776,7 +4802,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * Add a set of default options and values to the options manager * @param {Object} options The default options. */ - addOptions: function(options) { + addOptions: function (options) { this.options = Ext.applyIf(this.options, options); }, @@ -4785,7 +4811,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String} option * @param {Ext.form.Field} field */ - bind: function(option, field) { + bind: function (option, field) { this.binds[option] = this.binds[option] || []; this.binds[option].push(field); field._doption = option; @@ -4801,7 +4827,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { /** * Changes all the changed values to be the default values */ - commit: function() { + commit: function () { this.options = Ext.apply(this.options, this.changed); this.reset(); }, @@ -4811,7 +4837,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {Mixed} oldValue The original value * @param {Mixed} value The new value to convert */ - convertValueType: function(oldValue, value) { + convertValueType: function (oldValue, value) { if (Ext.type(oldValue) != Ext.type(value)) { switch (Ext.type(oldValue)) { case 'string': @@ -4841,7 +4867,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String} [option] A single option or an array of options to return. * @returns {Object} the options value. */ - get: function() { + get: function () { if (arguments.length == 1) { var option = arguments[0]; return this.isDirty(option) @@ -4851,7 +4877,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { var options = {}; Ext.each( arguments, - function(option) { + function (option) { if (!this.has(option)) return; options[option] = this.isDirty(option) ? this.changed[option] @@ -4868,7 +4894,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String|Array} [option] A single option or an array of options to return. * @returns {Object} the value of the option */ - getDefault: function(option) { + getDefault: function (option) { return this.options[option]; }, @@ -4876,7 +4902,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * Returns the dirty (changed) values. * @returns {Object} the changed options */ - getDirty: function() { + getDirty: function () { return this.changed; }, @@ -4884,7 +4910,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String} [option] The option to check * @returns {Boolean} true if the option has been changed from the default. */ - isDirty: function(option) { + isDirty: function (option) { return !Ext.isEmpty(this.changed[option]); }, @@ -4893,14 +4919,14 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String} option * @returns {Boolean} true if the option exists, else false. */ - has: function(option) { + has: function (option) { return this.options[option]; }, /** * Reset the options back to the default values. */ - reset: function() { + reset: function () { this.changed = {}; }, @@ -4909,7 +4935,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String} option * @param {Object} value The value for the option */ - set: function(option, value) { + set: function (option, value) { if (option === undefined) { return; } else if (typeof option == 'object') { @@ -4929,7 +4955,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {String/Object} option or options to update * @param {Object} [value]; */ - update: function(option, value) { + update: function (option, value) { if (option === undefined) { return; } else if (value === undefined) { @@ -4958,7 +4984,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * Lets the option manager know when a field is blurred so if a value * so value changing operations can continue on that field. */ - onFieldBlur: function(field, event) { + onFieldBlur: function (field, event) { if (this.focused == field) { this.focused = null; } @@ -4969,7 +4995,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @param {Ext.form.Field} field * @private */ - onFieldChange: function(field, event) { + onFieldChange: function (field, event) { if (field.field) field = field.field; // fix for spinners this.update(field._doption, field.getValue()); }, @@ -4978,16 +5004,16 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * Lets the option manager know when a field is focused so if a value changing * operation is performed it will not change the value of the field. */ - onFieldFocus: function(field, event) { + onFieldFocus: function (field, event) { this.focused = field; }, - onChange: function(option, newValue, oldValue) { + onChange: function (option, newValue, oldValue) { // If we don't have a bind there's nothing to do. if (Ext.isEmpty(this.binds[option])) return; Ext.each( this.binds[option], - function(bind) { + function (bind) { // The field is currently focused so we do not want to change it. if (bind == this.focused) return; // Set the form field to the new value. @@ -5027,16 +5053,16 @@ Deluge.about.AboutWindow = Ext.extend(Ext.Window, { }, buttonAlign: 'center', - initComponent: function() { + initComponent: function () { Deluge.about.AboutWindow.superclass.initComponent.call(this); this.addEvents({ build_ready: true, }); var self = this; - var libtorrent = function() { + var libtorrent = function () { deluge.client.core.get_libtorrent_version({ - success: function(lt_version) { + success: function (lt_version) { comment += '<br/>' + _('libtorrent:') + ' ' + lt_version; Ext.getCmp('about_comment').setText(comment, false); self.fireEvent('build_ready'); @@ -5056,10 +5082,10 @@ Deluge.about.AboutWindow = Ext.extend(Ext.Window, { client_version + '<br/>'; deluge.client.web.connected({ - success: function(connected) { + success: function (connected) { if (connected) { deluge.client.daemon.get_version({ - success: function(server_version) { + success: function (server_version) { comment += _('Server:') + ' ' + server_version + '<br/>'; libtorrent(); @@ -5069,7 +5095,7 @@ Deluge.about.AboutWindow = Ext.extend(Ext.Window, { this.fireEvent('build_ready'); } }, - failure: function() { + failure: function () { this.fireEvent('build_ready'); }, scope: this, @@ -5103,27 +5129,26 @@ Deluge.about.AboutWindow = Ext.extend(Ext.Window, { { xtype: 'label', style: 'padding-top: 5px; font-size: 12px;', - html: - '<a href="https://deluge-torrent.org" target="_blank">deluge-torrent.org</a>', + html: '<a href="https://deluge-torrent.org" target="_blank">deluge-torrent.org</a>', }, ]); this.addButton(_('Close'), this.onCloseClick, this); }, - show: function() { - this.on('build_ready', function() { + show: function () { + this.on('build_ready', function () { Deluge.about.AboutWindow.superclass.show.call(this); }); }, - onCloseClick: function() { + onCloseClick: function () { this.close(); }, }); Ext.namespace('Deluge'); -Deluge.About = function() { +Deluge.About = function () { new Deluge.about.AboutWindow().show(); }; /** @@ -5152,7 +5177,7 @@ Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { bodyStyle: 'padding: 10px 5px;', closeAction: 'hide', - initComponent: function() { + initComponent: function () { Deluge.AddConnectionWindow.superclass.initComponent.call(this); this.addEvents('hostadded'); @@ -5208,7 +5233,7 @@ Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { }); }, - onAddClick: function() { + onAddClick: function () { var values = this.form.getForm().getValues(); deluge.client.web.add_host( values.host, @@ -5216,7 +5241,7 @@ Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { values.username, values.password, { - success: function(result) { + success: function (result) { if (!result[0]) { Ext.MessageBox.show({ title: _('Error'), @@ -5239,7 +5264,7 @@ Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { ); }, - onHide: function() { + onHide: function () { this.form.getForm().reset(); }, }); @@ -5255,9 +5280,10 @@ Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { Ext.ns('Deluge'); // Custom VType validator for tracker urls -var trackerUrlTest = /(((^https?)|(^udp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; +var trackerUrlTest = + /(((^https?)|(^udp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; Ext.apply(Ext.form.VTypes, { - trackerUrl: function(val, field) { + trackerUrl: function (val, field) { return trackerUrlTest.test(val); }, trackerUrlText: 'Not a valid tracker url', @@ -5281,7 +5307,7 @@ Deluge.AddTrackerWindow = Ext.extend(Ext.Window, { closeAction: 'hide', iconCls: 'x-deluge-edit-trackers', - initComponent: function() { + initComponent: function () { Deluge.AddTrackerWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancelClick, this); @@ -5304,17 +5330,14 @@ Deluge.AddTrackerWindow = Ext.extend(Ext.Window, { }); }, - onAddClick: function() { - var trackers = this.form - .getForm() - .findField('trackers') - .getValue(); + onAddClick: function () { + var trackers = this.form.getForm().findField('trackers').getValue(); trackers = trackers.split('\n'); var cleaned = []; Ext.each( trackers, - function(tracker) { + function (tracker) { if (Ext.form.VTypes.trackerUrl(tracker)) { cleaned.push(tracker); } @@ -5323,17 +5346,11 @@ Deluge.AddTrackerWindow = Ext.extend(Ext.Window, { ); this.fireEvent('add', cleaned); this.hide(); - this.form - .getForm() - .findField('trackers') - .setValue(''); + this.form.getForm().findField('trackers').setValue(''); }, - onCancelClick: function() { - this.form - .getForm() - .findField('trackers') - .setValue(''); + onCancelClick: function () { + this.form.getForm().findField('trackers').setValue(''); this.hide(); }, }); @@ -5370,7 +5387,7 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { * Fires when the client has retrieved the list of methods from the server. * @param {Ext.ux.util.RpcClient} this */ - constructor: function(config) { + constructor: function (config) { Ext.ux.util.RpcClient.superclass.constructor.call(this, config); this._url = config.url || null; this._id = 0; @@ -5383,14 +5400,14 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { this.reloadMethods(); }, - reloadMethods: function() { + reloadMethods: function () { this._execute('system.listMethods', { success: this._setMethods, scope: this, }); }, - _execute: function(method, options) { + _execute: function (method, options) { options = options || {}; options.params = options.params || []; options.id = this._id; @@ -5413,7 +5430,7 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { }); }, - _onFailure: function(response, requestOptions) { + _onFailure: function (response, requestOptions) { var options = requestOptions.options; errorObj = { id: options.id, @@ -5439,7 +5456,7 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { } }, - _onSuccess: function(response, requestOptions) { + _onSuccess: function (response, requestOptions) { var responseObj = Ext.decode(response.responseText); var options = requestOptions.options; if (responseObj.error) { @@ -5477,9 +5494,9 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { } }, - _parseArgs: function(args) { + _parseArgs: function (args) { var params = []; - Ext.each(args, function(arg) { + Ext.each(args, function (arg) { params.push(arg); }); @@ -5488,7 +5505,7 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { var keys = Ext.keys(options), isOption = false; - Ext.each(this._optionKeys, function(key) { + Ext.each(this._optionKeys, function (key) { if (keys.indexOf(key) > -1) isOption = true; }); @@ -5504,15 +5521,15 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { return options; }, - _setMethods: function(methods) { + _setMethods: function (methods) { var components = {}, self = this; - Ext.each(methods, function(method) { + Ext.each(methods, function (method) { var parts = method.split('.'); var component = components[parts[0]] || {}; - var fn = function() { + var fn = function () { var options = self._parseArgs(arguments); return self._execute(method, options); }; @@ -5525,7 +5542,7 @@ Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { } Ext.each( this._components, - function(component) { + function (component) { if (!component in components) { delete this[component]; } @@ -5559,7 +5576,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { title: _('Connection Manager'), iconCls: 'x-deluge-connect-window-icon', - initComponent: function() { + initComponent: function () { Deluge.ConnectionManager.superclass.initComponent.call(this); this.on('hide', this.onHide, this); this.on('show', this.onShow, this); @@ -5671,9 +5688,9 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { * Check to see if the the web interface is currently connected * to a Deluge Daemon and show the Connection Manager if not. */ - checkConnected: function() { + checkConnected: function () { deluge.client.web.connected({ - success: function(connected) { + success: function (connected) { if (connected) { deluge.events.fire('connect'); } else { @@ -5684,7 +5701,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }); }, - disconnect: function(show) { + disconnect: function (show) { deluge.events.fire('disconnect'); if (show) { if (this.isVisible()) return; @@ -5692,15 +5709,15 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { } }, - loadHosts: function() { + loadHosts: function () { deluge.client.web.get_hosts({ success: this.onGetHosts, scope: this, }); }, - update: function() { - this.list.getStore().each(function(r) { + update: function () { + this.list.getStore().each(function (r) { deluge.client.web.get_host_status(r.id, { success: this.onGetHostStatus, scope: this, @@ -5713,7 +5730,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { * passed in records host state. * @param {Ext.data.Record} record The hosts record to update the UI for */ - updateButtons: function(record) { + updateButtons: function (record) { var button = this.buttons[1], status = record.get('status'); @@ -5747,7 +5764,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onAddClick: function(button, e) { + onAddClick: function (button, e) { if (!this.addWindow) { this.addWindow = new Deluge.AddConnectionWindow(); this.addWindow.on('hostadded', this.onHostChange, this); @@ -5756,7 +5773,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onEditClick: function(button, e) { + onEditClick: function (button, e) { var connection = this.list.getSelectedRecords()[0]; if (!connection) return; @@ -5768,24 +5785,24 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onHostChange: function() { + onHostChange: function () { this.loadHosts(); }, // private - onClose: function(e) { + onClose: function (e) { this.hide(); }, // private - onConnect: function(e) { + onConnect: function (e) { var selected = this.list.getSelectedRecords()[0]; if (!selected) return; var me = this; - var disconnect = function() { + var disconnect = function () { deluge.client.web.disconnect({ - success: function(result) { + success: function (result) { this.update(this); deluge.events.fire('disconnect'); }, @@ -5806,11 +5823,11 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { var id = selected.id; deluge.client.web.connect(id, { - success: function(methods) { + success: function (methods) { deluge.client.reloadMethods(); deluge.client.on( 'connected', - function(e) { + function (e) { deluge.events.fire('connect'); }, this, @@ -5823,11 +5840,11 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onGetHosts: function(hosts) { + onGetHosts: function (hosts) { this.list.getStore().loadData(hosts); Ext.each( hosts, - function(host) { + function (host) { deluge.client.web.get_host_status(host[0], { success: this.onGetHostStatus, scope: this, @@ -5838,7 +5855,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onGetHostStatus: function(host) { + onGetHostStatus: function (host) { var record = this.list.getStore().getById(host[0]); record.set('status', host[1]); record.set('version', host[2]); @@ -5849,19 +5866,19 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onHide: function() { + onHide: function () { if (this.running) window.clearInterval(this.running); }, // private - onLogin: function() { + onLogin: function () { if (deluge.config.first_login) { Ext.MessageBox.confirm( _('Change Default Password'), _( 'We recommend changing the default password.<br><br>Would you like to change it now?' ), - function(res) { + function (res) { this.checkConnected(); if (res == 'yes') { deluge.preferences.show(); @@ -5877,7 +5894,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onLogout: function() { + onLogout: function () { this.disconnect(); if (!this.hidden && this.rendered) { this.hide(); @@ -5885,12 +5902,12 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onRemoveClick: function(button) { + onRemoveClick: function (button) { var connection = this.list.getSelectedRecords()[0]; if (!connection) return; deluge.client.web.remove_host(connection.id, { - success: function(result) { + success: function (result) { if (!result) { Ext.MessageBox.show({ title: _('Error'), @@ -5909,7 +5926,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onSelectionChanged: function(list, selections) { + onSelectionChanged: function (list, selections) { if (selections[0]) { this.editHostButton.enable(); this.removeHostButton.enable(); @@ -5925,7 +5942,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { // FIXME: Find out why this is being fired twice // private - onShow: function() { + onShow: function () { if (!this.addHostButton) { var bbar = this.panel.getBottomToolbar(); this.addHostButton = bbar.items.get('cm-add'); @@ -5939,7 +5956,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { }, // private - onStopClick: function(button, e) { + onStopClick: function (button, e) { var connection = this.list.getSelectedRecords()[0]; if (!connection) return; @@ -5949,7 +5966,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { } else { // This means we need to stop the daemon deluge.client.web.stop_daemon(connection.id, { - success: function(result) { + success: function (result) { if (!result[0]) { Ext.MessageBox.show({ title: _('Error'), @@ -5965,6 +5982,79 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, { } }, }); +/* + * Deluge.CopyMagnet.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.CopyMagnet = Ext.extend(Ext.Window, { + title: _('Copy Magnet URI'), + width: 375, + closeAction: 'hide', + iconCls: 'icon-magnet-copy', + + initComponent: function () { + Deluge.CopyMagnet.superclass.initComponent.call(this); + form = this.add({ + xtype: 'form', + defaultType: 'textfield', + hideLabels: true, + }); + this.magnetURI = form.add({ + name: 'URI', + anchor: '100%', + }); + this.addButton(_('Close'), this.onClose, this); + this.addButton(_('Copy'), this.onCopy, this); + }, + show: function (a) { + Deluge.CopyMagnet.superclass.show.call(this); + var torrent = deluge.torrents.getSelected(); + deluge.client.core.get_magnet_uri(torrent.id, { + success: this.onRequestComplete, + scope: this, + }); + }, + onRequestComplete: function (uri) { + this.magnetURI.setValue(uri); + }, + onCopy: function () { + this.magnetURI.focus(); + this.magnetURI.el.dom.select(); + document.execCommand('copy'); + }, + onClose: function () { + this.hide(); + }, +}); + +deluge.copyMagnetWindow = new Deluge.CopyMagnet(); /** * Deluge.js * @@ -5992,21 +6082,14 @@ Ext.state.Manager.setProvider( // Add some additional functions to ext and setup some of the // configurable parameters Ext.apply(Ext, { - escapeHTML: function(text) { - text = String(text) - .replace('<', '<') - .replace('>', '>'); - return text.replace('&', '&'); - }, - - isObjectEmpty: function(obj) { + isObjectEmpty: function (obj) { for (var i in obj) { return false; } return true; }, - areObjectsEqual: function(obj1, obj2) { + areObjectsEqual: function (obj1, obj2) { var equal = true; if (!obj1 || !obj2) return false; for (var i in obj1) { @@ -6017,7 +6100,7 @@ Ext.apply(Ext, { return equal; }, - keys: function(obj) { + keys: function (obj) { var keys = []; for (var i in obj) if (obj.hasOwnProperty(i)) { @@ -6026,7 +6109,7 @@ Ext.apply(Ext, { return keys; }, - values: function(obj) { + values: function (obj) { var values = []; for (var i in obj) { if (obj.hasOwnProperty(i)) { @@ -6036,7 +6119,7 @@ Ext.apply(Ext, { return values; }, - splat: function(obj) { + splat: function (obj) { var type = Ext.type(obj); return type ? (type != 'array' ? [obj] : obj) : []; }, @@ -6073,7 +6156,7 @@ Ext.apply(Deluge, { * @param {String} text The text to display on the bar * @param {Number} modified Amount to subtract from the width allowing for fixes */ - progressBar: function(progress, width, text, modifier) { + progressBar: function (progress, width, text, modifier) { modifier = Ext.value(modifier, 10); var progressWidth = ((width / 100.0) * progress).toFixed(0); var barWidth = progressWidth - 1; @@ -6092,7 +6175,7 @@ Ext.apply(Deluge, { * Constructs a new instance of the specified plugin. * @param {String} name The plugin name to create */ - createPlugin: function(name) { + createPlugin: function (name) { return new Deluge.pluginStore[name](); }, @@ -6100,7 +6183,7 @@ Ext.apply(Deluge, { * Check to see if a plugin has been registered. * @param {String} name The plugin name to check */ - hasPlugin: function(name) { + hasPlugin: function (name) { return Deluge.pluginStore[name] ? true : false; }, @@ -6109,7 +6192,7 @@ Ext.apply(Deluge, { * @param {String} name The plugin name to register * @param {Plugin} plugin The plugin to register */ - registerPlugin: function(name, plugin) { + registerPlugin: function (name, plugin) { Deluge.pluginStore[name] = plugin; }, }); @@ -6177,7 +6260,7 @@ Deluge.EditConnectionWindow = Ext.extend(Ext.Window, { bodyStyle: 'padding: 10px 5px;', closeAction: 'hide', - initComponent: function() { + initComponent: function () { Deluge.EditConnectionWindow.superclass.initComponent.call(this); this.addEvents('hostedited'); @@ -6233,17 +6316,11 @@ Deluge.EditConnectionWindow = Ext.extend(Ext.Window, { }); }, - show: function(connection) { + show: function (connection) { Deluge.EditConnectionWindow.superclass.show.call(this); - this.form - .getForm() - .findField('host') - .setValue(connection.get('host')); - this.form - .getForm() - .findField('port') - .setValue(connection.get('port')); + this.form.getForm().findField('host').setValue(connection.get('host')); + this.form.getForm().findField('port').setValue(connection.get('port')); this.form .getForm() .findField('username') @@ -6251,7 +6328,7 @@ Deluge.EditConnectionWindow = Ext.extend(Ext.Window, { this.host_id = connection.id; }, - onEditClick: function() { + onEditClick: function () { var values = this.form.getForm().getValues(); deluge.client.web.edit_host( this.host_id, @@ -6260,7 +6337,7 @@ Deluge.EditConnectionWindow = Ext.extend(Ext.Window, { values.username, values.password, { - success: function(result) { + success: function (result) { if (!result) { console.log(result); Ext.MessageBox.show({ @@ -6281,7 +6358,7 @@ Deluge.EditConnectionWindow = Ext.extend(Ext.Window, { ); }, - onHide: function() { + onHide: function () { this.form.getForm().reset(); }, }); @@ -6314,7 +6391,7 @@ Deluge.EditTrackerWindow = Ext.extend(Ext.Window, { closeAction: 'hide', iconCls: 'x-deluge-edit-trackers', - initComponent: function() { + initComponent: function () { Deluge.EditTrackerWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancelClick, this); @@ -6337,32 +6414,23 @@ Deluge.EditTrackerWindow = Ext.extend(Ext.Window, { }); }, - show: function(record) { + show: function (record) { Deluge.EditTrackerWindow.superclass.show.call(this); this.record = record; - this.form - .getForm() - .findField('tracker') - .setValue(record.data['url']); + this.form.getForm().findField('tracker').setValue(record.data['url']); }, - onCancelClick: function() { + onCancelClick: function () { this.hide(); }, - onHide: function() { - this.form - .getForm() - .findField('tracker') - .setValue(''); + onHide: function () { + this.form.getForm().findField('tracker').setValue(''); }, - onSaveClick: function() { - var url = this.form - .getForm() - .findField('tracker') - .getValue(); + onSaveClick: function () { + var url = this.form.getForm().findField('tracker').getValue(); this.record.set('url', url); this.record.commit(); this.hide(); @@ -6380,7 +6448,7 @@ Deluge.EditTrackerWindow = Ext.extend(Ext.Window, { Ext.ns('Deluge'); /** - * @class Deluge.EditTrackerWindow + * @class Deluge.EditTrackersWindow * @extends Ext.Window */ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { @@ -6398,7 +6466,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { closeAction: 'hide', iconCls: 'x-deluge-edit-trackers', - initComponent: function() { + initComponent: function () { Deluge.EditTrackersWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancelClick, this); @@ -6427,6 +6495,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { header: _('Tracker'), width: 0.9, dataIndex: 'url', + tpl: new Ext.XTemplate('{url:htmlEncode}'), }, ], columnSort: { @@ -6481,18 +6550,18 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { }); }, - onAddClick: function() { + onAddClick: function () { this.addWindow.show(); }, - onAddTrackers: function(trackers) { + onAddTrackers: function (trackers) { var store = this.list.getStore(); Ext.each( trackers, - function(tracker) { + function (tracker) { var duplicate = false, heightestTier = -1; - store.each(function(record) { + store.each(function (record) { if (record.get('tier') > heightestTier) { heightestTier = record.get('tier'); } @@ -6513,27 +6582,27 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { ); }, - onCancelClick: function() { + onCancelClick: function () { this.hide(); }, - onEditClick: function() { + onEditClick: function () { var selected = this.list.getSelectedRecords()[0]; if (!selected) return; this.editWindow.show(selected); }, - onHide: function() { + onHide: function () { this.list.getStore().removeAll(); }, - onListNodeDblClicked: function(list, index, node, e) { + onListNodeDblClicked: function (list, index, node, e) { this.editWindow.show(this.list.getRecord(node)); }, - onOkClick: function() { + onOkClick: function () { var trackers = []; - this.list.getStore().each(function(record) { + this.list.getStore().each(function (record) { trackers.push({ tier: record.get('tier'), url: record.get('url'), @@ -6548,34 +6617,28 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { this.hide(); }, - onRemoveClick: function() { + onRemoveClick: function () { // Remove from the grid var selected = this.list.getSelectedRecords()[0]; if (!selected) return; this.list.getStore().remove(selected); }, - onRequestComplete: function(status) { + onRequestComplete: function (status) { this.list.getStore().loadData(status); this.list.getStore().sort('tier', 'ASC'); }, - onSaveFail: function() {}, + onSaveFail: function () {}, - onSelect: function(list) { + onSelect: function (list) { if (list.getSelectionCount()) { - this.panel - .getBottomToolbar() - .items.get(4) - .enable(); + this.panel.getBottomToolbar().items.get(4).enable(); } }, - onShow: function() { - this.panel - .getBottomToolbar() - .items.get(4) - .disable(); + onShow: function () { + this.panel.getBottomToolbar().items.get(4).disable(); var r = deluge.torrents.getSelected(); this.torrentId = r.id; deluge.client.core.get_torrent_status(r.id, ['trackers'], { @@ -6584,7 +6647,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { }); }, - onDownClick: function() { + onDownClick: function () { var r = this.list.getSelectedRecords()[0]; if (!r) return; @@ -6595,7 +6658,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { this.list.select(r.store.indexOf(r)); }, - onUpClick: function() { + onUpClick: function () { var r = this.list.getSelectedRecords()[0]; if (!r) return; @@ -6624,7 +6687,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { * Class for holding global events that occur within the UI. */ Deluge.EventsManager = Ext.extend(Ext.util.Observable, { - constructor: function() { + constructor: function () { this.toRegister = []; this.on('login', this.onLogin, this); Deluge.EventsManager.superclass.constructor.call(this); @@ -6633,7 +6696,7 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, { /** * Append an event handler to this object. */ - addListener: function(eventName, fn, scope, o) { + addListener: function (eventName, fn, scope, o) { this.addEvents(eventName); if (/[A-Z]/.test(eventName.substring(0, 1))) { if (!deluge.client) { @@ -6651,7 +6714,7 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, { ); }, - getEvents: function() { + getEvents: function () { deluge.client.web.get_events({ success: this.onGetEventsSuccess, failure: this.onGetEventsFailure, @@ -6662,8 +6725,8 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, { /** * Starts the EventsManagerManager checking for events. */ - start: function() { - Ext.each(this.toRegister, function(eventName) { + start: function () { + Ext.each(this.toRegister, function (eventName) { deluge.client.web.register_event_listener(eventName); }); this.running = true; @@ -6674,21 +6737,21 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, { /** * Stops the EventsManagerManager checking for events. */ - stop: function() { + stop: function () { this.running = false; }, // private - onLogin: function() { + onLogin: function () { this.start(); }, - onGetEventsSuccess: function(events) { + onGetEventsSuccess: function (events) { if (!this.running) return; if (events) { Ext.each( events, - function(event) { + function (event) { var name = event[0], args = event[1]; args.splice(0, 0, name); @@ -6701,7 +6764,7 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, { }, // private - onGetEventsFailure: function(result, error) { + onGetEventsFailure: function (result, error) { // the request timed out or we had a communication failure if (!this.running) return; if (!error.isTimeout && this.errorCount++ >= 3) { @@ -6742,7 +6805,7 @@ Deluge.FileBrowser = Ext.extend(Ext.Window, { width: 500, height: 400, - initComponent: function() { + initComponent: function () { Deluge.FileBrowser.superclass.initComponent.call(this); this.add({ @@ -6790,7 +6853,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { show_zero: null, - initComponent: function() { + initComponent: function () { Deluge.FilterPanel.superclass.initComponent.call(this); this.filterType = this.initialConfig.filter; var title = ''; @@ -6806,7 +6869,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { (title = this.filterType.replace('_', ' ')), (parts = title.split(' ')), (title = ''); - Ext.each(parts, function(p) { + Ext.each(parts, function (p) { fl = p.substring(0, 1).toUpperCase(); title += fl + p.substring(1) + ' '; }); @@ -6845,7 +6908,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { * Return the currently selected filter state * @returns {String} the current filter state */ - getState: function() { + getState: function () { if (!this.list.getSelectionCount()) return; var state = this.list.getSelectedRecords()[0]; @@ -6857,7 +6920,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { /** * Return the current states in the filter */ - getStates: function() { + getStates: function () { return this.states; }, @@ -6865,18 +6928,18 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { * Return the Store for the ListView of the FilterPanel * @returns {Ext.data.Store} the ListView store */ - getStore: function() { + getStore: function () { return this.list.getStore(); }, /** * Update the states in the FilterPanel */ - updateStates: function(states) { + updateStates: function (states) { this.states = {}; Ext.each( states, - function(state) { + function (state) { this.states[state[0]] = state[1]; }, this @@ -6888,7 +6951,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { : this.show_zero; if (!show_zero) { var newStates = []; - Ext.each(states, function(state) { + Ext.each(states, function (state) { if (state[1] > 0 || state[0] == 'All') { newStates.push(state); } @@ -6900,7 +6963,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { var filters = {}; Ext.each( states, - function(s, i) { + function (s, i) { var record = store.getById(s[0]); if (!record) { record = new store.recordType({ @@ -6919,7 +6982,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { this ); - store.each(function(record) { + store.each(function (record) { if (filters[record.id]) return; store.remove(record); var selected = this.list.getSelectedRecords()[0]; @@ -6941,7 +7004,7 @@ Deluge.FilterPanel.templates = { tracker_host: '<div class="x-deluge-filter" style="background-image: url(' + deluge.config.base + - 'tracker/{filter});">{filter} ({count})</div>', + 'tracker/{filter});">{filter:htmlEncode} ({count})</div>', }; /** * Deluge.Formatters.js @@ -6960,7 +7023,23 @@ Deluge.FilterPanel.templates = { * @version 1.3 * @singleton */ -Deluge.Formatters = { +Deluge.Formatters = (function () { + var charToEntity = { + '&': '&', + '>': '>', + '<': '<', + '"': '"', + "'": ''', + }; + + var charToEntityRegex = new RegExp( + '(' + Object.keys(charToEntity).join('|') + ')', + 'g' + ); + var htmlEncodeReplaceFn = function (match, capture) { + return charToEntity[capture]; + }; + /** * Formats a date string in the date representation of the current locale, * based on the systems timezone. @@ -6969,154 +7048,162 @@ Deluge.Formatters = { * @return {String} a string in the date representation of the current locale * or "" if seconds < 0. */ - date: function(timestamp) { - function zeroPad(num, count) { - var numZeropad = num + ''; - while (numZeropad.length < count) { - numZeropad = '0' + numZeropad; + return (Formatters = { + date: function (timestamp) { + function zeroPad(num, count) { + var numZeropad = num + ''; + while (numZeropad.length < count) { + numZeropad = '0' + numZeropad; + } + return numZeropad; } - return numZeropad; - } - timestamp = timestamp * 1000; - var date = new Date(timestamp); - return String.format( - '{0}/{1}/{2} {3}:{4}:{5}', - zeroPad(date.getDate(), 2), - zeroPad(date.getMonth() + 1, 2), - date.getFullYear(), - zeroPad(date.getHours(), 2), - zeroPad(date.getMinutes(), 2), - zeroPad(date.getSeconds(), 2) - ); - }, + timestamp = timestamp * 1000; + var date = new Date(timestamp); + return String.format( + '{0}/{1}/{2} {3}:{4}:{5}', + zeroPad(date.getDate(), 2), + zeroPad(date.getMonth() + 1, 2), + date.getFullYear(), + zeroPad(date.getHours(), 2), + zeroPad(date.getMinutes(), 2), + zeroPad(date.getSeconds(), 2) + ); + }, - /** - * Formats the bytes value into a string with KiB, MiB or GiB units. - * - * @param {Number} bytes the filesize in bytes - * @param {Boolean} showZero pass in true to displays 0 values - * @return {String} formatted string with KiB, MiB or GiB units. - */ - size: function(bytes, showZero) { - if (!bytes && !showZero) return ''; - bytes = bytes / 1024.0; + /** + * Formats the bytes value into a string with KiB, MiB or GiB units. + * + * @param {Number} bytes the filesize in bytes + * @param {Boolean} showZero pass in true to displays 0 values + * @return {String} formatted string with KiB, MiB or GiB units. + */ + size: function (bytes, showZero) { + if (!bytes && !showZero) return ''; + bytes = bytes / 1024.0; - if (bytes < 1024) { - return bytes.toFixed(1) + ' KiB'; - } else { - bytes = bytes / 1024; - } + if (bytes < 1024) { + return bytes.toFixed(1) + ' KiB'; + } else { + bytes = bytes / 1024; + } - if (bytes < 1024) { - return bytes.toFixed(1) + ' MiB'; - } else { - bytes = bytes / 1024; - } + if (bytes < 1024) { + return bytes.toFixed(1) + ' MiB'; + } else { + bytes = bytes / 1024; + } - return bytes.toFixed(1) + ' GiB'; - }, + return bytes.toFixed(1) + ' GiB'; + }, - /** - * Formats the bytes value into a string with K, M or G units. - * - * @param {Number} bytes the filesize in bytes - * @param {Boolean} showZero pass in true to displays 0 values - * @return {String} formatted string with K, M or G units. - */ - sizeShort: function(bytes, showZero) { - if (!bytes && !showZero) return ''; - bytes = bytes / 1024.0; + /** + * Formats the bytes value into a string with K, M or G units. + * + * @param {Number} bytes the filesize in bytes + * @param {Boolean} showZero pass in true to displays 0 values + * @return {String} formatted string with K, M or G units. + */ + sizeShort: function (bytes, showZero) { + if (!bytes && !showZero) return ''; + bytes = bytes / 1024.0; - if (bytes < 1024) { - return bytes.toFixed(1) + ' K'; - } else { - bytes = bytes / 1024; - } + if (bytes < 1024) { + return bytes.toFixed(1) + ' K'; + } else { + bytes = bytes / 1024; + } - if (bytes < 1024) { - return bytes.toFixed(1) + ' M'; - } else { - bytes = bytes / 1024; - } + if (bytes < 1024) { + return bytes.toFixed(1) + ' M'; + } else { + bytes = bytes / 1024; + } - return bytes.toFixed(1) + ' G'; - }, + return bytes.toFixed(1) + ' G'; + }, - /** - * Formats a string to display a transfer speed utilizing {@link #size} - * - * @param {Number} bytes the number of bytes per second - * @param {Boolean} showZero pass in true to displays 0 values - * @return {String} formatted string with KiB, MiB or GiB units. - */ - speed: function(bytes, showZero) { - return !bytes && !showZero ? '' : fsize(bytes, showZero) + '/s'; - }, + /** + * Formats a string to display a transfer speed utilizing {@link #size} + * + * @param {Number} bytes the number of bytes per second + * @param {Boolean} showZero pass in true to displays 0 values + * @return {String} formatted string with KiB, MiB or GiB units. + */ + speed: function (bytes, showZero) { + return !bytes && !showZero ? '' : fsize(bytes, showZero) + '/s'; + }, - /** - * Formats a string to show time in a human readable form. - * - * @param {Number} time the number of seconds - * @return {String} a formatted time string. will return '' if seconds == 0 - */ - timeRemaining: function(time) { - if (time <= 0) { - return '∞'; - } - time = time.toFixed(0); - if (time < 60) { - return time + 's'; - } else { - time = time / 60; - } + /** + * Formats a string to show time in a human readable form. + * + * @param {Number} time the number of seconds + * @return {String} a formatted time string. will return '' if seconds == 0 + */ + timeRemaining: function (time) { + if (time <= 0) { + return '∞'; + } + time = time.toFixed(0); + if (time < 60) { + return time + 's'; + } else { + time = time / 60; + } - if (time < 60) { - var minutes = Math.floor(time); - var seconds = Math.round(60 * (time - minutes)); - if (seconds > 0) { - return minutes + 'm ' + seconds + 's'; + if (time < 60) { + var minutes = Math.floor(time); + var seconds = Math.round(60 * (time - minutes)); + if (seconds > 0) { + return minutes + 'm ' + seconds + 's'; + } else { + return minutes + 'm'; + } } else { - return minutes + 'm'; + time = time / 60; } - } else { - time = time / 60; - } - if (time < 24) { - var hours = Math.floor(time); - var minutes = Math.round(60 * (time - hours)); - if (minutes > 0) { - return hours + 'h ' + minutes + 'm'; + if (time < 24) { + var hours = Math.floor(time); + var minutes = Math.round(60 * (time - hours)); + if (minutes > 0) { + return hours + 'h ' + minutes + 'm'; + } else { + return hours + 'h'; + } } else { - return hours + 'h'; + time = time / 24; } - } else { - time = time / 24; - } - var days = Math.floor(time); - var hours = Math.round(24 * (time - days)); - if (hours > 0) { - return days + 'd ' + hours + 'h'; - } else { - return days + 'd'; - } - }, + var days = Math.floor(time); + var hours = Math.round(24 * (time - days)); + if (hours > 0) { + return days + 'd ' + hours + 'h'; + } else { + return days + 'd'; + } + }, - /** - * Simply returns the value untouched, for when no formatting is required. - * - * @param {Mixed} value the value to be displayed - * @return the untouched value. - */ - plain: function(value) { - return value; - }, + /** + * Simply returns the value untouched, for when no formatting is required. + * + * @param {Mixed} value the value to be displayed + * @return the untouched value. + */ + plain: function (value) { + return value; + }, - cssClassEscape: function(value) { - return value.toLowerCase().replace('.', '_'); - }, -}; + cssClassEscape: function (value) { + return value.toLowerCase().replace('.', '_'); + }, + + htmlEncode: function (value) { + return !value + ? value + : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn); + }, + }); +})(); var fsize = Deluge.Formatters.size; var fsize_short = Deluge.Formatters.sizeShort; var fspeed = Deluge.Formatters.speed; @@ -7124,6 +7211,7 @@ var ftime = Deluge.Formatters.timeRemaining; var fdate = Deluge.Formatters.date; var fplain = Deluge.Formatters.plain; Ext.util.Format.cssClassEscape = Deluge.Formatters.cssClassEscape; +Ext.util.Format.htmlEncode = Deluge.Formatters.htmlEncode; /** * Deluge.Keys.js * @@ -7259,7 +7347,7 @@ Deluge.Keys = { // Merge the grid and status keys together as the status keys contain all the // grid ones. -Ext.each(Deluge.Keys.Grid, function(key) { +Ext.each(Deluge.Keys.Grid, function (key) { Deluge.Keys.Status.push(key); }); /** @@ -7287,7 +7375,7 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, { width: 300, height: 120, - initComponent: function() { + initComponent: function () { Deluge.LoginWindow.superclass.initComponent.call(this); this.on('show', this.onShow, this); @@ -7320,17 +7408,17 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, { this.passwordField.on('specialkey', this.onSpecialKey, this); }, - logout: function() { + logout: function () { deluge.events.fire('logout'); deluge.client.auth.delete_session({ - success: function(result) { + success: function (result) { this.show(true); }, scope: this, }); }, - show: function(skipCheck) { + show: function (skipCheck) { if (this.firstShow) { deluge.client.on('error', this.onClientError, this); this.firstShow = false; @@ -7341,28 +7429,28 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, { } deluge.client.auth.check_session({ - success: function(result) { + success: function (result) { if (result) { deluge.events.fire('login'); } else { this.show(true); } }, - failure: function(result) { + failure: function (result) { this.show(true); }, scope: this, }); }, - onSpecialKey: function(field, e) { + onSpecialKey: function (field, e) { if (e.getKey() == 13) this.onLogin(); }, - onLogin: function() { + onLogin: function () { var passwordField = this.passwordField; deluge.client.auth.login(passwordField.getValue(), { - success: function(result) { + success: function (result) { if (result) { deluge.events.fire('login'); this.hide(); @@ -7373,7 +7461,7 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, { msg: _('You entered an incorrect password'), buttons: Ext.MessageBox.OK, modal: false, - fn: function() { + fn: function () { passwordField.focus(true, 10); }, icon: Ext.MessageBox.WARNING, @@ -7385,14 +7473,14 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, { }); }, - onClientError: function(errorObj, response, requestOptions) { + onClientError: function (errorObj, response, requestOptions) { if (errorObj.error.code == 1) { deluge.events.fire('logout'); this.show(true); } }, - onShow: function() { + onShow: function () { this.passwordField.focus(true, 300); }, }); @@ -7407,7 +7495,7 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, { */ deluge.menus = { - onTorrentActionSetOpt: function(item, e) { + onTorrentActionSetOpt: function (item, e) { var ids = deluge.torrents.getSelectedIds(); var action = item.initialConfig.torrentAction; var opts = {}; @@ -7415,20 +7503,23 @@ deluge.menus = { deluge.client.core.set_torrent_options(ids, opts); }, - onTorrentActionMethod: function(item, e) { + onTorrentActionMethod: function (item, e) { var ids = deluge.torrents.getSelectedIds(); var action = item.initialConfig.torrentAction; deluge.client.core[action](ids, { - success: function() { + success: function () { deluge.ui.update(); }, }); }, - onTorrentActionShow: function(item, e) { + onTorrentActionShow: function (item, e) { var ids = deluge.torrents.getSelectedIds(); var action = item.initialConfig.torrentAction; switch (action) { + case 'copy_magnet': + deluge.copyMagnetWindow.show(); + break; case 'edit_trackers': deluge.editTrackers.show(); break; @@ -7710,6 +7801,13 @@ deluge.menus.torrent = new Ext.menu.Menu({ }, '-', { + torrentAction: 'copy_magnet', + text: _('Copy Magnet URI'), + iconCls: 'icon-magnet-copy', + handler: deluge.menus.onTorrentActionShow, + scope: deluge.menus, + }, + { torrentAction: 'force_reannounce', text: _('Update Tracker'), iconCls: 'icon-update-tracker', @@ -7796,7 +7894,7 @@ deluge.menus.filePriorities = new Ext.menu.Menu({ Ext.namespace('Deluge'); Deluge.MoveStorage = Ext.extend(Ext.Window, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { title: _('Move Download Folder'), @@ -7816,7 +7914,7 @@ Deluge.MoveStorage = Ext.extend(Ext.Window, { Deluge.MoveStorage.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.MoveStorage.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancel, this); @@ -7848,21 +7946,21 @@ Deluge.MoveStorage = Ext.extend(Ext.Window, { //}); }, - hide: function() { + hide: function () { Deluge.MoveStorage.superclass.hide.call(this); this.torrentIds = null; }, - show: function(torrentIds) { + show: function (torrentIds) { Deluge.MoveStorage.superclass.show.call(this); this.torrentIds = torrentIds; }, - onCancel: function() { + onCancel: function () { this.hide(); }, - onMove: function() { + onMove: function () { var dest = this.moveLocation.getValue(); deluge.client.core.move_storage(this.torrentIds, dest); this.hide(); @@ -7886,7 +7984,7 @@ deluge.moveStorage = new Deluge.MoveStorage(); * @extends Deluge.OptionsManager */ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { - constructor: function(config) { + constructor: function (config) { this.currentId = null; this.stored = {}; Deluge.MultiOptionsManager.superclass.constructor.call(this, config); @@ -7896,7 +7994,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * Changes bound fields to use the specified id. * @param {String} id */ - changeId: function(id, dontUpdateBinds) { + changeId: function (id, dontUpdateBinds) { var oldId = this.currentId; this.currentId = id; if (!dontUpdateBinds) { @@ -7904,7 +8002,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { if (!this.binds[option]) continue; Ext.each( this.binds[option], - function(bind) { + function (bind) { bind.setValue(this.get(option)); }, this @@ -7918,7 +8016,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * Changes all the changed values to be the default values * @param {String} id */ - commit: function() { + commit: function () { this.stored[this.currentId] = Ext.apply( this.stored[this.currentId], this.changed[this.currentId] @@ -7931,7 +8029,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String/Array} option A single option or an array of options to return. * @returns {Object} the options value. */ - get: function() { + get: function () { if (arguments.length == 1) { var option = arguments[0]; return this.isDirty(option) @@ -7949,7 +8047,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { var options = {}; Ext.each( arguments, - function(option) { + function (option) { options[option] = this.isDirty(option) ? this.changed[this.currentId][option] : this.getDefault(option); @@ -7965,7 +8063,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String} option A single option. * @returns {Object} the value of the option */ - getDefault: function(option) { + getDefault: function (option) { return this.has(option) ? this.stored[this.currentId][option] : this.options[option]; @@ -7975,7 +8073,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * Returns the dirty (changed) values. * @returns {Object} the changed options */ - getDirty: function() { + getDirty: function () { return this.changed[this.currentId] ? this.changed[this.currentId] : {}; }, @@ -7984,7 +8082,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String} option * @returns {Boolean} true if the option has been changed, else false. */ - isDirty: function(option) { + isDirty: function (option) { return ( this.changed[this.currentId] && !Ext.isEmpty(this.changed[this.currentId][option]) @@ -7997,7 +8095,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String} option * @returns {Boolean} true if the id has an option, else false. */ - has: function(option) { + has: function (option) { return ( this.stored[this.currentId] && !Ext.isEmpty(this.stored[this.currentId][option]) @@ -8007,7 +8105,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { /** * Reset the options back to the default values for the specified id. */ - reset: function() { + reset: function () { if (this.changed[this.currentId]) delete this.changed[this.currentId]; if (this.stored[this.currentId]) delete this.stored[this.currentId]; }, @@ -8015,7 +8113,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { /** * Reset the options back to their defaults for all ids. */ - resetAll: function() { + resetAll: function () { this.changed = {}; this.stored = {}; this.changeId(null); @@ -8027,7 +8125,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String} option * @param {Object} value The value for the option */ - setDefault: function(option, value) { + setDefault: function (option, value) { if (option === undefined) { return; } else if (value === undefined) { @@ -8058,7 +8156,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String/Object} option or options to update * @param {Object} [value]; */ - update: function(option, value) { + update: function (option, value) { if (option === undefined) { return; } else if (value === undefined) { @@ -8109,7 +8207,7 @@ Deluge.OtherLimitWindow = Ext.extend(Ext.Window, { constrainHeader: true, closeAction: 'hide', - initComponent: function() { + initComponent: function () { Deluge.OtherLimitWindow.superclass.initComponent.call(this); this.form = this.add({ xtype: 'form', @@ -8142,31 +8240,28 @@ Deluge.OtherLimitWindow = Ext.extend(Ext.Window, { this.afterMethod('show', this.doFocusField, this); }, - setValue: function(value) { + setValue: function (value) { this.form.getForm().setValues({ limit: value }); }, - onCancelClick: function() { + onCancelClick: function () { this.form.getForm().reset(); this.hide(); }, - onOkClick: function() { + onOkClick: function () { var config = {}; config[this.group] = this.form.getForm().getValues().limit; deluge.client.core.set_config(config, { - success: function() { + success: function () { deluge.ui.update(); }, }); this.hide(); }, - doFocusField: function() { - this.form - .getForm() - .findField('limit') - .focus(true, 10); + doFocusField: function () { + this.form.getForm().findField('limit').focus(true, 10); }, }); /** @@ -8192,7 +8287,7 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, { */ name: null, - constructor: function(config) { + constructor: function (config) { this.isDelugePlugin = true; this.addEvents({ /** @@ -8214,7 +8309,7 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, { * Disables the plugin, firing the "{@link #disabled}" event and * then executing the plugins clean up method onDisabled. */ - disable: function() { + disable: function () { this.fireEvent('disabled', this); if (this.onDisable) this.onDisable(); }, @@ -8223,13 +8318,13 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, { * Enables the plugin, firing the "{@link #enabled}" event and * then executes the plugins setup method, onEnabled. */ - enable: function() { + enable: function () { deluge.client.reloadMethods(); this.fireEvent('enable', this); if (this.onEnable) this.onEnable(); }, - registerTorrentStatus: function(key, header, options) { + registerTorrentStatus: function (key, header, options) { options = options || {}; var cc = options.colCfg || {}, sc = options.storeCfg || {}; @@ -8250,23 +8345,23 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, { deluge.torrents.getView().refresh(true); }, - deregisterTorrentStatus: function(key) { + deregisterTorrentStatus: function (key) { var fields = []; - Ext.each(deluge.torrents.meta.fields, function(field) { + Ext.each(deluge.torrents.meta.fields, function (field) { if (field.name != key) fields.push(field); }); deluge.torrents.meta.fields = fields; deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta); var cols = []; - Ext.each(deluge.torrents.columns, function(col) { + Ext.each(deluge.torrents.columns, function (col) { if (col.dataIndex != key) cols.push(col); }); deluge.torrents.colModel.setConfig(cols); deluge.torrents.columns = cols; var keys = []; - Ext.each(Deluge.Keys.Grid, function(k) { + Ext.each(Deluge.Keys.Grid, function (k) { if (k == key) keys.push(k); }); Deluge.Keys.Grid = keys; @@ -8304,16 +8399,16 @@ Deluge.RemoveWindow = Ext.extend(Ext.Window, { bodyStyle: 'padding: 5px; padding-left: 10px;', html: 'Are you sure you wish to remove the torrent (s)?', - initComponent: function() { + initComponent: function () { Deluge.RemoveWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancel, this); this.addButton(_('Remove With Data'), this.onRemoveData, this); this.addButton(_('Remove Torrent'), this.onRemove, this); }, - remove: function(removeData) { + remove: function (removeData) { deluge.client.core.remove_torrents(this.torrentIds, removeData, { - success: function(result) { + success: function (result) { if (result == true) { console.log( 'Error(s) occured when trying to delete torrent(s).' @@ -8326,25 +8421,25 @@ Deluge.RemoveWindow = Ext.extend(Ext.Window, { }); }, - show: function(ids) { + show: function (ids) { Deluge.RemoveWindow.superclass.show.call(this); this.torrentIds = ids; }, - onCancel: function() { + onCancel: function () { this.hide(); this.torrentIds = null; }, - onRemove: function() { + onRemove: function () { this.remove(false); }, - onRemoveData: function() { + onRemoveData: function () { this.remove(true); }, - onRemoved: function(torrentIds) { + onRemoved: function (torrentIds) { deluge.events.fire('torrentsRemoved', torrentIds); this.hide(); deluge.ui.update(); @@ -8378,7 +8473,7 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { // private selected: null, - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { id: 'sidebar', @@ -8397,16 +8492,16 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { }, // private - initComponent: function() { + initComponent: function () { Deluge.Sidebar.superclass.initComponent.call(this); deluge.events.on('disconnect', this.onDisconnect, this); }, - createFilter: function(filter, states) { + createFilter: function (filter, states) { var panel = new Deluge.FilterPanel({ filter: filter, }); - panel.on('selectionchange', function(view, nodes) { + panel.on('selectionchange', function (view, nodes) { deluge.ui.update(); }); this.add(panel); @@ -8414,7 +8509,7 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { this.doLayout(); this.panels[filter] = panel; - panel.header.on('click', function(header) { + panel.header.on('click', function (header) { if (!deluge.config.sidebar_multiple_filters) { deluge.ui.update(); } @@ -8428,16 +8523,16 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { this.fireEvent('afterfiltercreate', this, panel); }, - getFilter: function(filter) { + getFilter: function (filter) { return this.panels[filter]; }, - getFilterStates: function() { + getFilterStates: function () { var states = {}; if (deluge.config.sidebar_multiple_filters) { // Grab the filters from each of the filter panels - this.items.each(function(panel) { + this.items.each(function (panel) { var state = panel.getState(); if (state == null) return; states[panel.filterType] = state; @@ -8454,12 +8549,12 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { return states; }, - hasFilter: function(filter) { + hasFilter: function (filter) { return this.panels[filter] ? true : false; }, // private - onDisconnect: function() { + onDisconnect: function () { for (var filter in this.panels) { this.remove(this.panels[filter]); } @@ -8467,11 +8562,11 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { this.selected = null; }, - onFilterSelect: function(selModel, rowIndex, record) { + onFilterSelect: function (selModel, rowIndex, record) { deluge.ui.update(); }, - update: function(filters) { + update: function (filters) { for (var filter in filters) { var states = filters[filter]; if (Ext.getKeys(this.panels).indexOf(filter) > -1) { @@ -8484,7 +8579,7 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { // Perform a cleanup of fitlers that are not enabled any more. Ext.each( Ext.keys(this.panels), - function(filter) { + function (filter) { if (Ext.keys(filters).indexOf(filter) == -1) { // We need to remove the panel this.remove(this.panels[filter]); @@ -8508,7 +8603,7 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { Ext.namespace('Deluge'); Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { id: 'deluge-statusbar', @@ -8520,14 +8615,14 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { Deluge.Statusbar.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.Statusbar.superclass.initComponent.call(this); deluge.events.on('connect', this.onConnect, this); deluge.events.on('disconnect', this.onDisconnect, this); }, - createButtons: function() { + createButtons: function () { this.buttons = this.add( { id: 'statusbar-connections', @@ -8711,7 +8806,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { cls: 'x-btn-text-icon', iconCls: 'x-deluge-traffic', tooltip: _('Protocol Traffic Download/Upload'), - handler: function() { + handler: function () { deluge.preferences.show(); deluge.preferences.selectPage('Network'); }, @@ -8738,7 +8833,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { cls: 'x-btn-text-icon', iconCls: 'x-deluge-freespace', tooltip: _('Freespace in download folder'), - handler: function() { + handler: function () { deluge.preferences.show(); deluge.preferences.selectPage('Downloads'); }, @@ -8747,7 +8842,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { this.created = true; }, - onConnect: function() { + onConnect: function () { this.setStatus({ iconCls: 'x-connected', text: '', @@ -8755,7 +8850,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { if (!this.created) { this.createButtons(); } else { - Ext.each(this.buttons, function(item) { + Ext.each(this.buttons, function (item) { item.show(); item.enable(); }); @@ -8763,23 +8858,23 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { this.doLayout(); }, - onDisconnect: function() { + onDisconnect: function () { this.clearStatus({ useDefaults: true }); - Ext.each(this.buttons, function(item) { + Ext.each(this.buttons, function (item) { item.hide(); item.disable(); }); this.doLayout(); }, - update: function(stats) { + update: function (stats) { if (!stats) return; function addSpeed(val) { return val + ' KiB/s'; } - var updateStat = function(name, config) { + var updateStat = function (name, config) { var item = this.items.get('statusbar-' + name); if (config.limit.value > 0) { var value = config.value.formatter @@ -8874,7 +8969,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { * @extends Ext.Toolbar */ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { items: [ @@ -8978,62 +9073,62 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { connectedButtons: ['add', 'remove', 'pause', 'resume', 'up', 'down'], - initComponent: function() { + initComponent: function () { Deluge.Toolbar.superclass.initComponent.call(this); deluge.events.on('connect', this.onConnect, this); deluge.events.on('login', this.onLogin, this); }, - onConnect: function() { + onConnect: function () { Ext.each( this.connectedButtons, - function(buttonId) { + function (buttonId) { this.items.get(buttonId).enable(); }, this ); }, - onDisconnect: function() { + onDisconnect: function () { Ext.each( this.connectedButtons, - function(buttonId) { + function (buttonId) { this.items.get(buttonId).disable(); }, this ); }, - onLogin: function() { + onLogin: function () { this.items.get('logout').enable(); }, - onLogout: function() { + onLogout: function () { this.items.get('logout').disable(); deluge.login.logout(); }, - onConnectionManagerClick: function() { + onConnectionManagerClick: function () { deluge.connectionManager.show(); }, - onHelpClick: function() { + onHelpClick: function () { window.open('http://dev.deluge-torrent.org/wiki/UserGuide'); }, - onAboutClick: function() { + onAboutClick: function () { var about = new Deluge.about.AboutWindow(); about.show(); }, - onPreferencesClick: function() { + onPreferencesClick: function () { deluge.preferences.show(); }, - onTorrentAction: function(item) { + onTorrentAction: function (item) { var selection = deluge.torrents.getSelections(); var ids = []; - Ext.each(selection, function(record) { + Ext.each(selection, function (record) { ids.push(record.id); }); @@ -9044,7 +9139,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { case 'pause': case 'resume': deluge.client.core[item.id + '_torrent'](ids, { - success: function() { + success: function () { deluge.ui.update(); }, }); @@ -9052,7 +9147,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { case 'up': case 'down': deluge.client.core['queue_' + item.id](ids, { - success: function() { + success: function () { deluge.ui.update(); }, }); @@ -9060,7 +9155,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { } }, - onTorrentAdd: function() { + onTorrentAdd: function () { deluge.add.show(); }, }); @@ -9074,7 +9169,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { * See LICENSE for more details. */ -(function() { +(function () { /* Renderers for the Torrent Grid */ function queueRenderer(value) { return value == -1 ? '' : value + 1; @@ -9083,7 +9178,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { return String.format( '<div class="torrent-name x-deluge-{0}">{1}</div>', r.data['state'].toLowerCase(), - value + Ext.util.Format.htmlEncode(value) ); } function torrentSpeedRenderer(value) { @@ -9128,12 +9223,14 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { '<div style="background: url(' + deluge.config.base + 'tracker/{0}) no-repeat; padding-left: 20px;">{0}</div>', - value + Ext.util.Format.htmlEncode(value) ); } function etaSorter(eta) { - return eta * -1; + if (eta === 0) return Number.MAX_VALUE; + if (eta <= -1) return Number.MAX_SAFE_INTEGER; + return eta; } function dateOrNever(date) { @@ -9141,7 +9238,9 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { } function timeOrInf(time) { - return time < 0 ? '∞' : ftime(time); + if (time === 0) return ''; + if (time <= -1) return '∞'; + return ftime(time); } /** @@ -9386,6 +9485,8 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { { name: 'ratio', type: 'float' }, { name: 'distributed_copies', type: 'float' }, { name: 'time_added', type: 'int' }, + { name: 'last_seen_complete', type: 'int' }, + { name: 'completed_time', type: 'int' }, { name: 'tracker_host' }, { name: 'download_location' }, { name: 'total_done', type: 'int' }, @@ -9403,21 +9504,21 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { key: 'a', ctrl: true, stopEvent: true, - handler: function() { + handler: function () { deluge.torrents.getSelectionModel().selectAll(); }, }, { key: [46], stopEvent: true, - handler: function() { + handler: function () { ids = deluge.torrents.getSelectedIds(); deluge.removeWindow.show(ids); }, }, ], - constructor: function(config) { + constructor: function (config) { config = Ext.apply( { id: 'torrentGrid', @@ -9442,12 +9543,12 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { Deluge.TorrentGrid.superclass.constructor.call(this, config); }, - initComponent: function() { + initComponent: function () { Deluge.TorrentGrid.superclass.initComponent.call(this); deluge.events.on('torrentsRemoved', this.onTorrentsRemoved, this); deluge.events.on('disconnect', this.onDisconnect, this); - this.on('rowcontextmenu', function(grid, rowIndex, e) { + this.on('rowcontextmenu', function (grid, rowIndex, e) { e.stopEvent(); var selection = grid.getSelectionModel(); if (!selection.isSelected(rowIndex)) { @@ -9463,7 +9564,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { * @param index {int} The row index of the torrent you wish to retrieve. * @return {Ext.data.Record} The record representing the torrent. */ - getTorrent: function(index) { + getTorrent: function (index) { return this.getStore().getAt(index); }, @@ -9471,14 +9572,14 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { * Returns the currently selected record. * @ return {Array/Ext.data.Record} The record(s) representing the rows */ - getSelected: function() { + getSelected: function () { return this.getSelectionModel().getSelected(); }, /** * Returns the currently selected records. */ - getSelections: function() { + getSelections: function () { return this.getSelectionModel().getSelections(); }, @@ -9486,7 +9587,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { * Return the currently selected torrent id. * @return {String} The currently selected id. */ - getSelectedId: function() { + getSelectedId: function () { return this.getSelectionModel().getSelected().id; }, @@ -9494,15 +9595,15 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { * Return the currently selected torrent ids. * @return {Array} The currently selected ids. */ - getSelectedIds: function() { + getSelectedIds: function () { var ids = []; - Ext.each(this.getSelectionModel().getSelections(), function(r) { + Ext.each(this.getSelectionModel().getSelections(), function (r) { ids.push(r.id); }); return ids; }, - update: function(torrents, wipe) { + update: function (torrents, wipe) { var store = this.getStore(); // Need to perform a complete reload of the torrent grid. @@ -9536,7 +9637,7 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { store.add(newTorrents); // Remove any torrents that should not be in the store. - store.each(function(record) { + store.each(function (record) { if (!torrents[record.id]) { store.remove(record); delete this.torrents[record.id]; @@ -9550,17 +9651,17 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { }, // private - onDisconnect: function() { + onDisconnect: function () { this.getStore().removeAll(); this.torrents = {}; }, // private - onTorrentsRemoved: function(torrentIds) { + onTorrentsRemoved: function (torrentIds) { var selModel = this.getSelectionModel(); Ext.each( torrentIds, - function(torrentId) { + function (torrentId) { var record = this.getStore().getById(torrentId); if (selModel.isSelected(record)) { selModel.deselectRow(this.getStore().indexOf(record)); @@ -9618,7 +9719,7 @@ deluge.ui = { * @description Create all the interface components, the json-rpc client * and set up various events that the UI will utilise. */ - initialize: function() { + initialize: function () { deluge.add = new Deluge.add.AddWindow(); deluge.details = new Deluge.details.DetailsPanel(); deluge.connectionManager = new Deluge.ConnectionManager(); @@ -9676,7 +9777,7 @@ deluge.ui = { deluge.client.on( 'connected', - function(e) { + function (e) { deluge.login.show(); }, this, @@ -9689,7 +9790,7 @@ deluge.ui = { this.originalTitle = document.title; }, - checkConnection: function() { + checkConnection: function () { deluge.client.web.connected({ success: this.onConnectionSuccess, failure: this.onConnectionError, @@ -9697,7 +9798,7 @@ deluge.ui = { }); }, - update: function() { + update: function () { var filters = deluge.sidebar.getFilterStates(); this.oldFilters = this.filters; this.filters = filters; @@ -9710,9 +9811,9 @@ deluge.ui = { deluge.details.update(); }, - onConnectionError: function(error) {}, + onConnectionError: function (error) {}, - onConnectionSuccess: function(result) { + onConnectionSuccess: function (result) { deluge.statusbar.setStatus({ iconCls: 'x-deluge-statusbar icon-ok', text: _('Connection restored'), @@ -9723,7 +9824,7 @@ deluge.ui = { } }, - onUpdateError: function(error) { + onUpdateError: function (error) { if (this.errorCount == 2) { Ext.MessageBox.show({ title: _('Lost Connection'), @@ -9745,7 +9846,7 @@ deluge.ui = { * @private * Updates the various components in the interface. */ - onUpdate: function(data) { + onUpdate: function (data) { if (!data['connected']) { deluge.connectionManager.disconnect(true); return; @@ -9775,7 +9876,7 @@ deluge.ui = { * @private * Start the Deluge UI polling the server and update the interface. */ - onConnect: function() { + onConnect: function () { if (!this.running) { this.running = setInterval(this.update, 2000); this.update(); @@ -9790,14 +9891,14 @@ deluge.ui = { * @static * @private */ - onDisconnect: function() { + onDisconnect: function () { this.stop(); }, - onGotPlugins: function(plugins) { + onGotPlugins: function (plugins) { Ext.each( plugins.enabled_plugins, - function(plugin) { + function (plugin) { if (deluge.plugins[plugin]) return; deluge.client.web.get_plugin_resources(plugin, { success: this.onGotPluginResources, @@ -9808,7 +9909,7 @@ deluge.ui = { ); }, - onPluginEnabled: function(pluginName) { + onPluginEnabled: function (pluginName) { if (deluge.plugins[pluginName]) { deluge.plugins[pluginName].enable(); } else { @@ -9819,13 +9920,13 @@ deluge.ui = { } }, - onGotPluginResources: function(resources) { + onGotPluginResources: function (resources) { var scripts = Deluge.debug ? resources.debug_scripts : resources.scripts; Ext.each( scripts, - function(script) { + function (script) { Ext.ux.JSLoader({ url: deluge.config.base + script, onLoad: this.onPluginLoaded, @@ -9836,11 +9937,11 @@ deluge.ui = { ); }, - onPluginDisabled: function(pluginName) { + onPluginDisabled: function (pluginName) { if (deluge.plugins[pluginName]) deluge.plugins[pluginName].disable(); }, - onPluginLoaded: function(options) { + onPluginLoaded: function (options) { // This could happen if the plugin has multiple scripts if (!Deluge.hasPlugin(options.pluginName)) return; @@ -9854,7 +9955,7 @@ deluge.ui = { * @static * Stop the Deluge UI polling the server and clear the interface. */ - stop: function() { + stop: function () { if (this.running) { clearInterval(this.running); this.running = false; @@ -9863,6 +9964,6 @@ deluge.ui = { }, }; -Ext.onReady(function(e) { +Ext.onReady(function (e) { deluge.ui.initialize(); }); |