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

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

split out Deluge.Add into seperate smaller files
add back adding torrents via file

  • Property mode set to 100644
File size: 2.4 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
74 Deluge.Client.web.download_torrent_from_url(url, {
75 success: this.onDownload,
76 scope: this
77 });
78 this.hide();
79 this.fireEvent('beforeadd', url);
80 },
81
82 onDownload: function(filename) {
83 this.form.items.get('url').setValue('');
84 Deluge.Client.web.get_torrent_info(filename, {
85 success: this.onGotInfo,
86 scope: this,
87 filename: filename
88 });
89 },
90
91 onGotInfo: function(info, obj, response, request) {
92 info['filename'] = request.options.filename;
93 this.fireEvent('add', info);
94 }
95});
Note: See TracBrowser for help on using the repository browser.