source: deluge/ui/web/js/Deluge.Add.File.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.File.js
3 Contains the Add Torrent by file 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.FileWindow = 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 File'),
36 iconCls: 'x-deluge-add-file',
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 baseCls: 'x-plain',
50 labelWidth: 55,
51 autoHeight: true,
52 fileUpload: true,
53 items: [{
54 xtype: 'fileuploadfield',
55 id: 'torrentFile',
56 emptyText: _('Select a torrent'),
57 fieldLabel: _('File'),
58 name: 'file',
59 buttonCfg: {
60 text: _('Browse') + '...'
61 }
62 }]
63 }));
64 },
65
66 onAdd: function(field, e) {
67 if (this.form.getForm().isValid()) {
68 this.form.getForm().submit({
69 url: '/upload',
70 waitMsg: _('Uploading your torrent...'),
71 success: this.onUploadSuccess,
72 scope: this
73 });
74 }
75 this.fireEvent('beforeadd', null);
76 },
77
78 onUploadSuccess: function(fp, upload) {
79 this.hide();
80 var filename = upload.result.toString();
81 this.form.getForm().findField('torrentFile').setValue('');
82 Deluge.Client.web.get_torrent_info(filename, {
83 success: this.onGotInfo,
84 scope: this,
85 filename: filename
86 });
87 },
88
89 onGotInfo: function(info, obj, response, request) {
90 info['filename'] = request.options.filename;
91 this.fireEvent('add', info);
92 }
93});
Note: See TracBrowser for help on using the repository browser.