summaryrefslogtreecommitdiffstats
path: root/deluge/ui/webui/templates/ajax/static/js/deluge-add.js
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/webui/templates/ajax/static/js/deluge-add.js')
-rw-r--r--deluge/ui/webui/templates/ajax/static/js/deluge-add.js151
1 files changed, 82 insertions, 69 deletions
diff --git a/deluge/ui/webui/templates/ajax/static/js/deluge-add.js b/deluge/ui/webui/templates/ajax/static/js/deluge-add.js
index 889514b44..ee789187a 100644
--- a/deluge/ui/webui/templates/ajax/static/js/deluge-add.js
+++ b/deluge/ui/webui/templates/ajax/static/js/deluge-add.js
@@ -1,12 +1,25 @@
/*
Script: deluge-add.js
Contains the add torrent window and the torrent creator window.
-
-License:
- General Public License v3
-
-Copyright:
- Damien Churchill (c) 2008 <damoxc@gmail.com>
+ *
+ * Copyright (C) Damien Churchill 2008 <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.
+ *
*/
Deluge.Widgets.AddWindow = new Class({
@@ -17,7 +30,7 @@ Deluge.Widgets.AddWindow = new Class({
title: _('Add Torrents'),
url: '/template/render/html/window_add_torrent.html'
},
-
+
initialize: function() {
this.parent();
this.bound = {
@@ -32,7 +45,7 @@ Deluge.Widgets.AddWindow = new Class({
this.addEvent('loaded', this.bound.onLoad);
this.addEvent('show', this.bound.onShow);
},
-
+
onLoad: function(e) {
this.content.id = 'addTorrent';
this.torrents = this.content.getElement('select');
@@ -43,28 +56,28 @@ Deluge.Widgets.AddWindow = new Class({
this.optionsTab = new Deluge.Widgets.AddTorrent.OptionsTab();
this.tabs.addPage(this.filesTab);
this.tabs.addPage(this.optionsTab);
-
+
this.fileWindow = new Deluge.Widgets.AddTorrent.File();
this.fileWindow.addEvent('torrentAdded', this.bound.onTorrentAdded);
this.fileButton = this.content.getElement('button.file');
this.fileButton.addEvent('click', function(e) {
this.fileWindow.show();
}.bindWithEvent(this));
-
+
this.urlWindow = new Deluge.Widgets.AddTorrent.Url();
- this.urlWindow.addEvent('torrentAdded', this.bound.onTorrentAdded);
+ this.urlWindow.addEvent('torrentAdded', this.bound.onTorrentAdded);
this.urlButton = this.content.getElement('button.url');
this.urlButton.addEvent('click', function(e) {
this.urlWindow.show();
}.bindWithEvent(this));
-
+
this.removeButton = this.content.getElement('button.remove');
this.removeButton.addEvent('click', this.bound.onRemoveClick);
-
+
this.content.getElement('button.add').addEvent('click', this.bound.onAdd);
this.content.getElement('button.cancel').addEvent('click', this.bound.onCancel);
},
-
+
onTorrentAdded: function(torrentInfo) {
var option = new Element('option');
option.set('value', torrentInfo['info_hash']);
@@ -74,11 +87,11 @@ Deluge.Widgets.AddWindow = new Class({
this.torrents.grab(option);
this.torrentInfo[torrentInfo['info_hash']] = torrentInfo;
},
-
+
onTorrentChanged: function(e) {
this.filesTab.setTorrent(this.torrentInfo[this.torrents.value]);
},
-
+
onAdd: function(e) {
torrents = new Array();
$each(this.torrentInfo, function(torrent) {
@@ -90,18 +103,18 @@ Deluge.Widgets.AddWindow = new Class({
Deluge.Client.add_torrents(torrents);
this.onCancel()
},
-
+
onShow: function(e) {
this.optionsTab.getDefaults();
},
-
+
onCancel: function(e) {
this.hide();
this.torrents.empty();
this.torrentInfo.empty();
this.filesTab.table.empty();
},
-
+
onRemoveClick: function(e) {
delete this.torrentInfo[this.torrents.value];
this.torrents.options[this.torrents.selectedIndex].dispose();
@@ -113,13 +126,13 @@ Deluge.Widgets.AddTorrent = {}
Deluge.Widgets.AddTorrent.File = new Class({
Extends: Widgets.Window,
-
+
options: {
width: 400,
height: 100,
title: _('From File')
},
-
+
initialize: function() {
this.parent();
this.bound = {
@@ -147,35 +160,35 @@ Deluge.Widgets.AddTorrent.File = new Class({
this.content.grab(this.iframe);
this.iframe.addEvent('load', this.bound.onLoad);
},
-
+
onLoad: function(e) {
var body = $(this.iframe.contentDocument.body);
var form = body.getElement('form');
var cancelButton = form.getElement('button.cancel');
cancelButton.addEvent('click', this.bound.onCancel);
-
+
var fileInputs = form.getElement('div.fileInputs');
var fileInput = fileInputs.getElement('input');
fileInput.set('opacity', 0.000001);
var fakeFile = fileInputs.getElement('div').getElement('input');
-
+
fileInput.addEvent('change', function(e) {
fakeFile.value = fileInput.value;
});
-
+
form.addEvent('submit', this.bound.onSubmit);
this.iframe.removeEvent('load', this.bound.onLoad);
},
-
+
onCancel: function(e) {
this.hide();
},
-
+
onSubmit: function(e) {
this.iframe.addEvent('load', this.bound.onComplete);
this.iframe.set('opacity', 0);
},
-
+
onComplete: function(e) {
filename = $(this.iframe.contentDocument.body).get('text');
this.hide();
@@ -183,7 +196,7 @@ Deluge.Widgets.AddTorrent.File = new Class({
onSuccess: this.bound.onGetInfoSuccess
});
},
-
+
onGetInfoSuccess: function(info) {
if (info) this.fireEvent('torrentAdded', info);
}
@@ -191,13 +204,13 @@ Deluge.Widgets.AddTorrent.File = new Class({
Deluge.Widgets.AddTorrent.Url = new Class({
Extends: Widgets.Window,
-
+
options: {
width: 300,
height: 100,
title: _('From Url')
},
-
+
initialize: function() {
this.parent();
this.bound = {
@@ -206,7 +219,7 @@ Deluge.Widgets.AddTorrent.Url = new Class({
onDownloadSuccess: this.onDownloadSuccess.bindWithEvent(this),
onGetInfoSuccess: this.onGetInfoSuccess.bindWithEvent(this)
};
-
+
this.form = new Element('form');
this.urlInput = new Element('input', {
'type': 'text',
@@ -224,11 +237,11 @@ Deluge.Widgets.AddTorrent.Url = new Class({
this.form.grab(this.urlInput).grab(new Element('br'));
this.form.grab(this.okButton).grab(this.cancelButton);
this.content.grab(this.form);
-
+
this.okButton.addEvent('click', this.bound.onOkClick);
this.cancelButton.addEvent('click', this.bound.onCancelClick);
},
-
+
onOkClick: function(e) {
e.stop();
var url = this.urlInput.get('value');
@@ -237,19 +250,19 @@ Deluge.Widgets.AddTorrent.Url = new Class({
});
this.hide();
},
-
+
onCancelClick: function(e) {
e.stop();
this.urlInput.set('value', '');
this.hide();
},
-
+
onDownloadSuccess: function(filename) {
Deluge.Client.get_torrent_info(filename, {
onSuccess: this.bound.onGetInfoSuccess
});
},
-
+
onGetInfoSuccess: function(info) {
this.fireEvent('torrentAdded', info);
}
@@ -257,20 +270,20 @@ Deluge.Widgets.AddTorrent.Url = new Class({
Deluge.Widgets.AddTorrent.FilesTab = new Class({
Extends: Widgets.TabPage,
-
+
options: {
url: '/template/render/html/add_torrent_files.html'
},
-
+
initialize: function() {
this.addEvent('loaded', this.onLoad.bindWithEvent(this));
this.parent('Files');
},
-
+
onLoad: function(e) {
- this.table = this.element.getElement('table');
+ this.table = this.element.getElement('table');
},
-
+
setTorrent: function(torrent) {
this.table.empty();
if (!torrent) return;
@@ -292,19 +305,19 @@ Deluge.Widgets.AddTorrent.FilesTab = new Class({
Deluge.Widgets.AddTorrent.OptionsTab = new Class({
Extends: Widgets.TabPage,
-
+
options: {
url: '/template/render/html/add_torrent_options.html'
},
-
+
initialize: function() {
this.parent('Options');
this.addEvent('loaded', this.onLoad.bindWithEvent(this));
},
-
+
onLoad: function(e) {
this.form = this.element.getElement('form');
-
+
new Widgets.Spinner(this.form.max_download_speed_per_torrent, {
step: 10,
precision: 1,
@@ -313,7 +326,7 @@ Deluge.Widgets.AddTorrent.OptionsTab = new Class({
low: -1
}
});
-
+
new Widgets.Spinner(this.form.max_upload_speed_per_torrent, {
step: 10,
precision: 1,
@@ -322,7 +335,7 @@ Deluge.Widgets.AddTorrent.OptionsTab = new Class({
low: -1
}
});
-
+
new Widgets.Spinner(this.form.max_connections_per_torrent, {
step: 1,
precision: 0,
@@ -331,7 +344,7 @@ Deluge.Widgets.AddTorrent.OptionsTab = new Class({
low: -1
}
});
-
+
new Widgets.Spinner(this.form.max_upload_slots_per_torrent, {
step: 1,
precision: 0,
@@ -341,7 +354,7 @@ Deluge.Widgets.AddTorrent.OptionsTab = new Class({
}
});
},
-
+
getDefaults: function() {
var keys = [
'add_paused',
@@ -357,12 +370,12 @@ Deluge.Widgets.AddTorrent.OptionsTab = new Class({
onSuccess: this.onGetConfigSuccess.bindWithEvent(this)
});
},
-
+
onGetConfigSuccess: function(config) {
this.default_config = config;
this.setFormToDefault();
},
-
+
setFormToDefault: function() {
this.form.add_paused.checked = config['add_paused'];
$each(this.form.compact_allocation, function(el) {
@@ -378,22 +391,22 @@ Deluge.Widgets.AddTorrent.OptionsTab = new Class({
$$W(this.form.max_connections_per_torrent).setValue(config['max_connections_per_torrent']);
$$W(this.form.max_upload_slots_per_torrent).setValue(config['max_upload_slots_per_torrent']);
},
-
+
setTorrent: function(torrent) {
-
+
}
});
Deluge.Widgets.CreateTorrent = new Class({
Extends: Widgets.Window,
-
+
options: {
width: 400,
height: 400,
title: _('Create Torrent'),
url: '/template/render/html/window_create_torrent.html'
},
-
+
initialize: function() {
this.parent();
this.bound = {
@@ -403,21 +416,21 @@ Deluge.Widgets.CreateTorrent = new Class({
}
this.addEvent('loaded', this.bound.onLoad);
},
-
+
onLoad: function(e) {
this.tabs = new Deluge.Widgets.CreateTorrent.Tabs(this.content.getElement('.moouiTabs'));
this.fileButton = this.content.getElement('button.file');
this.folderButton = this.content.getElement('button.folder');
this.content.id = 'createTorrent';
-
+
this.fileButton.addEvent('click', this.bound.onFileClick);
},
-
+
onFileClick: function(e) {
var desktop = google.gears.factory.create('beta.desktop');
desktop.openFiles(this.onFilesPicked.bind(this));
},
-
+
onFilesPicked: function(files) {
for (var i = 0; i < files.length; i++) {
alert(files[i].blob);
@@ -427,7 +440,7 @@ Deluge.Widgets.CreateTorrent = new Class({
Deluge.Widgets.CreateTorrent.Tabs = new Class({
Extends: Widgets.Tabs,
-
+
initialize: function(element) {
this.parent(element);
this.info = new Deluge.Widgets.CreateTorrent.InfoTab();
@@ -443,11 +456,11 @@ Deluge.Widgets.CreateTorrent.Tabs = new Class({
Deluge.Widgets.CreateTorrent.InfoTab = new Class({
Extends: Widgets.TabPage,
-
+
options: {
url: '/template/render/html/create_torrent_info.html'
},
-
+
initialize: function() {
this.parent('Info');
}
@@ -455,11 +468,11 @@ Deluge.Widgets.CreateTorrent.InfoTab = new Class({
Deluge.Widgets.CreateTorrent.TrackersTab = new Class({
Extends: Widgets.TabPage,
-
+
options: {
url: '/template/render/html/create_torrent_trackers.html'
},
-
+
initialize: function() {
this.parent('Trackers');
}
@@ -467,11 +480,11 @@ Deluge.Widgets.CreateTorrent.TrackersTab = new Class({
Deluge.Widgets.CreateTorrent.WebseedsTab = new Class({
Extends: Widgets.TabPage,
-
+
options: {
url: '/template/render/html/create_torrent_webseeds.html'
},
-
+
initialize: function() {
this.parent('Webseeds');
}
@@ -479,11 +492,11 @@ Deluge.Widgets.CreateTorrent.WebseedsTab = new Class({
Deluge.Widgets.CreateTorrent.OptionsTab = new Class({
Extends: Widgets.TabPage,
-
+
options: {
url: '/template/render/html/create_torrent_options.html'
},
-
+
initialize: function() {
this.parent('Options');
}