Author: damoxc
Revision: 5193
Log:
add torrents to be added to the grid before their info has been
retrieved with a url or filename in place of the torrent name
Diff:
Modified: trunk/deluge/ui/web/js/Deluge.Add.File.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Add.File.js 2009-04-27 18:50:41 UTC (rev
5192)
+++ trunk/deluge/ui/web/js/Deluge.Add.File.js 2009-04-27 20:48:39 UTC (rev
5193)
@@ -65,16 +65,23 @@
onAdd: function(field, e) {
if (this.form.getForm().isValid()) {
+ this.torrentId = this.createTorrentId();
this.form.getForm().submit({
url: '/upload',
waitMsg: _('Uploading your torrent...'),
success: this.onUploadSuccess,
scope: this
});
+ var name =
this.form.getForm().findField('torrentFile').value;
+ this.fireEvent('beforeadd', this.torrentId, name);
}
- this.fireEvent('beforeadd', null);
},
+ onGotInfo: function(info, obj, response, request) {
+ info['filename'] = request.options.filename;
+ this.fireEvent('add', this.torrentId, info);
+ },
+
onUploadSuccess: function(fp, upload) {
this.hide();
var filename = upload.result.toString();
@@ -84,10 +91,5 @@
scope: this,
filename: filename
});
- },
-
- onGotInfo: function(info, obj, response, request) {
- info['filename'] = request.options.filename;
- this.fireEvent('add', info);
}
});
\ No newline at end of file
Modified: trunk/deluge/ui/web/js/Deluge.Add.Url.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Add.Url.js 2009-04-27 18:50:41 UTC (rev
5192)
+++ trunk/deluge/ui/web/js/Deluge.Add.Url.js 2009-04-27 20:48:39 UTC (rev
5193)
@@ -70,26 +70,29 @@
var field = this.form.items.get('url');
var url = field.getValue();
+ var torrentId = this.createTorrentId();
Deluge.Client.web.download_torrent_from_url(url, {
success: this.onDownload,
- scope: this
+ scope: this,
+ torrentId: torrentId
});
this.hide();
- this.fireEvent('beforeadd', url);
+ this.fireEvent('beforeadd', torrentId, url);
},
- onDownload: function(filename) {
+ onDownload: function(filename, obj, resp, req) {
this.form.items.get('url').setValue('');
Deluge.Client.web.get_torrent_info(filename, {
success: this.onGotInfo,
scope: this,
- filename: filename
+ filename: filename,
+ torrentId: req.options.torrentId
});
},
onGotInfo: function(info, obj, response, request) {
info['filename'] = request.options.filename;
- this.fireEvent('add', info);
+ this.fireEvent('add', request.options.torrentId, info);
}
});
\ No newline at end of file
Modified: trunk/deluge/ui/web/js/Deluge.Add.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Add.js 2009-04-27 18:50:41 UTC (rev
5192)
+++ trunk/deluge/ui/web/js/Deluge.Add.js 2009-04-27 20:48:39 UTC (rev
5193)
@@ -62,6 +62,30 @@
new Ext.tree.TreeSorter(this.files, {
folderSort: true
});
+
+ this.form = this.add({
+ xtype: 'form',
+ labelWidth: 1,
+ frame: false,
+ title: _('Options'),
+ bodyStyle: 'padding: 5px;',
+ border: false,
+
+
+ items: [{
+ xtype: 'fieldset',
+ title: _('Download Location'),
+ border: false,
+ defaultType: 'textfield',
+ labelWidth: 1,
+ items: [{
+ fieldLabel: '',
+ labelSeperator: '',
+ name: 'download_location',
+ width: 330
+ }]
+ }]
+ });
},
clear: function() {
@@ -89,13 +113,13 @@
'prioritize_first_last_pieces'
]
Deluge.Client.core.get_config_values(keys, {
- onSuccess: function(config) {
+ success: function(config) {
this.defaults = config;
- $each(config, function(value, key) {
+ for (var key in config) {
var field = this.form.findField(key);
if (!field) return;
- field.setValue(value);
- }, this);
+ field.setValue(config[key]);
+ }
var field =
this.form.findField('compact_allocation');
if (config['compact_allocation']) {
field.items.get('compact_allocation_true').setValue(true);
@@ -104,7 +128,8 @@
field.items.get('compact_allocation_false').setValue(true);
field.items.get('compact_allocation_true').setValue(false);
}
- }.bindWithEvent(this)
+ },
+ scope: this
});
}
});
@@ -116,6 +141,10 @@
'beforeadd',
'add'
);
+ },
+
+ createTorrentId: function() {
+ return new Date().getTime();
}
});
@@ -145,19 +174,30 @@
this.addButton(_('Cancel'), this.onCancel, this);
this.addButton(_('Add'), this.onAdd, this);
+ function torrentRenderer(value, p, r) {
+ if (r.data['infohash']) {
+ return String.format('<div
class="x-add-torrent-name">{0}</div>', value);
+ } else {
+ return String.format('<div
class="x-add-torrent-name-loading">{0}</div>', value);
+ }
+ }
+
this.grid = this.add({
xtype: 'grid',
region: 'center',
store: new Ext.data.SimpleStore({
- fields: [{name: 'torrent', mapping: 1}],
+ fields: [
+ {name: 'info_hash', mapping: 1},
+ {name: 'text', mapping: 2}
+ ],
id: 0
}),
columns: [{
id: 'torrent',
width: 150,
sortable: true,
- renderer: fplain,
- dataIndex: 'torrent'
+ renderer: torrentRenderer,
+ dataIndex: 'text'
}],
stripeRows: true,
selModel: new Ext.grid.RowSelectionModel({
@@ -249,11 +289,11 @@
delete this.torrents[torrent.id];
this.grid.getStore().remove(torrent);
- this.clearFiles();
+ this.options.clear();
},
onSelect: function(selModel, rowIndex, record) {
- var torrentInfo = this.torrents[record.id];
+ var torrentInfo = this.torrents[record.get('info_hash')];
function walk(files, parent) {
for (var file in files) {
@@ -299,10 +339,12 @@
}
},
- onTorrentBeforeAdd: function(temptext) {
+ onTorrentBeforeAdd: function(torrentId, text) {
+ var store = this.grid.getStore();
+ store.loadData([[torrentId, null, text]], true);
},
- onTorrentAdd: function(info) {
+ onTorrentAdd: function(torrentId, info) {
if (!info) {
Ext.MessageBox.show({
title: _('Error'),
@@ -314,7 +356,11 @@
});
return;
}
- this.grid.getStore().loadData([[info['info_hash'],
info['name']]], true);
+
+ var r = this.grid.getStore().getById(torrentId);
+ r.set('info_hash', info['info_hash']);
+ r.set('text', info['name']);
+ this.grid.getStore().commitChanges();
this.torrents[info['info_hash']] = info;
},
@@ -322,332 +368,4 @@
this.url.show();
}
});
-Deluge.Add = new Ext.deluge.add.AddWindow();
-
-/*Deluge.Add = {
- onFile: function() {
- this.File.Window.show();
- },
-
- onOptionsRender: function(panel) {
- panel.layout = new Ext.layout.FormLayout();
- panel.layout.setContainer(panel);
- panel.doLayout();
- this.form = panel.getForm();
- this.getDefaults();
- },
-
- onRender: function(window) {
- new Ext.tree.TreeSorter(this.Files, {
- folderSort: true
- });
- },
-
- onSelect: function(selModel, rowIndex, record) {
- var torrentInfo = Deluge.Add.torrents[record.id];
-
- function walk(files, parent) {
- $each(files, function(item, file) {
- if ($type(item) == 'object') {
- var child = new Ext.tree.TreeNode({
- text: file
- });
- walk(item, child);
- parent.appendChild(child);
- } else {
- parent.appendChild(new
Ext.tree.TreeNode({
- filename: file,
- text: file, // this needs to be
here for sorting reasons
- size: fsize(item[0]),
- leaf: true,
- checked: item[1],
- iconCls: 'x-deluge-file',
- uiProvider:
Ext.tree.ColumnNodeUI
- }));
- }
- });
- }
-
- this.clearFiles();
-
- var root = this.Files.getRootNode();
- walk(torrentInfo['files_tree'], root);
- root.firstChild.expand();
- },
-
- onTorrentAdded: function(info, filename) {
- if (!info) {
- Ext.MessageBox.show({
- title: _('Error'),
- msg: _('Not a valid torrent'),
- buttons: Ext.MessageBox.OK,
- modal: false,
- icon: Ext.MessageBox.ERROR,
- iconCls: 'x-deluge-icon-error'
- });
- return;
- }
- info['filename'] = filename;
- this.Store.loadData([[info['info_hash'], info['name']]], true);
- this.torrents[info['info_hash']] = info;
- },
-
- onUrl: function(button, event) {
- this.Url.Window.show();
- },
-
- onRemove: function() {
- var selection = this.Grid.getSelectionModel();
- if (!selection.hasSelection()) return;
- var torrent = selection.getSelected();
-
- delete this.torrents[torrent.id];
- this.Store.remove(torrent);
- this.clearFiles();
- }
-}
-
-Deluge.Add.Options = new Ext.TabPanel({
- region: 'south',
- margins: '5 5 5 5',
- activeTab: 0,
- height: 220,
- items: [{
- id: 'addFilesTab',
- title: _('Files'),
- items: [Deluge.Add.Files]
- },{
- id: 'addOptionsTab',
- title: _('Options'),
- layout: 'fit',
- items: [new Ext.form.FormPanel({
- id: 'addOptionsForm',
- bodyStyle: 'padding: 5px;',
- border: false,
- items: [{
- xtype: 'fieldset',
- style: 'padding: 0px; padding-top: 5px;',
- title: _('Download Location'),
- border: false,
- autoHeight: true,
- border: false,
- labelWidth: 1,
- items: [{
- layout: 'column',
- border: false,
- items: [{
- xtype: 'textfield',
- id: 'download_location',
- fieldLabel: '',
- labelSeparator: '',
- width: 330
- }, {
- border: false,
- style: 'padding-left: 5px;',
- items: [{
- xtype: 'button',
- text: _('Browse') +
'...',
- disabled: true
- }]
- }]
- }]
- }, {
- layout: 'column',
- border: false,
- defaults: {
- border: false
- },
- items: [{
- xtype: 'fieldset',
- bodyStyle: 'margin-left: 5px;
margin-right:5px;',
- title: _('Allocation'),
- autoHeight: true,
- border: false,
- labelWidth: 1,
- width: 100,
- items: [new Ext.form.RadioGroup({
- id: 'compact_allocation',
- name: 'compact_allocation',
- columns: 1,
- labelSeparator: '',
- items: [{
- boxLabel: _('Full'),
- inputValue: 'false',
- id:
'compact_allocation_false',
- name:
'compact_allocation',
- checked: true
- },{
- boxLabel: _('Compact'),
- inputValue: 'true',
- id:
'compact_allocation_true',
- name:
'compact_allocation'
- }]
- })]
- }, {
- xtype: 'fieldset',
- title: _('Bandwidth'),
- layout: 'form',
- autoHeight: true,
- defaultType: 'uxspinner',
- labelWidth: 100,
- items: [{
- id:
'max_download_speed_per_torrent',
- fieldLabel: _('Max Down Speed'),
- width: 60,
- value: -1,
- strategy: new
Ext.ux.form.Spinner.NumberStrategy({
- minValue: -1,
- maxValue: 99999,
- incrementValue: 1
- })
- }, {
- id:
'max_upload_speed_per_torrent',
- fieldLabel: _('Max Up Speed'),
- width: 60,
- value: -1,
- strategy: new
Ext.ux.form.Spinner.NumberStrategy({
- minValue: -1,
- maxValue: 99999,
- incrementValue: 1
- })
- }, {
- id:
'max_connections_per_torrent',
- fieldLabel: _('Max
Connections'),
- width: 60,
- value: -1,
- strategy: new
Ext.ux.form.Spinner.NumberStrategy({
- minValue: -1,
- maxValue: 99999,
- incrementValue: 1
- })
- }, {
- id:
'max_upload_slots_per_torrent',
- fieldLabel: _('Max Upload
Slots'),
- colspan: 2,
- width: 60,
- value: -1,
- strategy: new
Ext.ux.form.Spinner.NumberStrategy({
- minValue: -1,
- maxValue: 99999,
- incrementValue: 1
- })
- }]
- }, {
- xtype: 'fieldset',
- title: _('General'),
- autoHeight: true,
- border: false,
- labelWidth: 10,
- defaultType: 'checkbox',
- items: [{
- fieldLabel: '',
- labelSeparator: '',
- boxLabel: _('Add In Paused
State'),
- id: 'add_paused'
- }, {
- fieldLabel: '',
- labelSeparator: '',
- boxLabel: _('Prioritize
First/Last Piece'),
- id:
'prioritize_first_last_pieces'
- }, {
- xtype: 'button',
- text: _('Apply to All'),
- style: 'margin-left: 20px;
margin-top: 5px;'
- }, {
- xtype: 'button',
- text: _('Revert to Defaults'),
- style: 'margin-left: 20px;
margin-top: 5px;'
- }]
- }]
- }],
- listeners: {
- 'render': {
- fn: Deluge.Add.onOptionsRender,
- scope: Deluge.Add
- }
- }
- })]
- }]
-});
-
-Deluge.Add.File = {
- onAdd: function() {
- if (this.form.getForm().isValid()) {
- this.form.getForm().submit({
- url: '/upload',
- waitMsg: _('Uploading your torrent...'),
- success:
this.onUploadSuccess.bindWithEvent(this)
- });
- }
- },
-
- onUploadSuccess: function(fp, upload) {
- this.Window.hide();
- var filename = upload.result.toString();
- this.form.items.get('torrentFile').setValue('');
- Deluge.Client.web.get_torrent_info(filename, {
- onSuccess:
Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add, filename)
- });
- }
-}
-
-Deluge.Add.File.form = new Ext.form.FormPanel({
- fileUpload: true,
- id: 'fileAddForm',
- baseCls: 'x-plain',
- labelWidth: 55,
- autoHeight: true,
- items: [{
- xtype: 'fileuploadfield',
- id: 'torrentFile',
- emptyText: _('Select a torrent'),
- fieldLabel: _('File'),
- name: 'file',
- buttonCfg: {
- text: _('Browse') + '...'
- }
- }]
-});
-
-Deluge.Add.File.Window = new Ext.Window({
- layout: 'fit',
- width: 350,
- height: 115,
- bodyStyle: 'padding: 10px 5px;',
- buttonAlign: 'center',
- closeAction: 'hide',
- modal: true,
- plain: true,
- title: _('Add from File'),
- iconCls: 'x-deluge-add-file',
- items: Deluge.Add.File.form,
- buttons: [{
- text: _('Add'),
- handler: Deluge.Add.File.onAdd,
- scope: Deluge.Add.File
- }]
-});
-
-Deluge.Add.Url = {
- onAdd: function(field, e) {
- if (field.id == 'url' && e.getKey() != e.ENTER) return;
-
- var field = this.form.items.get('url');
- var url = field.getValue();
-
- Deluge.Client.web.download_torrent_from_url(url, {
- onSuccess: this.onDownload.bindWithEvent(this)
- });
- this.Window.hide();
- },
-
- onDownload: function(filename) {
- this.form.items.get('url').setValue('');
- Deluge.Client.web.get_torrent_info(filename, {
- onSuccess:
Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add, filename)
- });
- }
-}
-
-Deluge.Add.Url.form = ;
-*/
\ No newline at end of file
+Deluge.Add = new Ext.deluge.add.AddWindow();
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---