add a working javascript loader

implement the core code for disabling/enabling plugins on the fly
This commit is contained in:
Damien Churchill 2009-09-16 09:02:26 +00:00
parent b2390b8ff4
commit e4fb98bd02
3 changed files with 67 additions and 4 deletions

View file

@ -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];
},
/**

View file

@ -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();
},
/**

View file

@ -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);
}