source: deluge/ui/web/js/Deluge.Add.File.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.6 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.torrentId = this.createTorrentId();
69 this.form.getForm().submit({
70 url: '/upload',
71 waitMsg: _('Uploading your torrent...'),
72 success: this.onUploadSuccess,
73 scope: this
74 });
75 var name = this.form.getForm().findField('torrentFile').value;
76 this.fireEvent('beforeadd', this.torrentId, name);
77 }
78 },
79
80 onGotInfo: function(info, obj, response, request) {
81 info['filename'] = request.options.filename;
82 this.fireEvent('add', this.torrentId, info);
83 },
84
85 onUploadSuccess: function(fp, upload) {
86 this.hide();
87 var filename = upload.result.toString();
88 this.form.getForm().findField('torrentFile').setValue('');
89 Deluge.Client.web.get_torrent_info(filename, {
90 success: this.onGotInfo,
91 scope: this,
92 filename: filename
93 });
94 }
95});
Note: See TracBrowser for help on using the repository browser.