source: deluge/ui/web/js/Deluge.Add.Url.js@ 8582915

2.0.x develop extjs4-port
Last change on this file since 8582915 was 8582915, checked in by Damien Churchill <damoc@gmail.com>, 16 years ago

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

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2Script: Deluge.Add.Url.js
3 Contains the Add Torrent by url window.
4
5Copyright:
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
24Ext.deluge.add.UrlWindow = Ext.extend(Ext.deluge.add.Window, {
25 constructor: function(config) {
26 config = Ext.apply({
27 layout: 'fit',
28 width: 350,
29 height: 115,
30 bodyStyle: 'padding: 10px 5px;',
31 buttonAlign: 'center',
32 closeAction: 'hide',
33 modal: true,
34 plain: true,
35 title: _('Add from Url'),
36 iconCls: 'x-deluge-add-url-window-icon',
37 buttons: [{
38 text: _('Add'),
39 handler: this.onAdd,
40 scope: this
41 }]
42 }, config);
43 Ext.deluge.add.UrlWindow.superclass.constructor.call(this, config);
44 },
45
46 initComponent: function() {
47 Ext.deluge.add.UrlWindow.superclass.initComponent.call(this);
48 this.form = this.add(new Ext.form.FormPanel({
49 defaultType: 'textfield',
50 baseCls: 'x-plain',
51 labelWidth: 55,
52 items: [{
53 fieldLabel: _('Url'),
54 id: 'url',
55 name: 'url',
56 inputType: 'url',
57 anchor: '100%',
58 listeners: {
59 'specialkey': {
60 fn: this.onAdd,
61 scope: this
62 }
63 }
64 }]
65 }));
66 },
67
68 onAdd: function(field, e) {
69 if (field.id == 'url' && e.getKey() != e.ENTER) return;
70
71 var field = this.form.items.get('url');
72 var url = field.getValue();
73 var torrentId = this.createTorrentId();
74
75 Deluge.Client.web.download_torrent_from_url(url, {
76 success: this.onDownload,
77 scope: this,
78 torrentId: torrentId
79 });
80 this.hide();
81 this.fireEvent('beforeadd', torrentId, url);
82 },
83
84 onDownload: function(filename, obj, resp, req) {
85 this.form.items.get('url').setValue('');
86 Deluge.Client.web.get_torrent_info(filename, {
87 success: this.onGotInfo,
88 scope: this,
89 filename: filename,
90 torrentId: req.options.torrentId
91 });
92 },
93
94 onGotInfo: function(info, obj, response, request) {
95 info['filename'] = request.options.filename;
96 this.fireEvent('add', request.options.torrentId, info);
97 }
98});
Note: See TracBrowser for help on using the repository browser.