mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-20 19:44:52 +00:00
add a working javascript loader
implement the core code for disabling/enabling plugins on the fly
This commit is contained in:
parent
b2390b8ff4
commit
e4fb98bd02
3 changed files with 67 additions and 4 deletions
|
@ -129,6 +129,19 @@ Ext.deluge.PreferencesWindow = Ext.extend(Ext.Window, {
|
|||
store.loadData([[name]], true);
|
||||
page['bodyStyle'] = 'margin: 5px';
|
||||
this.pages[name] = this.configPanel.add(page);
|
||||
return this.pages[name];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a preferences page from the window.
|
||||
* @param {mixed} name
|
||||
*/
|
||||
removePage: function(page) {
|
||||
var name = page.title;
|
||||
var store = this.categoriesGrid.getStore();
|
||||
store.removeAt(store.find('name', name));
|
||||
this.configPanel.remove(page);
|
||||
delete this.pages[page.title];
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -162,14 +162,26 @@ Deluge.UI = {
|
|||
},
|
||||
|
||||
onGotPluginResources: function(resources) {
|
||||
var scripts = (Deluge.debug) ? resources['debug_scripts'] : resources['scripts'];
|
||||
var scripts = (Deluge.debug) ? resources.debug_scripts : resources.scripts;
|
||||
Ext.each(scripts, function(script) {
|
||||
|
||||
Ext.ux.JSLoader({
|
||||
url: script,
|
||||
onLoad: this.onPluginLoaded,
|
||||
pluginName: resources.name
|
||||
});
|
||||
}, this);
|
||||
},
|
||||
|
||||
onPluginDisabled: function(pluginName) {
|
||||
//alert('D: ' + pluginName);
|
||||
Deluge.Plugins[pluginName].disable();
|
||||
},
|
||||
|
||||
onPluginLoaded: function(options) {
|
||||
// This could happen if the plugin has multiple scripts
|
||||
if (!Deluge.Plugins[options.pluginName]) return;
|
||||
|
||||
// Enable the plugin
|
||||
Deluge.Plugins[options.pluginName].enable();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -993,4 +993,42 @@ Ext.override(Ext.form.TriggerField, {
|
|||
actionMode: 'wrap',
|
||||
onShow: Ext.form.TriggerField.superclass.onShow,
|
||||
onHide: Ext.form.TriggerField.superclass.onHide
|
||||
});
|
||||
});
|
||||
|
||||
Ext.ux.JSLoader = function(options) {
|
||||
Ext.ux.JSLoader.scripts[++Ext.ux.JSLoader.index] = {
|
||||
url: options.url,
|
||||
success: true,
|
||||
jsLoadObj: null,
|
||||
options: options,
|
||||
onLoad: options.onLoad || Ext.emptyFn,
|
||||
onError: options.onError || Ext.ux.JSLoader.stdError,
|
||||
scope: options.scope || this
|
||||
};
|
||||
|
||||
Ext.Ajax.request({
|
||||
url: options.url,
|
||||
scriptIndex: Ext.ux.JSLoader.index,
|
||||
success: function(response, options) {
|
||||
var script = Ext.ux.JSLoader.scripts[options.scriptIndex];
|
||||
try {
|
||||
eval(response.responseText);
|
||||
} catch(e) {
|
||||
script.success = false;
|
||||
script.onError(script.options, e);
|
||||
}
|
||||
if (script.success) script.onLoad.call(script.scope, script.options);
|
||||
},
|
||||
failure: function(response, options) {
|
||||
var script = Ext.ux.JSLoader.scripts[options.scriptIndex];
|
||||
script.success = false;
|
||||
script.onError(script.options, response.status);
|
||||
}
|
||||
});
|
||||
}
|
||||
Ext.ux.JSLoader.index = 0;
|
||||
Ext.ux.JSLoader.scripts = [];
|
||||
Ext.ux.JSLoader.stdError = function(options, e) {
|
||||
// throw(e);
|
||||
window.alert('Error loading script:\n\n' + options.url + '\n\nstatus: ' + e);
|
||||
}
|
Loading…
Add table
Reference in a new issue