From fee298bd3c58183fc0b5a70ed6cd9362813dbf6b Mon Sep 17 00:00:00 2001 From: phasefx Date: Thu, 3 Sep 2009 04:14:48 +0000 Subject: [PATCH] Replacing persist mechanism with oils_persist. This changeset isn't as scary as it looks, I promise. :-) In XUL you can say, and whenever those specified attributes change, the new values will be remembered the next time that element is loaded. Problems with persist: * No longer works with remote XUL in Xulrunner 1.9 series, only chrome. Mozilla did this for security reasons. * Persist was tied to the window.location of each interface, so: 1) Settings would be lost on any "upgrade" that effectively changed the URL. For example, /xul/rel_1_2/server/ versus /xul/rel_1_4/server/ 2) Some interfaces still make use of URL params, which effectively breaks persistance (because the URL changes constantly), and allows localstore.rdf to grow without limit (thanks to Jeff for noticing that last bit) The solution: * We renamed all occurances of @persist to @oils_persist, in case Mozilla changes the behavior again. * We created a persist_helper() function and call it alongside font_helper() in the @onload for most windows (all that currently have elements using @oils_persist, at least) persist_helper grabs all elements that have an @oils_persist, and constructs look-up keys based on the location.hostname, location.path, and element.id, and uses the Mozilla preference system to look for preferences with those keys. These keys don't include URL parameters. For elements, an event listener is added that will set the preference whenever the element fires a command event (is checked or unchecked). TODO: * Tweak the keys further so that they're BUILD_ID (version) agnostic * Add more event listeners to accomodate @oils_persist on other elements like window, splitter, and grippy. * Possibly remove persist_helper (and font_helper) from the inline @onload, and load it through a window.addEventListener('load',function(){ persist_helper(); },false); in the global util overlay instead. git-svn-id: svn://svn.open-ils.org/ILS/trunk@13953 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../chrome/content/OpenILS/global_util.js | 39 +++++++++++ .../chrome/content/circ/offline_checkin.xul | 6 +- .../chrome/content/circ/offline_checkout.xul | 8 +-- .../chrome/content/circ/offline_in_house_use.xul | 6 +- .../chrome/content/circ/offline_renew.xul | 8 +-- .../chrome/content/main/menu_frame.xul | 4 +- .../chrome/content/util/list_clipboard.xul | 4 +- .../xul/staff_client/server/cat/copy_buckets.xul | 2 +- .../staff_client/server/cat/copy_buckets_quick.xul | 2 +- .../xul/staff_client/server/cat/copy_editor.xul | 4 +- .../xul/staff_client/server/cat/copy_summary.xul | 4 +- Open-ILS/xul/staff_client/server/cat/marcedit.xul | 10 +-- .../xul/staff_client/server/cat/record_buckets.xul | 2 +- .../server/cat/record_buckets_overlay.xul | 2 +- .../server/cat/record_buckets_quick.xul | 2 +- .../xul/staff_client/server/cat/spine_labels.xul | 76 +++++++++++----------- .../xul/staff_client/server/cat/volume_editor.xul | 4 +- Open-ILS/xul/staff_client/server/cat/z3950.xul | 14 ++-- Open-ILS/xul/staff_client/server/circ/checkin.xul | 2 +- .../staff_client/server/circ/checkin_overlay.xul | 8 +-- Open-ILS/xul/staff_client/server/circ/checkout.xul | 2 +- .../staff_client/server/circ/checkout_overlay.xul | 4 +- .../xul/staff_client/server/circ/copy_details.xul | 4 +- .../xul/staff_client/server/circ/copy_status.xul | 2 +- .../server/circ/copy_status_overlay.xul | 4 +- .../xul/staff_client/server/circ/in_house_use.xul | 6 +- .../staff_client/server/patron/bill_history.xul | 10 +-- Open-ILS/xul/staff_client/server/patron/bills.xul | 2 +- .../staff_client/server/patron/bills_overlay.xul | 4 +- .../xul/staff_client/server/patron/display.xul | 2 +- .../staff_client/server/patron/display_horiz.xul | 2 +- .../server/patron/display_horiz_overlay.xul | 10 +-- .../staff_client/server/patron/display_overlay.xul | 10 +-- .../staff_client/server/patron/hold_details.xul | 12 ++-- .../staff_client/server/patron/hold_notices.xul | 10 +-- Open-ILS/xul/staff_client/server/patron/holds.xul | 2 +- .../staff_client/server/patron/holds_overlay.xul | 4 +- .../server/patron/standing_penalties.xul | 4 +- .../xul/staff_client/server/patron/summary.xul | 2 +- .../server/patron/summary_overlay_horiz.xul | 2 +- 40 files changed, 172 insertions(+), 133 deletions(-) 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 4cc94675c..56d7e597c 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 @@ -37,6 +37,45 @@ } } + function persist_helper() { + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']); + var nodes = document.getElementsByAttribute('oils_persist','*'); + for (var i = 0; i < nodes.length; i++) { + var base_key = 'oils_persist_' + String(location.hostname + location.pathname + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_'; + var attribute_list = nodes[i].getAttribute('oils_persist').split(' '); + for (var j = 0; j < attribute_list.length; j++) { + var key = base_key + attribute_list[j]; + var value = prefs.prefHasUserValue(key) ? prefs.getCharPref(key) : null; + dump('persist_helper: retrieving key = ' + key + ' value = ' + value + ' for ' + nodes[i].nodeName + '\n'); + if (value) nodes[i].setAttribute( attribute_list[j], value ); + } + if (nodes[i].nodeName == 'checkbox' && attribute_list.indexOf('checked') > -1) nodes[i].addEventListener( + 'command', + function(bk) { + return function(ev) { + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var key = bk + 'checked'; + var value = ev.target.checked; + ev.target.setAttribute( 'checked', value ); + prefs.setCharPref( key, value ); + dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox\n'); + } catch(E) { + alert('Error in persist_helper(), checkbox command event listener: ' + E); + } + }; + }(base_key), + false + ); + // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc. + } + } catch(E) { + alert('Error in persist_helper(): ' + E); + } + } + function getKeys(o) { var keys = []; for (var k in o) keys.push(k); diff --git a/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkin.xul b/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkin.xul index d19616d0b..8fa3bc47b 100644 --- a/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkin.xul +++ b/Open-ILS/xul/staff_client/chrome/content/circ/offline_checkin.xul @@ -16,7 +16,7 @@ @@ -50,7 +50,7 @@ &common.check_barcode.description; - +