2
Script: Deluge.EditTrackers.js
3
Contains the edit trackers window.
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)
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.
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.
23
In addition, as a special exception, the copyright holders give
24
permission to link the code of portions of this program with the OpenSSL
26
You must obey the GNU General Public License in all respects for all of
27
the code used other than OpenSSL. If you modify file(s) with this
28
exception, you may extend this exception to your version of the file(s),
29
but you are not obligated to do so. If you do not wish to do so, delete
30
this exception statement from your version. If you delete this exception
31
statement from all source files in the program, then also delete it here.
36
Ext.deluge.AddTracker = Ext.extend(Ext.Window, {
37
constructor: function(config) {
39
title: _('Add Tracker'),
42
bodyStyle: 'padding: 5px',
47
iconCls: 'x-deluge-edit-trackers',
51
Ext.deluge.AddTracker.superclass.constructor.call(this, config);
54
initComponent: function() {
55
Ext.deluge.AddTracker.superclass.initComponent.call(this);
57
this.addButton(_('Cancel'), this.onCancel, this);
58
this.addButton(_('Add'), this.onAdd, this);
59
this.addEvents('add');
61
this.form = this.add({
63
defaultType: 'textarea',
67
fieldLabel: _('Trackers'),
74
onCancel: function() {
75
this.form.getForm().findField('trackers').setValue('');
80
var trackers = this.form.getForm().findField('trackers').getValue();
81
trackers = trackers.split('\n');
84
Ext.each(trackers, function(tracker) {
85
if (Ext.form.VTypes.url(tracker)) {
86
cleaned.push(tracker);
89
this.fireEvent('add', cleaned);
91
this.form.getForm().findField('trackers').setValue('');
95
Ext.deluge.EditTracker = Ext.extend(Ext.Window, {
96
constructor: function(config) {
98
title: _('Edit Tracker'),
101
bodyStyle: 'padding: 5px',
103
buttonAlign: 'right',
106
iconCls: 'x-deluge-edit-trackers',
110
Ext.deluge.EditTracker.superclass.constructor.call(this, config);
113
initComponent: function() {
114
Ext.deluge.EditTracker.superclass.initComponent.call(this);
116
this.addButton(_('Cancel'), this.onCancel, this);
117
this.addButton(_('Save'), this.onSave, this);
118
this.on('hide', this.onHide, this);
120
this.form = this.add({
122
defaultType: 'textfield',
126
fieldLabel: _('Tracker'),
133
show: function(record) {
134
Ext.deluge.EditTracker.superclass.show.call(this);
136
this.record = record;
137
this.form.getForm().findField('tracker').setValue(record.data['url']);
140
onCancel: function() {
145
this.form.getForm().findField('tracker').setValue('');
149
var url = this.form.getForm().findField('tracker').getValue();
150
this.record.set('url', url);
151
this.record.commit();
156
Ext.deluge.EditTrackers = Ext.extend(Ext.Window, {
158
constructor: function(config) {
160
title: _('Edit Trackers'),
163
bodyStyle: 'padding: 5px',
165
buttonAlign: 'right',
168
iconCls: 'x-deluge-edit-trackers',
172
Ext.deluge.EditTrackers.superclass.constructor.call(this, config);
175
initComponent: function() {
176
Ext.deluge.EditTrackers.superclass.initComponent.call(this);
178
this.addButton(_('Cancel'), this.onCancel, this);
179
this.addButton(_('Ok'), this.onOk, this);
180
this.addEvents('save');
182
this.on('show', this.onShow, this);
183
this.on('save', this.onSave, this);
185
this.addWindow = new Ext.deluge.AddTracker();
186
this.addWindow.on('add', this.onAddTrackers, this);
187
this.editWindow = new Ext.deluge.EditTracker();
189
this.grid = this.add({
191
store: new Ext.data.SimpleStore({
193
{name: 'tier', mapping: 0},
194
{name: 'url', mapping: 1}
205
header: _('Tracker'),
211
selModel: new Ext.grid.RowSelectionModel({
214
'selectionchange': {fn: this.onSelect, scope: this}
217
autoExpandColumn: 'tracker',
218
deferredRender:false,
221
bbar: new Ext.Toolbar({
224
cls: 'x-btn-text-icon',
226
icon: '/icons/up.png',
230
cls: 'x-btn-text-icon',
232
icon: '/icons/down.png',
233
handler: this.onDown,
236
cls: 'x-btn-text-icon',
238
icon: '/icons/add.png',
242
cls: 'x-btn-text-icon',
244
icon: '/icons/edit_trackers.png',
245
handler: this.onEdit,
248
cls: 'x-btn-text-icon',
250
icon: '/icons/remove.png',
251
handler: this.onRemove,
260
this.addWindow.show();
263
onAddTrackers: function(trackers) {
264
var store = this.grid.getStore();
265
Ext.each(trackers, function(tracker) {
266
var duplicate = false, heightestTier = -1;
267
store.each(function(record) {
268
if (record.get('tier') > heightestTier) {
269
heightestTier = record.get('tier');
271
if (tracker == record.get('tracker')) {
277
store.loadData([[heightestTier + 1, tracker]], true);
282
onCancel: function() {
287
var r = this.grid.getSelectionModel().getSelected();
288
this.editWindow.show(r);
292
this.grid.getStore().removeAll();
297
this.grid.getStore().each(function(record) {
299
'tier': record.get('tier'),
300
'url': record.get('url')
304
Deluge.Client.core.set_torrent_trackers(this.torrentId, trackers, {
305
failure: this.onSaveFail,
312
onRemove: function() {
313
// Remove from the grid
314
var r = this.grid.getSelectionModel().getSelected();
315
this.grid.getStore().remove(r);
318
onRequestComplete: function(status) {
320
Ext.each(status['trackers'], function(tracker) {
321
trackers.push([tracker['tier'], tracker['url']]);
323
this.grid.getStore().loadData(trackers);
326
onSaveFail: function() {
330
onSelect: function(sm) {
331
if (sm.hasSelection()) {
332
this.grid.getBottomToolbar().items.get(4).enable();
337
this.grid.getBottomToolbar().items.get(4).disable();
338
var r = Deluge.Torrents.getSelected();
339
this.torrentId = r.id;
340
Deluge.Client.core.get_torrent_status(r.id, ['trackers'], {
341
success: this.onRequestComplete,
346
Deluge.EditTrackers = new Ext.deluge.EditTrackers();
b'\\ No newline at end of file'