Convert tabs to spaces in label.js

This commit is contained in:
Bobby R. Ward 2012-02-20 16:54:08 -06:00 committed by Calum Lind
commit bc425b392a

View file

@ -1,6 +1,6 @@
/*! /*!
* label.js * label.js
* *
* Copyright (c) Damien Churchill 2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2010 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -36,65 +36,65 @@ Ext.ns('Deluge.ux');
* @extends Ext.Window * @extends Ext.Window
*/ */
Deluge.ux.AddLabelWindow = Ext.extend(Ext.Window, { Deluge.ux.AddLabelWindow = Ext.extend(Ext.Window, {
title: _('Add Label'),
width: 300,
height: 100,
initComponent: function() { title: _('Add Label'),
Deluge.ux.AddLabelWindow.superclass.initComponent.call(this); width: 300,
this.addButton(_('Cancel'), this.onCancelClick, this); height: 100,
this.addButton(_('Ok'), this.onOkClick, this);
this.form = this.add({ initComponent: function() {
xtype: 'form', Deluge.ux.AddLabelWindow.superclass.initComponent.call(this);
height: 35, this.addButton(_('Cancel'), this.onCancelClick, this);
baseCls: 'x-plain', this.addButton(_('Ok'), this.onOkClick, this);
bodyStyle:'padding:5px 5px 0',
defaultType: 'textfield',
labelWidth: 50,
items: [{
fieldLabel: _('Name'),
name: 'name',
allowBlank: false,
width: 220,
listeners: {
'specialkey': {
fn: function(field, e) {
if (e.getKey() == 13) this.onOkClick();
},
scope: this
}
}
}]
});
},
onCancelClick: function() { this.form = this.add({
this.hide(); xtype: 'form',
}, height: 35,
baseCls: 'x-plain',
bodyStyle:'padding:5px 5px 0',
defaultType: 'textfield',
labelWidth: 50,
items: [{
fieldLabel: _('Name'),
name: 'name',
allowBlank: false,
width: 220,
listeners: {
'specialkey': {
fn: function(field, e) {
if (e.getKey() == 13) this.onOkClick();
},
scope: this
}
}
}]
});
},
onOkClick: function() { onCancelClick: function() {
var label = this.form.getForm().getValues().name; this.hide();
deluge.client.label.add(label, { },
success: function() {
deluge.ui.update();
this.fireEvent('labeladded', label);
},
scope: this
});
this.hide();
},
onHide: function(comp) { onOkClick: function() {
Deluge.ux.AddLabelWindow.superclass.onHide.call(this, comp); var label = this.form.getForm().getValues().name;
this.form.getForm().reset(); deluge.client.label.add(label, {
}, success: function() {
deluge.ui.update();
this.fireEvent('labeladded', label);
},
scope: this
});
this.hide();
},
onShow: function(comp) { onHide: function(comp) {
Deluge.ux.AddLabelWindow.superclass.onShow.call(this, comp); Deluge.ux.AddLabelWindow.superclass.onHide.call(this, comp);
this.form.getForm().findField('name').focus(false, 150); this.form.getForm().reset();
} },
onShow: function(comp) {
Deluge.ux.AddLabelWindow.superclass.onShow.call(this, comp);
this.form.getForm().findField('name').focus(false, 150);
}
}); });
@ -104,243 +104,243 @@ Deluge.ux.AddLabelWindow = Ext.extend(Ext.Window, {
*/ */
Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, { Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
title: _('Label Options'), title: _('Label Options'),
width: 325, width: 325,
height: 240, height: 240,
initComponent: function() {
Deluge.ux.LabelOptionsWindow.superclass.initComponent.call(this);
this.addButton(_('Cancel'), this.onCancelClick, this);
this.addButton(_('Ok'), this.onOkClick, this);
this.form = this.add({ initComponent: function() {
xtype: 'form' Deluge.ux.LabelOptionsWindow.superclass.initComponent.call(this);
}); this.addButton(_('Cancel'), this.onCancelClick, this);
this.addButton(_('Ok'), this.onOkClick, this);
this.tabs = this.form.add({ this.form = this.add({
xtype: 'tabpanel', xtype: 'form'
height: 175, });
border: false,
items: [{
title: _('Maximum'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'apply_max',
fieldLabel: '',
boxLabel: _('Apply per torrent max settings:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
defaultType: 'spinnerfield',
style: 'margin-top: 0px; padding-top: 0px;',
items: [{
fieldLabel: _('Download Speed'),
name: 'max_download_speed',
width: 80,
disabled: true,
value: -1,
minValue: -1
}, {
fieldLabel: _('Upload Speed'),
name: 'max_upload_speed',
width: 80,
disabled: true,
value: -1,
minValue: -1
}, {
fieldLabel: _('Upload Slots'),
name: 'max_upload_slots',
width: 80,
disabled: true,
value: -1,
minValue: -1
}, {
fieldLabel: _('Connections'),
name: 'max_connections',
width: 80,
disabled: true,
value: -1,
minValue: -1
}]
}]
}]
}, {
title: _('Queue'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'apply_queue',
fieldLabel: '',
boxLabel: _('Apply queue settings:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
defaultType: 'checkbox',
style: 'margin-top: 0px; padding-top: 0px;',
defaults: {
style: 'margin-left: 20px'
},
items: [{
boxLabel: _('Auto Managed'),
name: 'is_auto_managed',
disabled: true
}, {
boxLabel: _('Stop seed at ratio:'),
name: 'stop_at_ratio',
disabled: true
}, {
xtype: 'spinnerfield',
name: 'stop_ratio',
width: 60,
decimalPrecision: 2,
incrementValue: 0.1,
style: 'position: relative; left: 100px',
disabled: true
}, {
boxLabel: _('Remove at ratio'),
name: 'remove_at_ratio',
disabled: true
}]
}]
}]
}, {
title: _('Location'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'apply_move_completed',
fieldLabel: '',
boxLabel: _('Apply location settings:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
defaultType: 'checkbox',
labelWidth: 1,
style: 'margin-top: 0px; padding-top: 0px;',
defaults: {
style: 'margin-left: 20px'
},
items: [{
boxLabel: _('Move completed to:'),
name: 'move_completed',
disabled: true
}, {
xtype: 'textfield',
name: 'move_completed_path',
width: 250,
disabled: true
}]
}]
}]
}, {
title: _('Trackers'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'auto_add',
fieldLabel: '',
boxLabel: _('Automatically apply label:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-top: 0px; padding-top: 0px;',
defaults: {
style: 'margin-left: 20px'
},
defaultType: 'textarea',
items: [{
boxLabel: _('Move completed to:'),
name: 'auto_add_trackers',
width: 250,
height: 100,
disabled: true
}]
}]
}]
}]
});
},
getLabelOptions: function() { this.tabs = this.form.add({
deluge.client.label.get_options(this.label, { xtype: 'tabpanel',
success: this.gotOptions, height: 175,
scope: this border: false,
}); items: [{
}, title: _('Maximum'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'apply_max',
fieldLabel: '',
boxLabel: _('Apply per torrent max settings:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
defaultType: 'spinnerfield',
style: 'margin-top: 0px; padding-top: 0px;',
items: [{
fieldLabel: _('Download Speed'),
name: 'max_download_speed',
width: 80,
disabled: true,
value: -1,
minValue: -1
}, {
fieldLabel: _('Upload Speed'),
name: 'max_upload_speed',
width: 80,
disabled: true,
value: -1,
minValue: -1
}, {
fieldLabel: _('Upload Slots'),
name: 'max_upload_slots',
width: 80,
disabled: true,
value: -1,
minValue: -1
}, {
fieldLabel: _('Connections'),
name: 'max_connections',
width: 80,
disabled: true,
value: -1,
minValue: -1
}]
}]
}]
}, {
title: _('Queue'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'apply_queue',
fieldLabel: '',
boxLabel: _('Apply queue settings:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
defaultType: 'checkbox',
style: 'margin-top: 0px; padding-top: 0px;',
defaults: {
style: 'margin-left: 20px'
},
items: [{
boxLabel: _('Auto Managed'),
name: 'is_auto_managed',
disabled: true
}, {
boxLabel: _('Stop seed at ratio:'),
name: 'stop_at_ratio',
disabled: true
}, {
xtype: 'spinnerfield',
name: 'stop_ratio',
width: 60,
decimalPrecision: 2,
incrementValue: 0.1,
style: 'position: relative; left: 100px',
disabled: true
}, {
boxLabel: _('Remove at ratio'),
name: 'remove_at_ratio',
disabled: true
}]
}]
}]
}, {
title: _('Location'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'apply_move_completed',
fieldLabel: '',
boxLabel: _('Apply location settings:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
defaultType: 'checkbox',
labelWidth: 1,
style: 'margin-top: 0px; padding-top: 0px;',
defaults: {
style: 'margin-left: 20px'
},
items: [{
boxLabel: _('Move completed to:'),
name: 'move_completed',
disabled: true
}, {
xtype: 'textfield',
name: 'move_completed_path',
width: 250,
disabled: true
}]
}]
}]
}, {
title: _('Trackers'),
items: [{
border: false,
items: [{
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [{
xtype: 'checkbox',
name: 'auto_add',
fieldLabel: '',
boxLabel: _('Automatically apply label:'),
listeners: {
check: this.onFieldChecked
}
}]
}, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
style: 'margin-top: 0px; padding-top: 0px;',
defaults: {
style: 'margin-left: 20px'
},
defaultType: 'textarea',
items: [{
boxLabel: _('Move completed to:'),
name: 'auto_add_trackers',
width: 250,
height: 100,
disabled: true
}]
}]
}]
}]
});
},
gotOptions: function(options) { getLabelOptions: function() {
this.form.getForm().setValues(options); deluge.client.label.get_options(this.label, {
}, success: this.gotOptions,
scope: this
});
},
show: function(label) { gotOptions: function(options) {
Deluge.ux.LabelOptionsWindow.superclass.show.call(this); this.form.getForm().setValues(options);
this.label = label; },
this.setTitle(_('Label Options') + ': ' + this.label);
this.tabs.setActiveTab(0);
this.getLabelOptions();
},
onCancelClick: function() { show: function(label) {
this.hide(); Deluge.ux.LabelOptionsWindow.superclass.show.call(this);
}, this.label = label;
this.setTitle(_('Label Options') + ': ' + this.label);
this.tabs.setActiveTab(0);
this.getLabelOptions();
},
onOkClick: function() { onCancelClick: function() {
var values = this.form.getForm().getFieldValues(); this.hide();
values['auto_add_trackers'] = values['auto_add_trackers'].split('\n'); },
deluge.client.label.set_options(this.label, values);
this.hide();
},
onFieldChecked: function(field, checked) { onOkClick: function() {
var fs = field.ownerCt.nextSibling(); var values = this.form.getForm().getFieldValues();
fs.items.each(function(field) { values['auto_add_trackers'] = values['auto_add_trackers'].split('\n');
field.setDisabled(!checked); deluge.client.label.set_options(this.label, values);
}); this.hide();
} },
onFieldChecked: function(field, checked) {
var fs = field.ownerCt.nextSibling();
fs.items.each(function(field) {
field.setDisabled(!checked);
});
}
}); });
@ -353,178 +353,178 @@ Ext.ns('Deluge.plugins');
*/ */
Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, { Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
name: 'Label', name: 'Label',
createMenu: function() { createMenu: function() {
this.labelMenu = new Ext.menu.Menu({ this.labelMenu = new Ext.menu.Menu({
items: [{ items: [{
text: _('Add Label'), text: _('Add Label'),
iconCls: 'icon-add', iconCls: 'icon-add',
handler: this.onLabelAddClick, handler: this.onLabelAddClick,
scope: this scope: this
}, { }, {
text: _('Remove Label'), text: _('Remove Label'),
disabled: true, disabled: true,
iconCls: 'icon-remove', iconCls: 'icon-remove',
handler: this.onLabelRemoveClick, handler: this.onLabelRemoveClick,
scope: this scope: this
}, { }, {
text: _('Label Options'), text: _('Label Options'),
disabled: true, disabled: true,
handler: this.onLabelOptionsClick, handler: this.onLabelOptionsClick,
scope: this scope: this
}] }]
}); });
}, },
setFilter: function(filter) { setFilter: function(filter) {
filter.show_zero = true; filter.show_zero = true;
filter.list.on('contextmenu', this.onLabelContextMenu, this); filter.list.on('contextmenu', this.onLabelContextMenu, this);
filter.header.on('contextmenu', this.onLabelHeaderContextMenu, this); filter.header.on('contextmenu', this.onLabelHeaderContextMenu, this);
this.filter = filter; this.filter = filter;
}, },
updateTorrentMenu: function(filter) { updateTorrentMenu: function(filter) {
for (var state in filter.getStates()) { for (var state in filter.getStates()) {
if (!state) continue; if (!state) continue;
this.torrentMenu.addMenuItem({ this.torrentMenu.addMenuItem({
text: state, text: state,
label: state, label: state,
handler: this.onTorrentMenuClick, handler: this.onTorrentMenuClick,
scope: this scope: this
}); });
} }
}, },
onDisable: function() {
deluge.sidebar.un('filtercreate', this.onFilterCreate);
deluge.sidebar.un('afterfiltercreate', this.onAfterFilterCreate);
delete Deluge.FilterPanel.templates.label;
this.deregisterTorrentStatus('label');
deluge.menus.torrent.remove(this.tmSep);
deluge.menus.torrent.remove(this.tm);
},
onEnable: function() {
this.torrentMenu = new Ext.menu.Menu({
items: [{
text: _('No Label'),
label: '',
handler: this.onTorrentMenuClick,
scope: this
}]
});
this.tmSep = deluge.menus.torrent.add({ onDisable: function() {
xtype: 'menuseparator' deluge.sidebar.un('filtercreate', this.onFilterCreate);
}); deluge.sidebar.un('afterfiltercreate', this.onAfterFilterCreate);
delete Deluge.FilterPanel.templates.label;
this.deregisterTorrentStatus('label');
deluge.menus.torrent.remove(this.tmSep);
deluge.menus.torrent.remove(this.tm);
},
this.tm = deluge.menus.torrent.add({ onEnable: function() {
text: _('Label'), this.torrentMenu = new Ext.menu.Menu({
menu: this.torrentMenu items: [{
}); text: _('No Label'),
label: '',
handler: this.onTorrentMenuClick,
scope: this
}]
});
var lbltpl = '<div class="x-deluge-filter">' + this.tmSep = deluge.menus.torrent.add({
'<tpl if="filter">{filter}</tpl>' + xtype: 'menuseparator'
'<tpl if="!filter">No Label</tpl>' + });
' ({count})' +
'</div>';
if (deluge.sidebar.hasFilter('label')) { this.tm = deluge.menus.torrent.add({
var filter = deluge.sidebar.getFilter('label'); text: _('Label'),
filter.list.columns[0].tpl = new Ext.XTemplate(lbltpl); menu: this.torrentMenu
this.setFilter(filter); });
this.updateTorrentMenu(filter);
filter.list.refresh();
} else {
deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
deluge.sidebar.on('afterfiltercreate', this.onAfterFilterCreate, this);
Deluge.FilterPanel.templates.label = lbltpl;
}
this.registerTorrentStatus('label', _('Label'));
},
onAfterFilterCreate: function(sidebar, filter) { var lbltpl = '<div class="x-deluge-filter">' +
if (filter.filter != 'label') return; '<tpl if="filter">{filter}</tpl>' +
this.updateTorrentMenu(filter); '<tpl if="!filter">No Label</tpl>' +
}, ' ({count})' +
'</div>';
onFilterCreate: function(sidebar, filter) { if (deluge.sidebar.hasFilter('label')) {
if (filter.filter != 'label') return; var filter = deluge.sidebar.getFilter('label');
this.setFilter(filter); filter.list.columns[0].tpl = new Ext.XTemplate(lbltpl);
}, this.setFilter(filter);
this.updateTorrentMenu(filter);
filter.list.refresh();
} else {
deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
deluge.sidebar.on('afterfiltercreate', this.onAfterFilterCreate, this);
Deluge.FilterPanel.templates.label = lbltpl;
}
this.registerTorrentStatus('label', _('Label'));
},
onLabelAddClick: function() { onAfterFilterCreate: function(sidebar, filter) {
if (!this.addWindow) { if (filter.filter != 'label') return;
this.addWindow = new Deluge.ux.AddLabelWindow(); this.updateTorrentMenu(filter);
this.addWindow.on('labeladded', this.onLabelAdded, this); },
}
this.addWindow.show();
},
onLabelAdded: function(label) { onFilterCreate: function(sidebar, filter) {
this.torrentMenu.addMenuItem({ if (filter.filter != 'label') return;
text: label, this.setFilter(filter);
label: label, },
handler: this.onTorrentMenuClick,
scope: this
});
},
onLabelContextMenu: function(dv, i, node, e) { onLabelAddClick: function() {
e.preventDefault(); if (!this.addWindow) {
if (!this.labelMenu) this.createMenu(); this.addWindow = new Deluge.ux.AddLabelWindow();
var r = dv.getRecord(node); this.addWindow.on('labeladded', this.onLabelAdded, this);
if (dv.getRecord(node).get('filter')) { }
this.labelMenu.items.get(1).setDisabled(false); this.addWindow.show();
this.labelMenu.items.get(2).setDisabled(false); },
}
dv.select(i); onLabelAdded: function(label) {
this.labelMenu.showAt(e.getXY()); this.torrentMenu.addMenuItem({
}, text: label,
label: label,
handler: this.onTorrentMenuClick,
scope: this
});
},
onLabelHeaderContextMenu: function(e, t) { onLabelContextMenu: function(dv, i, node, e) {
e.preventDefault(); e.preventDefault();
if (!this.labelMenu) this.createMenu(); if (!this.labelMenu) this.createMenu();
this.labelMenu.items.get(1).setDisabled(true); var r = dv.getRecord(node);
this.labelMenu.items.get(2).setDisabled(true); if (dv.getRecord(node).get('filter')) {
this.labelMenu.showAt(e.getXY()); this.labelMenu.items.get(1).setDisabled(false);
}, this.labelMenu.items.get(2).setDisabled(false);
}
onLabelOptionsClick: function() { dv.select(i);
if (!this.labelOpts) this.labelOpts = new Deluge.ux.LabelOptionsWindow(); this.labelMenu.showAt(e.getXY());
this.labelOpts.show(this.filter.getState()); },
},
onLabelRemoveClick: function() { onLabelHeaderContextMenu: function(e, t) {
var state = this.filter.getState(); e.preventDefault();
deluge.client.label.remove(state, { if (!this.labelMenu) this.createMenu();
success: function() { this.labelMenu.items.get(1).setDisabled(true);
deluge.ui.update(); this.labelMenu.items.get(2).setDisabled(true);
this.torrentMenu.items.each(function(item) { this.labelMenu.showAt(e.getXY());
if (item.text != state) return; },
this.torrentMenu.remove(item);
var i = item;
}, this);
},
scope: this
});
},
onTorrentMenuClick: function(item, e) { onLabelOptionsClick: function() {
var ids = deluge.torrents.getSelectedIds(); if (!this.labelOpts) this.labelOpts = new Deluge.ux.LabelOptionsWindow();
Ext.each(ids, function(id, i) { this.labelOpts.show(this.filter.getState());
if (ids.length == i +1 ) { },
deluge.client.label.set_torrent(id, item.label, {
success: function() { onLabelRemoveClick: function() {
deluge.ui.update(); var state = this.filter.getState();
} deluge.client.label.remove(state, {
}); success: function() {
} else { deluge.ui.update();
deluge.client.label.set_torrent(id, item.label); this.torrentMenu.items.each(function(item) {
} if (item.text != state) return;
}); this.torrentMenu.remove(item);
} var i = item;
}, this);
},
scope: this
});
},
onTorrentMenuClick: function(item, e) {
var ids = deluge.torrents.getSelectedIds();
Ext.each(ids, function(id, i) {
if (ids.length == i +1 ) {
deluge.client.label.set_torrent(id, item.label, {
success: function() {
deluge.ui.update();
}
});
} else {
deluge.client.label.set_torrent(id, item.label);
}
});
}
}); });
Deluge.registerPlugin('Label', Deluge.plugins.LabelPlugin); Deluge.registerPlugin('Label', Deluge.plugins.LabelPlugin);