From 8095a2efaa6ce9c264c531a46dc3983012686457 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Fri, 21 Dec 2012 00:19:37 -0500 Subject: [PATCH] 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 Conflicts [permission numbering]: Open-ILS/src/sql/Pg/950.data.seed-values.sql --- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 4 +- .../upgrade/XXXX.data.server_addon_perms.sql | 17 ++++ Open-ILS/web/opac/locale/en-US/lang.dtd | 1 + .../chrome/content/OpenILS/global_util.js | 15 ++++ .../chrome/content/main/constants.js | 3 +- .../staff_client/chrome/content/main/menu.js | 10 +++ .../chrome/content/main/menu_frame_menus.xul | 4 + .../xul/staff_client/server/addon/addons.js | 83 +++++++++++++++++++ .../xul/staff_client/server/addon/addons.xul | 55 ++++++++++++ .../staff_client/server/addon/autoloader.js | 78 +++++++++++++++++ .../locale/en-US/addon/addons.properties | 6 ++ docs/RELEASE_NOTES_NEXT/xul_server_addons.txt | 12 +++ 12 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.server_addon_perms.sql create mode 100644 Open-ILS/xul/staff_client/server/addon/addons.js create mode 100644 Open-ILS/xul/staff_client/server/addon/addons.xul create mode 100644 Open-ILS/xul/staff_client/server/addon/autoloader.js create mode 100644 Open-ILS/xul/staff_client/server/locale/en-US/addon/addons.properties create mode 100644 docs/RELEASE_NOTES_NEXT/xul_server_addons.txt 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 8242492061..1ceb535978 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1607,7 +1607,9 @@ INSERT INTO permission.perm_list ( id, code, description ) VALUES 'Allows the user to check-in long-overdue items, prompting ' || 'long-overdue check-in processing', 'ppl', 'code')), ( 550, 'SET_CIRC_LONG_OVERDUE', oils_i18n_gettext(550, - 'Allows the user to mark a circulation as long-overdue', 'ppl', 'code')) + 'Allows the user to mark a circulation as long-overdue', 'ppl', 'code')), + ( 551, 'ADMIN_SERVER_ADDON_FOR_WORKSTATION', oils_i18n_gettext( 551, + '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..efbd6a4ae9 --- /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 ( + 551, + 'ADMIN_SERVER_ADDON_FOR_WORKSTATION', + oils_i18n_gettext( + 551, + '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 22496245ed..8a653fc74a 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -912,6 +912,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 fabe682c72..d1be18631d 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 @@ -643,3 +643,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 80748cac3b..95fa50f5df 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -517,5 +517,6 @@ 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' } 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 c461602a1b..c98b224d43 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -1747,6 +1747,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 647ad707fc..2fba991b37 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 @@ -360,6 +360,9 @@ /> + @@ -529,6 +532,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 @@ + + + + + + + + + + + + + +]> + + + + + + + + + + + + +