From: Jason Etheridge Date: Fri, 21 Dec 2012 05:19:37 +0000 (-0500) Subject: JSAN module autoloader for "add-ons" X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=28134361e874efa82823ad776a7c914b428c6b16;p=working%2FEvergreen.git JSAN module autoloader for "add-ons" This adds a "Server Add-ons" menu entry under Admin -> Workstation Administration in the staff client. Choosing this allows you to edit or set a list of identifiers that correspond to JSAN-style modules found in /server/addons/, and is meant mainly for activating 3rd party modules within the staff client on a per-workstation basis. You need the ADMIN_SERVER_ADDON_FOR_WORKSTATION permission to use it. Configuration options for activated add-ons may also show up in this interface. More technical details: This Server Add-ons list is stored as a JSON array in the Mozilla preference 'oils.addon.autoload.list'. We also add an addon.autoloader module that gets called in most XUL interfaces via the util_overlay file. This autoloader will loop through the modules specified in 'oils.addon.autoload.list' and instantiate each, storing a reference to each of the newly created objects in a data structure in window.oils_autoloaded. So, as an example, let's say there is a module: /xul/server/addon/uber_scan.js And we have the identifier 'uber_scan' in our Server Add-ons list. Then, on every page load of a XUL interface using the stock util overlay, we will effectively call: new addon.uber_scan(); Causing the code in the module to execute. It is up to the module to determine whether it needs to do anything within a given interface. Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index af1a771633..6a1898c8fe 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -87,7 +87,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0757', :eg_version); -- tsbere/senator +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('XXXX', :eg_version); -- phasefx CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 4381559535..e0fecaf1ae 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1583,8 +1583,8 @@ INSERT INTO permission.perm_list ( id, code, description ) VALUES 'Allows a user to configure URL verification org unit settings', 'ppl', 'description')), ( 545, 'SAVED_FILTER_DIALOG_FILTERS', oils_i18n_gettext( 545, 'Allows users to save and load sets of filters for filter dialogs, available in certain staff interfaces', 'ppl', 'description')) - - + ,( 546, 'ADMIN_SERVER_ADDON_FOR_WORKSTATION', oils_i18n_gettext( 546, + 'Allows a user to specify which Server Add-ons get invoked at the current workstation', 'ppl', 'description')) ; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.server_addon_perms.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.server_addon_perms.sql new file mode 100644 index 0000000000..2c1a5f58d3 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.server_addon_perms.sql @@ -0,0 +1,17 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +INSERT INTO permission.perm_list ( id, code, description ) VALUES ( + 546, + 'ADMIN_SERVER_ADDON_FOR_WORKSTATION', + oils_i18n_gettext( + 546, + 'Allows a user to specify which Server Add-ons get invoked at the current workstation', + 'ppl', + 'description' + ) +); + +COMMIT; + diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index e0cb546b9a..a2eadb9488 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -880,6 +880,7 @@ + diff --git a/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js b/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js index 09c8671cec..57d735ec92 100644 --- a/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js +++ b/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js @@ -634,3 +634,18 @@ alert('Error in global_utils.js, widget_prompt(): ' + E); } } + + + window.addEventListener( + 'load', + function(ev) { + try { + if (window.oils_autoloaded) { return; } + JSAN.use('addon.autoloader'); + window.oils_autoloaded = new addon.autoloader(); + } catch(E) { + dump('Error in global_util.js with addon.autoloader: ' + E + '\n'); + } + }, + false + ); diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index 8ec44a8fe3..17c1e76ff6 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -523,7 +523,8 @@ var urls = { 'SERIAL_PRINT_ROUTING_LIST_USERS' : 'oils://remote/eg/serial/print_routing_list_users', 'XUL_SERIAL_BATCH_RECEIVE': 'oils://remote/xul/server/serial/batch_receive.xul', 'EG_TRIGGER_EVENTS' : 'oils://remote/eg/actor/user/event_log', - 'XUL_SEARCH_PREFS' : 'chrome://open_ils_staff_client/content/main/search_prefs.xul' + 'XUL_SEARCH_PREFS' : 'chrome://open_ils_staff_client/content/main/search_prefs.xul', + 'XUL_SERVER_ADDONS' : 'oils://remote/xul/server/addon/addons.xul' } if(use_tpac) { diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index 04a91f5e7b..a815094d92 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -1721,6 +1721,16 @@ main.menu.prototype = { } } ], + 'cmd_server_addon_ws_configure' : [ + ['oncommand'], + function() { + try { + obj.set_tab(obj.url_prefix('XUL_SERVER_ADDONS'),{'browser' : false}); + } catch(E) { + alert(E); + } + } + ] }; JSAN.use('util.controller'); diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul index 8967f9c2a3..82ab733a15 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul @@ -347,6 +347,9 @@ /> + @@ -516,6 +519,7 @@ + diff --git a/Open-ILS/xul/staff_client/server/addon/addons.js b/Open-ILS/xul/staff_client/server/addon/addons.js new file mode 100644 index 0000000000..3824c0f7ab --- /dev/null +++ b/Open-ILS/xul/staff_client/server/addon/addons.js @@ -0,0 +1,83 @@ +var error; +var g = { 'addons_ui' : true }; +var prefs; + +function my_init() { + try { + if (typeof JSAN == 'undefined') { + throw( "The JSAN library object is missing."); } + JSAN.errorLevel = "die"; // none, warn, or die + JSAN.addRepository('/xul/server/'); + JSAN.use('util.error'); error = new util.error(); + error.sdump('D_TRACE','my_init() for addon/addon.xul'); + + if (typeof window.xulG == 'object' + && typeof window.xulG.set_tab_name == 'function') { + try { + window.xulG.set_tab_name( + $('addonStrings').getString('addons.tab.label') + ); + } catch(E) { + alert(E); + } + } + + const Cc = Components.classes; + const Ci = Components.interfaces; + const prefs_Cc = '@mozilla.org/preferences-service;1'; + prefs = Cc[prefs_Cc].getService(Ci['nsIPrefBranch']); + + var addons = JSON2js( + pref.prefHasUserValue('oils.addon.autoload.list') + ? pref.getCharPref('oils.addon.autoload.list') + : '[]' + ); + + $('addonlist_tb').value = addons.join("\n"); + + $('addonlist_desc').textContent = $('addonStrings').getString( + 'addons.list.desc'); + // Why messagecat instead of lang.dtd here? Mostly as an example for add-ons + // that won't have access to lang.dtd + + $('addonlist_caption').setAttribute('label',$('addonStrings').getString( + 'addons.list.caption')); + + $('addonlist_save_btn').setAttribute( + 'label', $('addonStrings').getString( + 'addons.list.update_btn.label')); + + $('addonlist_save_btn').setAttribute( + 'accesskey', $('addonStrings').getString( + 'addons.list.update_btn.accesskey')); + + $('addonpref_caption').setAttribute('label',$('addonStrings').getString( + 'addons.pref.caption')); + + } catch(E) { + alert('Error in addons.js, my_init(): ' + E); + } +} + +function update() { + try { + JSAN.use('util.functional'); + var addon_string = $('addonlist_tb').value.replace(' ','','g'); + var addons = util.functional.filter_list( + addon_string.split("\n"), + function(s) { + return s != ''; // filtering out empty lines + } + ); + + pref.setCharPref( + 'oils.addon.autoload.list', + js2JSON(addons) + ); + + location.href = location.href; + + } catch(E) { + alert('Error in addons.js, update(): ' + E); + } +} diff --git a/Open-ILS/xul/staff_client/server/addon/addons.xul b/Open-ILS/xul/staff_client/server/addon/addons.xul new file mode 100644 index 0000000000..8e8e5ca5db --- /dev/null +++ b/Open-ILS/xul/staff_client/server/addon/addons.xul @@ -0,0 +1,55 @@ + + + + + + + + + + + + + +]> + + + + + + + + + + + + +