mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-06 00:18:39 +00:00
rewrite the plugins page using the new get_plugins method in the web json api
update the grid when a Plugin{Dis|En}abledEvent occurs
This commit is contained in:
parent
037fbcaaa7
commit
2f49c5cfa7
1 changed files with 68 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Script: Deluge.Preferences.Plugins.js
|
Script: Deluge.Preferences.Plugins.js
|
||||||
The plugins preferences page.
|
The plugins preferences page.
|
||||||
|
|
||||||
Copyright:
|
Copyright:
|
||||||
(C) Damien Churchill 2009 <damoxc@gmail.com>
|
(C) Damien Churchill 2009 <damoxc@gmail.com>
|
||||||
|
@ -20,15 +20,15 @@ Copyright:
|
||||||
51 Franklin Street, Fifth Floor
|
51 Franklin Street, Fifth Floor
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
In addition, as a special exception, the copyright holders give
|
In addition, as a special exception, the copyright holders give
|
||||||
permission to link the code of portions of this program with the OpenSSL
|
permission to link the code of portions of this program with the OpenSSL
|
||||||
library.
|
library.
|
||||||
You must obey the GNU General Public License in all respects for all of
|
You must obey the GNU General Public License in all respects for all of
|
||||||
the code used other than OpenSSL. If you modify file(s) with this
|
the code used other than OpenSSL. If you modify file(s) with this
|
||||||
exception, you may extend this exception to your version of the file(s),
|
exception, you may extend this exception to your version of the file(s),
|
||||||
but you are not obligated to do so. If you do not wish to do so, delete
|
but you are not obligated to do so. If you do not wish to do so, delete
|
||||||
this exception statement from your version. If you delete this exception
|
this exception statement from your version. If you delete this exception
|
||||||
statement from all source files in the program, then also delete it here.
|
statement from all source files in the program, then also delete it here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Ext.namespace('Ext.deluge.preferences');
|
Ext.namespace('Ext.deluge.preferences');
|
||||||
|
@ -43,7 +43,7 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
}, config);
|
}, config);
|
||||||
Ext.deluge.preferences.Plugins.superclass.constructor.call(this, config);
|
Ext.deluge.preferences.Plugins.superclass.constructor.call(this, config);
|
||||||
},
|
},
|
||||||
|
|
||||||
pluginTemplate: new Ext.Template(
|
pluginTemplate: new Ext.Template(
|
||||||
'<dl class="singleline">' +
|
'<dl class="singleline">' +
|
||||||
'<dt>Author:</dt><dd>{author}</dd>' +
|
'<dt>Author:</dt><dd>{author}</dd>' +
|
||||||
|
@ -53,7 +53,7 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
'<dt>Details:</dt><dd>{details}</dd>' +
|
'<dt>Details:</dt><dd>{details}</dd>' +
|
||||||
'</dl>'
|
'</dl>'
|
||||||
),
|
),
|
||||||
|
|
||||||
initComponent: function() {
|
initComponent: function() {
|
||||||
Ext.deluge.preferences.Plugins.superclass.initComponent.call(this);
|
Ext.deluge.preferences.Plugins.superclass.initComponent.call(this);
|
||||||
this.defaultValues = {
|
this.defaultValues = {
|
||||||
|
@ -63,12 +63,12 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
'details': ''
|
'details': ''
|
||||||
};
|
};
|
||||||
this.pluginTemplate.compile();
|
this.pluginTemplate.compile();
|
||||||
|
|
||||||
var checkboxRenderer = function(v, p, record){
|
var checkboxRenderer = function(v, p, record){
|
||||||
p.css += ' x-grid3-check-col-td';
|
p.css += ' x-grid3-check-col-td';
|
||||||
return '<div class="x-grid3-check-col'+(v?'-on':'')+'"> </div>';
|
return '<div class="x-grid3-check-col'+(v?'-on':'')+'"> </div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.grid = this.add({
|
this.grid = this.add({
|
||||||
xtype: 'grid',
|
xtype: 'grid',
|
||||||
region: 'center',
|
region: 'center',
|
||||||
|
@ -112,11 +112,6 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
text: _('Install'),
|
text: _('Install'),
|
||||||
handler: this.onInstallPlugin,
|
handler: this.onInstallPlugin,
|
||||||
scope: this
|
scope: this
|
||||||
}, {
|
|
||||||
cls: 'x-btn-text-icon',
|
|
||||||
text: _('Rescan'),
|
|
||||||
handler: this.onRescanPlugins,
|
|
||||||
scope: this
|
|
||||||
}, '->', {
|
}, '->', {
|
||||||
cls: 'x-btn-text-icon',
|
cls: 'x-btn-text-icon',
|
||||||
text: _('Find More'),
|
text: _('Find More'),
|
||||||
|
@ -125,7 +120,7 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
var fieldset = this.add({
|
var fieldset = this.add({
|
||||||
xtype: 'fieldset',
|
xtype: 'fieldset',
|
||||||
border: false,
|
border: false,
|
||||||
|
@ -141,25 +136,48 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
style: 'margin-left: 10px'
|
style: 'margin-left: 10px'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('show', this.onShow, this);
|
this.on('show', this.onShow, this);
|
||||||
|
this.pluginInfo.on('render', this.onPluginInfoRender, this);
|
||||||
this.grid.on('cellclick', this.onCellClick, this);
|
this.grid.on('cellclick', this.onCellClick, this);
|
||||||
Deluge.Preferences.on('show', this.onPreferencesShow, this);
|
Deluge.Preferences.on('show', this.onPreferencesShow, this);
|
||||||
|
Deluge.Events.on('PluginDisabledEvent', this.onPluginDisabled, this);
|
||||||
|
Deluge.Events.on('PluginEnabledEvent', this.onPluginsEnabled, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
disablePlugin: function(plugin) {
|
disablePlugin: function(plugin) {
|
||||||
Deluge.Client.core.disable_plugin(plugin);
|
Deluge.Client.core.disable_plugin(plugin);
|
||||||
},
|
},
|
||||||
|
|
||||||
enablePlugin: function(plugin) {
|
enablePlugin: function(plugin) {
|
||||||
Deluge.Client.core.enable_plugin(plugin);
|
Deluge.Client.core.enable_plugin(plugin);
|
||||||
},
|
},
|
||||||
|
|
||||||
setInfo: function(plugin) {
|
setInfo: function(plugin) {
|
||||||
|
if (!this.pluginInfo.rendered) return;
|
||||||
var values = plugin || this.defaultValues;
|
var values = plugin || this.defaultValues;
|
||||||
this.pluginInfo.body.dom.innerHTML = this.pluginTemplate.apply(values);
|
this.pluginInfo.body.dom.innerHTML = this.pluginTemplate.apply(values);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updatePlugins: function() {
|
||||||
|
Deluge.Client.web.get_plugins({
|
||||||
|
success: this.onGotPlugins,
|
||||||
|
scope: this
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
updatePluginsGrid: function() {
|
||||||
|
var plugins = [];
|
||||||
|
Ext.each(this.availablePlugins, function(plugin) {
|
||||||
|
if (this.enabledPlugins.indexOf(plugin) > -1) {
|
||||||
|
plugins.push([true, plugin]);
|
||||||
|
} else {
|
||||||
|
plugins.push([false, plugin]);
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
this.grid.getStore().loadData(plugins);
|
||||||
|
},
|
||||||
|
|
||||||
onCellClick: function(grid, rowIndex, colIndex, e) {
|
onCellClick: function(grid, rowIndex, colIndex, e) {
|
||||||
if (colIndex != 0) return;
|
if (colIndex != 0) return;
|
||||||
var r = grid.getStore().getAt(rowIndex);
|
var r = grid.getStore().getAt(rowIndex);
|
||||||
|
@ -171,23 +189,18 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
this.disablePlugin(r.get('plugin'));
|
this.disablePlugin(r.get('plugin'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onFindMorePlugins: function() {
|
onFindMorePlugins: function() {
|
||||||
window.open('http://dev.deluge-torrent.org/wiki/Plugins');
|
window.open('http://dev.deluge-torrent.org/wiki/Plugins');
|
||||||
},
|
},
|
||||||
|
|
||||||
onGotAvailablePlugins: function(plugins) {
|
onGotPlugins: function(plugins) {
|
||||||
this.availablePlugins = plugins;
|
this.enabledPlugins = plugins.enabled_plugins;
|
||||||
Deluge.Client.core.get_enabled_plugins({
|
this.availablePlugins = plugins.available_plugins;
|
||||||
success: this.onGotEnabledPlugins,
|
this.setInfo();
|
||||||
scope: this
|
this.updatePluginsGrid();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onGotEnabledPlugins: function(plugins) {
|
|
||||||
this.enabledPlugins = plugins;
|
|
||||||
},
|
|
||||||
|
|
||||||
onGotPluginInfo: function(info) {
|
onGotPluginInfo: function(info) {
|
||||||
var values = {
|
var values = {
|
||||||
author: info['Author'],
|
author: info['Author'],
|
||||||
|
@ -199,33 +212,34 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||||
this.setInfo(values);
|
this.setInfo(values);
|
||||||
delete info;
|
delete info;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onPluginEnabled: function(pluginName) {
|
||||||
|
var index = this.grid.getStore().find('plugin', pluginName);
|
||||||
|
var plugin = this.grid.getStore().getAt(index);
|
||||||
|
plugin.set('enabled', true);
|
||||||
|
plugin.commit();
|
||||||
|
},
|
||||||
|
|
||||||
|
onPluginDisabled: function(pluginName) {
|
||||||
|
var index = this.grid.getStore().find('plugin', pluginName);
|
||||||
|
var plugin = this.grid.getStore().getAt(index);
|
||||||
|
plugin.set('enabled', false);
|
||||||
|
plugin.commit();
|
||||||
|
},
|
||||||
|
|
||||||
onPluginSelect: function(selmodel, rowIndex, r) {
|
onPluginSelect: function(selmodel, rowIndex, r) {
|
||||||
Deluge.Client.web.get_plugin_info(r.get('plugin'), {
|
Deluge.Client.web.get_plugin_info(r.get('plugin'), {
|
||||||
success: this.onGotPluginInfo,
|
success: this.onGotPluginInfo,
|
||||||
scope: this
|
scope: this
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onPreferencesShow: function() {
|
onPreferencesShow: function() {
|
||||||
Deluge.Client.core.get_available_plugins({
|
this.updatePlugins();
|
||||||
success: this.onGotAvailablePlugins,
|
|
||||||
scope: this
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onPluginInfoRender: function(ct, position) {
|
||||||
Ext.deluge.preferences.Plugins.superclass.onShow.call(this);
|
|
||||||
this.setInfo();
|
this.setInfo();
|
||||||
var plugins = [];
|
|
||||||
Ext.each(this.availablePlugins, function(plugin) {
|
|
||||||
if (this.enabledPlugins.indexOf(plugin) > -1) {
|
|
||||||
plugins.push([true, plugin]);
|
|
||||||
} else {
|
|
||||||
plugins.push([false, plugin]);
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
this.grid.getStore().loadData(plugins);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Deluge.Preferences.addPage(new Ext.deluge.preferences.Plugins());
|
Deluge.Preferences.addPage(new Ext.deluge.preferences.Plugins());
|
Loading…
Add table
Add a link
Reference in a new issue