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