diff --git a/deluge/ui/web/js/Deluge.Preferences.js b/deluge/ui/web/js/Deluge.Preferences.js index 5db73ae4e..47de722f3 100644 --- a/deluge/ui/web/js/Deluge.Preferences.js +++ b/deluge/ui/web/js/Deluge.Preferences.js @@ -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]; }, /** diff --git a/deluge/ui/web/js/Deluge.UI.js b/deluge/ui/web/js/Deluge.UI.js index 170093d14..3d5f4ad5c 100644 --- a/deluge/ui/web/js/Deluge.UI.js +++ b/deluge/ui/web/js/Deluge.UI.js @@ -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(); }, /** diff --git a/deluge/ui/web/js/ext-extensions-debug.js b/deluge/ui/web/js/ext-extensions-debug.js index 1270308f2..b7df07ecd 100644 --- a/deluge/ui/web/js/ext-extensions-debug.js +++ b/deluge/ui/web/js/ext-extensions-debug.js @@ -993,4 +993,42 @@ Ext.override(Ext.form.TriggerField, { actionMode: 'wrap', onShow: Ext.form.TriggerField.superclass.onShow, onHide: Ext.form.TriggerField.superclass.onHide -}); \ No newline at end of file +}); + +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); +} \ No newline at end of file