1 | /*
|
---|
2 | Script: Deluge.Add.js
|
---|
3 | Contains the Add Torrent window.
|
---|
4 |
|
---|
5 | Copyright:
|
---|
6 | (C) Damien Churchill 2009 <damoxc@gmail.com>
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 3, or (at your option)
|
---|
10 | any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program. If not, write to:
|
---|
19 | The Free Software Foundation, Inc.,
|
---|
20 | 51 Franklin Street, Fifth Floor
|
---|
21 | Boston, MA 02110-1301, USA.
|
---|
22 | */
|
---|
23 |
|
---|
24 | Ext.namespace('Ext.deluge.add');
|
---|
25 | Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
---|
26 |
|
---|
27 | constructor: function(config) {
|
---|
28 | config = Ext.apply({
|
---|
29 | region: 'south',
|
---|
30 | margins: '5 5 5 5',
|
---|
31 | activeTab: 0,
|
---|
32 | height: 220
|
---|
33 | }, config);
|
---|
34 | Ext.deluge.add.OptionsPanel.superclass.constructor.call(this, config);
|
---|
35 | },
|
---|
36 |
|
---|
37 | initComponent: function() {
|
---|
38 | Ext.deluge.add.OptionsPanel.superclass.initComponent.call(this);
|
---|
39 | this.files = this.add(new Ext.tree.ColumnTree({
|
---|
40 | layout: 'fit',
|
---|
41 | title: _('Files'),
|
---|
42 | rootVisible: false,
|
---|
43 | autoScroll: true,
|
---|
44 | height: 170,
|
---|
45 | border: false,
|
---|
46 | animate: false,
|
---|
47 |
|
---|
48 | columns: [{
|
---|
49 | header: _('Filename'),
|
---|
50 | width: 275,
|
---|
51 | dataIndex: 'filename'
|
---|
52 | },{
|
---|
53 | header: _('Size'),
|
---|
54 | width: 80,
|
---|
55 | dataIndex: 'size'
|
---|
56 | }],
|
---|
57 |
|
---|
58 | root: new Ext.tree.AsyncTreeNode({
|
---|
59 | text: 'Files'
|
---|
60 | })
|
---|
61 | }));
|
---|
62 | new Ext.tree.TreeSorter(this.files, {
|
---|
63 | folderSort: true
|
---|
64 | });
|
---|
65 | },
|
---|
66 |
|
---|
67 | clear: function() {
|
---|
68 | this.clearFiles();
|
---|
69 | },
|
---|
70 |
|
---|
71 | clearFiles: function() {
|
---|
72 | var root = this.files.getRootNode();
|
---|
73 | if (!root.hasChildNodes()) return;
|
---|
74 | root.cascade(function(node) {
|
---|
75 | if (!node.parentNode || !node.getOwnerTree()) return;
|
---|
76 | node.remove();
|
---|
77 | });
|
---|
78 | },
|
---|
79 |
|
---|
80 | getDefaults: function() {
|
---|
81 | var keys = [
|
---|
82 | 'add_paused',
|
---|
83 | 'compact_allocation',
|
---|
84 | 'download_location',
|
---|
85 | 'max_connections_per_torrent',
|
---|
86 | 'max_download_speed_per_torrent',
|
---|
87 | 'max_upload_slots_per_torrent',
|
---|
88 | 'max_upload_speed_per_torrent',
|
---|
89 | 'prioritize_first_last_pieces'
|
---|
90 | ]
|
---|
91 | Deluge.Client.core.get_config_values(keys, {
|
---|
92 | onSuccess: function(config) {
|
---|
93 | this.defaults = config;
|
---|
94 | $each(config, function(value, key) {
|
---|
95 | var field = this.form.findField(key);
|
---|
96 | if (!field) return;
|
---|
97 | field.setValue(value);
|
---|
98 | }, this);
|
---|
99 | var field = this.form.findField('compact_allocation');
|
---|
100 | if (config['compact_allocation']) {
|
---|
101 | field.items.get('compact_allocation_true').setValue(true);
|
---|
102 | field.items.get('compact_allocation_false').setValue(false);
|
---|
103 | } else {
|
---|
104 | field.items.get('compact_allocation_false').setValue(true);
|
---|
105 | field.items.get('compact_allocation_true').setValue(false);
|
---|
106 | }
|
---|
107 | }.bindWithEvent(this)
|
---|
108 | });
|
---|
109 | }
|
---|
110 | });
|
---|
111 |
|
---|
112 | Ext.deluge.add.Window = Ext.extend(Ext.Window, {
|
---|
113 | initComponent: function() {
|
---|
114 | Ext.deluge.add.Window.superclass.initComponent.call(this);
|
---|
115 | this.addEvents(
|
---|
116 | 'beforeadd',
|
---|
117 | 'add'
|
---|
118 | );
|
---|
119 | }
|
---|
120 | });
|
---|
121 |
|
---|
122 | Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
|
---|
123 |
|
---|
124 | torrents: {},
|
---|
125 |
|
---|
126 | constructor: function(config) {
|
---|
127 | config = Ext.apply({
|
---|
128 | title: _('Add Torrents'),
|
---|
129 | layout: 'border',
|
---|
130 | width: 470,
|
---|
131 | height: 450,
|
---|
132 | bodyStyle: 'padding: 10px 5px;',
|
---|
133 | buttonAlign: 'right',
|
---|
134 | closeAction: 'hide',
|
---|
135 | closable: true,
|
---|
136 | plain: true,
|
---|
137 | iconCls: 'x-deluge-add-window-icon'
|
---|
138 | }, config);
|
---|
139 | Ext.deluge.add.AddWindow.superclass.constructor.call(this, config);
|
---|
140 | },
|
---|
141 |
|
---|
142 | initComponent: function() {
|
---|
143 | Ext.deluge.add.AddWindow.superclass.initComponent.call(this);
|
---|
144 |
|
---|
145 | this.addButton(_('Cancel'), this.onCancel, this);
|
---|
146 | this.addButton(_('Add'), this.onAdd, this);
|
---|
147 |
|
---|
148 | this.grid = this.add({
|
---|
149 | xtype: 'grid',
|
---|
150 | region: 'center',
|
---|
151 | store: new Ext.data.SimpleStore({
|
---|
152 | fields: [{name: 'torrent', mapping: 1}],
|
---|
153 | id: 0
|
---|
154 | }),
|
---|
155 | columns: [{
|
---|
156 | id: 'torrent',
|
---|
157 | width: 150,
|
---|
158 | sortable: true,
|
---|
159 | renderer: fplain,
|
---|
160 | dataIndex: 'torrent'
|
---|
161 | }],
|
---|
162 | stripeRows: true,
|
---|
163 | selModel: new Ext.grid.RowSelectionModel({
|
---|
164 | singleSelect: true,
|
---|
165 | listeners: {
|
---|
166 | 'rowselect': {
|
---|
167 | fn: this.onSelect,
|
---|
168 | scope: this
|
---|
169 | }
|
---|
170 | }
|
---|
171 | }),
|
---|
172 | hideHeaders: true,
|
---|
173 | autoExpandColumn: 'torrent',
|
---|
174 | deferredRender: false,
|
---|
175 | autoScroll: true,
|
---|
176 | margins: '5 5 5 5',
|
---|
177 | bbar: new Ext.Toolbar({
|
---|
178 | items: [{
|
---|
179 | id: 'file',
|
---|
180 | cls: 'x-btn-text-icon',
|
---|
181 | iconCls: 'x-deluge-add-file',
|
---|
182 | text: _('File'),
|
---|
183 | handler: this.onFile,
|
---|
184 | scope: this
|
---|
185 | }, {
|
---|
186 | id: 'url',
|
---|
187 | cls: 'x-btn-text-icon',
|
---|
188 | text: _('Url'),
|
---|
189 | icon: '/icons/add_url.png',
|
---|
190 | handler: this.onUrl,
|
---|
191 | scope: this
|
---|
192 | }, {
|
---|
193 | id: 'infohash',
|
---|
194 | cls: 'x-btn-text-icon',
|
---|
195 | text: _('Infohash'),
|
---|
196 | icon: '/icons/add_magnet.png',
|
---|
197 | disabled: true
|
---|
198 | }, '->', {
|
---|
199 | id: 'remove',
|
---|
200 | cls: 'x-btn-text-icon',
|
---|
201 | text: _('Remove'),
|
---|
202 | icon: '/icons/remove.png',
|
---|
203 | handler: this.onRemove,
|
---|
204 | scope: this
|
---|
205 | }]
|
---|
206 | })
|
---|
207 | });
|
---|
208 |
|
---|
209 | this.options = this.add(new Ext.deluge.add.OptionsPanel());
|
---|
210 | this.on('show', this.onShow, this);
|
---|
211 | },
|
---|
212 |
|
---|
213 | clear: function() {
|
---|
214 | this.torrents = {};
|
---|
215 | this.grid.getStore().removeAll();
|
---|
216 | this.options.clear();
|
---|
217 | },
|
---|
218 |
|
---|
219 | onAdd: function() {
|
---|
220 | torrents = [];
|
---|
221 | for (var id in this.torrents) {
|
---|
222 | var info = this.torrents[id];
|
---|
223 | torrents.push({
|
---|
224 | path: info['filename'],
|
---|
225 | options: {}
|
---|
226 | });
|
---|
227 | }
|
---|
228 | Deluge.Client.web.add_torrents(torrents, {
|
---|
229 | success: function(result) {
|
---|
230 | }
|
---|
231 | })
|
---|
232 | this.clear();
|
---|
233 | this.hide();
|
---|
234 | },
|
---|
235 |
|
---|
236 | onCancel: function() {
|
---|
237 | this.clear();
|
---|
238 | this.hide();
|
---|
239 | },
|
---|
240 |
|
---|
241 | onFile: function() {
|
---|
242 | this.file.show();
|
---|
243 | },
|
---|
244 |
|
---|
245 | onRemove: function() {
|
---|
246 | var selection = this.grid.getSelectionModel();
|
---|
247 | if (!selection.hasSelection()) return;
|
---|
248 | var torrent = selection.getSelected();
|
---|
249 |
|
---|
250 | delete this.torrents[torrent.id];
|
---|
251 | this.grid.getStore().remove(torrent);
|
---|
252 | this.clearFiles();
|
---|
253 | },
|
---|
254 |
|
---|
255 | onSelect: function(selModel, rowIndex, record) {
|
---|
256 | var torrentInfo = this.torrents[record.id];
|
---|
257 |
|
---|
258 | function walk(files, parent) {
|
---|
259 | for (var file in files) {
|
---|
260 | var item = files[file];
|
---|
261 |
|
---|
262 | if (Ext.type(item) == 'object') {
|
---|
263 | var child = new Ext.tree.TreeNode({
|
---|
264 | text: file
|
---|
265 | });
|
---|
266 | walk(item, child);
|
---|
267 | parent.appendChild(child);
|
---|
268 | } else {
|
---|
269 | parent.appendChild(new Ext.tree.TreeNode({
|
---|
270 | filename: file,
|
---|
271 | text: file, // this needs to be here for sorting reasons
|
---|
272 | size: fsize(item[0]),
|
---|
273 | leaf: true,
|
---|
274 | checked: item[1],
|
---|
275 | iconCls: 'x-deluge-file',
|
---|
276 | uiProvider: Ext.tree.ColumnNodeUI
|
---|
277 | }));
|
---|
278 | }
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | this.options.clearFiles();
|
---|
283 | var root = this.options.files.getRootNode();
|
---|
284 | walk(torrentInfo['files_tree'], root);
|
---|
285 | root.firstChild.expand();
|
---|
286 | },
|
---|
287 |
|
---|
288 | onShow: function() {
|
---|
289 | if (!this.url) {
|
---|
290 | this.url = new Ext.deluge.add.UrlWindow();
|
---|
291 | this.url.on('beforeadd', this.onTorrentBeforeAdd, this);
|
---|
292 | this.url.on('add', this.onTorrentAdd, this);
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (!this.file) {
|
---|
296 | this.file = new Ext.deluge.add.FileWindow();
|
---|
297 | this.file.on('beforeadd', this.onTorrentBeforeAdd, this);
|
---|
298 | this.file.on('add', this.onTorrentAdd, this);
|
---|
299 | }
|
---|
300 | },
|
---|
301 |
|
---|
302 | onTorrentBeforeAdd: function(temptext) {
|
---|
303 | },
|
---|
304 |
|
---|
305 | onTorrentAdd: function(info) {
|
---|
306 | if (!info) {
|
---|
307 | Ext.MessageBox.show({
|
---|
308 | title: _('Error'),
|
---|
309 | msg: _('Not a valid torrent'),
|
---|
310 | buttons: Ext.MessageBox.OK,
|
---|
311 | modal: false,
|
---|
312 | icon: Ext.MessageBox.ERROR,
|
---|
313 | iconCls: 'x-deluge-icon-error'
|
---|
314 | });
|
---|
315 | return;
|
---|
316 | }
|
---|
317 | this.grid.getStore().loadData([[info['info_hash'], info['name']]], true);
|
---|
318 | this.torrents[info['info_hash']] = info;
|
---|
319 | },
|
---|
320 |
|
---|
321 | onUrl: function(button, event) {
|
---|
322 | this.url.show();
|
---|
323 | }
|
---|
324 | });
|
---|
325 | Deluge.Add = new Ext.deluge.add.AddWindow();
|
---|
326 |
|
---|
327 | /*Deluge.Add = {
|
---|
328 | onFile: function() {
|
---|
329 | this.File.Window.show();
|
---|
330 | },
|
---|
331 |
|
---|
332 | onOptionsRender: function(panel) {
|
---|
333 | panel.layout = new Ext.layout.FormLayout();
|
---|
334 | panel.layout.setContainer(panel);
|
---|
335 | panel.doLayout();
|
---|
336 | this.form = panel.getForm();
|
---|
337 | this.getDefaults();
|
---|
338 | },
|
---|
339 |
|
---|
340 | onRender: function(window) {
|
---|
341 | new Ext.tree.TreeSorter(this.Files, {
|
---|
342 | folderSort: true
|
---|
343 | });
|
---|
344 | },
|
---|
345 |
|
---|
346 | onSelect: function(selModel, rowIndex, record) {
|
---|
347 | var torrentInfo = Deluge.Add.torrents[record.id];
|
---|
348 |
|
---|
349 | function walk(files, parent) {
|
---|
350 | $each(files, function(item, file) {
|
---|
351 | if ($type(item) == 'object') {
|
---|
352 | var child = new Ext.tree.TreeNode({
|
---|
353 | text: file
|
---|
354 | });
|
---|
355 | walk(item, child);
|
---|
356 | parent.appendChild(child);
|
---|
357 | } else {
|
---|
358 | parent.appendChild(new Ext.tree.TreeNode({
|
---|
359 | filename: file,
|
---|
360 | text: file, // this needs to be here for sorting reasons
|
---|
361 | size: fsize(item[0]),
|
---|
362 | leaf: true,
|
---|
363 | checked: item[1],
|
---|
364 | iconCls: 'x-deluge-file',
|
---|
365 | uiProvider: Ext.tree.ColumnNodeUI
|
---|
366 | }));
|
---|
367 | }
|
---|
368 | });
|
---|
369 | }
|
---|
370 |
|
---|
371 | this.clearFiles();
|
---|
372 |
|
---|
373 | var root = this.Files.getRootNode();
|
---|
374 | walk(torrentInfo['files_tree'], root);
|
---|
375 | root.firstChild.expand();
|
---|
376 | },
|
---|
377 |
|
---|
378 | onTorrentAdded: function(info, filename) {
|
---|
379 | if (!info) {
|
---|
380 | Ext.MessageBox.show({
|
---|
381 | title: _('Error'),
|
---|
382 | msg: _('Not a valid torrent'),
|
---|
383 | buttons: Ext.MessageBox.OK,
|
---|
384 | modal: false,
|
---|
385 | icon: Ext.MessageBox.ERROR,
|
---|
386 | iconCls: 'x-deluge-icon-error'
|
---|
387 | });
|
---|
388 | return;
|
---|
389 | }
|
---|
390 | info['filename'] = filename;
|
---|
391 | this.Store.loadData([[info['info_hash'], info['name']]], true);
|
---|
392 | this.torrents[info['info_hash']] = info;
|
---|
393 | },
|
---|
394 |
|
---|
395 | onUrl: function(button, event) {
|
---|
396 | this.Url.Window.show();
|
---|
397 | },
|
---|
398 |
|
---|
399 | onRemove: function() {
|
---|
400 | var selection = this.Grid.getSelectionModel();
|
---|
401 | if (!selection.hasSelection()) return;
|
---|
402 | var torrent = selection.getSelected();
|
---|
403 |
|
---|
404 | delete this.torrents[torrent.id];
|
---|
405 | this.Store.remove(torrent);
|
---|
406 | this.clearFiles();
|
---|
407 | }
|
---|
408 | }
|
---|
409 |
|
---|
410 | Deluge.Add.Options = new Ext.TabPanel({
|
---|
411 | region: 'south',
|
---|
412 | margins: '5 5 5 5',
|
---|
413 | activeTab: 0,
|
---|
414 | height: 220,
|
---|
415 | items: [{
|
---|
416 | id: 'addFilesTab',
|
---|
417 | title: _('Files'),
|
---|
418 | items: [Deluge.Add.Files]
|
---|
419 | },{
|
---|
420 | id: 'addOptionsTab',
|
---|
421 | title: _('Options'),
|
---|
422 | layout: 'fit',
|
---|
423 | items: [new Ext.form.FormPanel({
|
---|
424 | id: 'addOptionsForm',
|
---|
425 | bodyStyle: 'padding: 5px;',
|
---|
426 | border: false,
|
---|
427 | items: [{
|
---|
428 | xtype: 'fieldset',
|
---|
429 | style: 'padding: 0px; padding-top: 5px;',
|
---|
430 | title: _('Download Location'),
|
---|
431 | border: false,
|
---|
432 | autoHeight: true,
|
---|
433 | border: false,
|
---|
434 | labelWidth: 1,
|
---|
435 | items: [{
|
---|
436 | layout: 'column',
|
---|
437 | border: false,
|
---|
438 | items: [{
|
---|
439 | xtype: 'textfield',
|
---|
440 | id: 'download_location',
|
---|
441 | fieldLabel: '',
|
---|
442 | labelSeparator: '',
|
---|
443 | width: 330
|
---|
444 | }, {
|
---|
445 | border: false,
|
---|
446 | style: 'padding-left: 5px;',
|
---|
447 | items: [{
|
---|
448 | xtype: 'button',
|
---|
449 | text: _('Browse') + '...',
|
---|
450 | disabled: true
|
---|
451 | }]
|
---|
452 | }]
|
---|
453 | }]
|
---|
454 | }, {
|
---|
455 | layout: 'column',
|
---|
456 | border: false,
|
---|
457 | defaults: {
|
---|
458 | border: false
|
---|
459 | },
|
---|
460 | items: [{
|
---|
461 | xtype: 'fieldset',
|
---|
462 | bodyStyle: 'margin-left: 5px; margin-right:5px;',
|
---|
463 | title: _('Allocation'),
|
---|
464 | autoHeight: true,
|
---|
465 | border: false,
|
---|
466 | labelWidth: 1,
|
---|
467 | width: 100,
|
---|
468 | items: [new Ext.form.RadioGroup({
|
---|
469 | id: 'compact_allocation',
|
---|
470 | name: 'compact_allocation',
|
---|
471 | columns: 1,
|
---|
472 | labelSeparator: '',
|
---|
473 | items: [{
|
---|
474 | boxLabel: _('Full'),
|
---|
475 | inputValue: 'false',
|
---|
476 | id: 'compact_allocation_false',
|
---|
477 | name: 'compact_allocation',
|
---|
478 | checked: true
|
---|
479 | },{
|
---|
480 | boxLabel: _('Compact'),
|
---|
481 | inputValue: 'true',
|
---|
482 | id: 'compact_allocation_true',
|
---|
483 | name: 'compact_allocation'
|
---|
484 | }]
|
---|
485 | })]
|
---|
486 | }, {
|
---|
487 | xtype: 'fieldset',
|
---|
488 | title: _('Bandwidth'),
|
---|
489 | layout: 'form',
|
---|
490 | autoHeight: true,
|
---|
491 | defaultType: 'uxspinner',
|
---|
492 | labelWidth: 100,
|
---|
493 | items: [{
|
---|
494 | id: 'max_download_speed_per_torrent',
|
---|
495 | fieldLabel: _('Max Down Speed'),
|
---|
496 | width: 60,
|
---|
497 | value: -1,
|
---|
498 | strategy: new Ext.ux.form.Spinner.NumberStrategy({
|
---|
499 | minValue: -1,
|
---|
500 | maxValue: 99999,
|
---|
501 | incrementValue: 1
|
---|
502 | })
|
---|
503 | }, {
|
---|
504 | id: 'max_upload_speed_per_torrent',
|
---|
505 | fieldLabel: _('Max Up Speed'),
|
---|
506 | width: 60,
|
---|
507 | value: -1,
|
---|
508 | strategy: new Ext.ux.form.Spinner.NumberStrategy({
|
---|
509 | minValue: -1,
|
---|
510 | maxValue: 99999,
|
---|
511 | incrementValue: 1
|
---|
512 | })
|
---|
513 | }, {
|
---|
514 | id: 'max_connections_per_torrent',
|
---|
515 | fieldLabel: _('Max Connections'),
|
---|
516 | width: 60,
|
---|
517 | value: -1,
|
---|
518 | strategy: new Ext.ux.form.Spinner.NumberStrategy({
|
---|
519 | minValue: -1,
|
---|
520 | maxValue: 99999,
|
---|
521 | incrementValue: 1
|
---|
522 | })
|
---|
523 | }, {
|
---|
524 | id: 'max_upload_slots_per_torrent',
|
---|
525 | fieldLabel: _('Max Upload Slots'),
|
---|
526 | colspan: 2,
|
---|
527 | width: 60,
|
---|
528 | value: -1,
|
---|
529 | strategy: new Ext.ux.form.Spinner.NumberStrategy({
|
---|
530 | minValue: -1,
|
---|
531 | maxValue: 99999,
|
---|
532 | incrementValue: 1
|
---|
533 | })
|
---|
534 | }]
|
---|
535 | }, {
|
---|
536 | xtype: 'fieldset',
|
---|
537 | title: _('General'),
|
---|
538 | autoHeight: true,
|
---|
539 | border: false,
|
---|
540 | labelWidth: 10,
|
---|
541 | defaultType: 'checkbox',
|
---|
542 | items: [{
|
---|
543 | fieldLabel: '',
|
---|
544 | labelSeparator: '',
|
---|
545 | boxLabel: _('Add In Paused State'),
|
---|
546 | id: 'add_paused'
|
---|
547 | }, {
|
---|
548 | fieldLabel: '',
|
---|
549 | labelSeparator: '',
|
---|
550 | boxLabel: _('Prioritize First/Last Piece'),
|
---|
551 | id: 'prioritize_first_last_pieces'
|
---|
552 | }, {
|
---|
553 | xtype: 'button',
|
---|
554 | text: _('Apply to All'),
|
---|
555 | style: 'margin-left: 20px; margin-top: 5px;'
|
---|
556 | }, {
|
---|
557 | xtype: 'button',
|
---|
558 | text: _('Revert to Defaults'),
|
---|
559 | style: 'margin-left: 20px; margin-top: 5px;'
|
---|
560 | }]
|
---|
561 | }]
|
---|
562 | }],
|
---|
563 | listeners: {
|
---|
564 | 'render': {
|
---|
565 | fn: Deluge.Add.onOptionsRender,
|
---|
566 | scope: Deluge.Add
|
---|
567 | }
|
---|
568 | }
|
---|
569 | })]
|
---|
570 | }]
|
---|
571 | });
|
---|
572 |
|
---|
573 | Deluge.Add.File = {
|
---|
574 | onAdd: function() {
|
---|
575 | if (this.form.getForm().isValid()) {
|
---|
576 | this.form.getForm().submit({
|
---|
577 | url: '/upload',
|
---|
578 | waitMsg: _('Uploading your torrent...'),
|
---|
579 | success: this.onUploadSuccess.bindWithEvent(this)
|
---|
580 | });
|
---|
581 | }
|
---|
582 | },
|
---|
583 |
|
---|
584 | onUploadSuccess: function(fp, upload) {
|
---|
585 | this.Window.hide();
|
---|
586 | var filename = upload.result.toString();
|
---|
587 | this.form.items.get('torrentFile').setValue('');
|
---|
588 | Deluge.Client.web.get_torrent_info(filename, {
|
---|
589 | onSuccess: Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add, filename)
|
---|
590 | });
|
---|
591 | }
|
---|
592 | }
|
---|
593 |
|
---|
594 | Deluge.Add.File.form = new Ext.form.FormPanel({
|
---|
595 | fileUpload: true,
|
---|
596 | id: 'fileAddForm',
|
---|
597 | baseCls: 'x-plain',
|
---|
598 | labelWidth: 55,
|
---|
599 | autoHeight: true,
|
---|
600 | items: [{
|
---|
601 | xtype: 'fileuploadfield',
|
---|
602 | id: 'torrentFile',
|
---|
603 | emptyText: _('Select a torrent'),
|
---|
604 | fieldLabel: _('File'),
|
---|
605 | name: 'file',
|
---|
606 | buttonCfg: {
|
---|
607 | text: _('Browse') + '...'
|
---|
608 | }
|
---|
609 | }]
|
---|
610 | });
|
---|
611 |
|
---|
612 | Deluge.Add.File.Window = new Ext.Window({
|
---|
613 | layout: 'fit',
|
---|
614 | width: 350,
|
---|
615 | height: 115,
|
---|
616 | bodyStyle: 'padding: 10px 5px;',
|
---|
617 | buttonAlign: 'center',
|
---|
618 | closeAction: 'hide',
|
---|
619 | modal: true,
|
---|
620 | plain: true,
|
---|
621 | title: _('Add from File'),
|
---|
622 | iconCls: 'x-deluge-add-file',
|
---|
623 | items: Deluge.Add.File.form,
|
---|
624 | buttons: [{
|
---|
625 | text: _('Add'),
|
---|
626 | handler: Deluge.Add.File.onAdd,
|
---|
627 | scope: Deluge.Add.File
|
---|
628 | }]
|
---|
629 | });
|
---|
630 |
|
---|
631 | Deluge.Add.Url = {
|
---|
632 | onAdd: function(field, e) {
|
---|
633 | if (field.id == 'url' && e.getKey() != e.ENTER) return;
|
---|
634 |
|
---|
635 | var field = this.form.items.get('url');
|
---|
636 | var url = field.getValue();
|
---|
637 |
|
---|
638 | Deluge.Client.web.download_torrent_from_url(url, {
|
---|
639 | onSuccess: this.onDownload.bindWithEvent(this)
|
---|
640 | });
|
---|
641 | this.Window.hide();
|
---|
642 | },
|
---|
643 |
|
---|
644 | onDownload: function(filename) {
|
---|
645 | this.form.items.get('url').setValue('');
|
---|
646 | Deluge.Client.web.get_torrent_info(filename, {
|
---|
647 | onSuccess: Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add, filename)
|
---|
648 | });
|
---|
649 | }
|
---|
650 | }
|
---|
651 |
|
---|
652 | Deluge.Add.Url.form = ;
|
---|
653 | */
|
---|