Allow staff to pick search/pref libraries
authorThomas Berezansky <tsbere@mvlc.org>
Thu, 20 Sep 2012 18:33:41 +0000 (14:33 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 17 Oct 2012 01:09:32 +0000 (21:09 -0400)
This adds a workstation-level set of settings for search and preferred
libraries. These override the default search library and the preferred
library individually, allowing staff to default searching at one OU but
still get copy information for a different one.

Original use case is "search everywhere, but show my local copies".

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/pref_lib_display.tt2
Open-ILS/web/opac/locale/en-US/lang.dtd
Open-ILS/xul/staff_client/chrome/content/main/constants.js
Open-ILS/xul/staff_client/chrome/content/main/main.js
Open-ILS/xul/staff_client/chrome/content/main/menu.js
Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul
Open-ILS/xul/staff_client/chrome/content/main/search_prefs.xul [new file with mode: 0644]
Open-ILS/xul/staff_client/components/oils_protocol.js

index 470e381..4dc5ea0 100644 (file)
@@ -378,6 +378,10 @@ sub _get_search_lib {
     $loc = $self->cgi->param('loc');
     return $loc if $loc;
 
+    if ($self->apache->headers_in->get('OILS-Search-Lib')) {
+        return $self->apache->headers_in->get('OILS-Search-Lib');
+    }
+
     my $pref_lib = $self->_get_pref_lib();
     return $pref_lib if $pref_lib;
 
@@ -392,6 +396,10 @@ sub _get_pref_lib {
     my $plib = $self->cgi->param('plib');
     return $plib if $plib;
 
+    if ($self->apache->headers_in->get('OILS-Pref-Lib')) {
+        return $self->apache->headers_in->get('OILS-Pref-Lib');
+    }
+
     if ($ctx->{user}) {
         # See if the user has a search library preference
         my $lset = $self->editor->search_actor_user_setting({
index 635c766..d8c9856 100644 (file)
@@ -1,7 +1,7 @@
 [%- IF ctx.pref_ou && ctx.pref_ou != ctx.search_ou; %]
 <span class="preflib">[%
     l('Preferred library: [_1][_2][_3]', '<b>', ctx.get_aou(ctx.pref_ou).name, '</b>');
-    %]<a href="[% mkurl(ctx.opac_root _ '/myopac/prefs_settings')
-    %]" class="preflib_change" title="[% l("Change preferred library"); %]">[% l('?') %]</a>
+    IF NOT ctx.is_staff %]<a href="[% mkurl(ctx.opac_root _ '/myopac/prefs_settings')
+    %]" class="preflib_change" title="[% l("Change preferred library"); %]">[% l('?') %]</a>[% END; %]
 </span>
 [%- END; %]
index 055f2e3..ce9e816 100644 (file)
 <!ENTITY staff.main.menu.admin.client.hotkeys.setworkstation.accesskey "">
 <!ENTITY staff.main.menu.admin.client.hotkeys.clearworkstation.label "Clear Workstation Default">
 <!ENTITY staff.main.menu.admin.client.hotkeys.clearworkstation.accesskey "">
+<!ENTITY staff.main.menu.admin.client.search_prefs.label "Set Search Preferences">
 <!ENTITY staff.main.menu.admin.client.toolbars "Toolbars">
 <!ENTITY staff.main.menu.admin.client.toolbars.current "Current">
 <!ENTITY staff.main.menu.admin.client.toolbars.config.label "Configure Toolbars">
 <!ENTITY staff.item.batch.hold.cancel_btn.label "Cancel">
 <!ENTITY staff.item.batch.hold.cancel_btn.accesskey "C">
 <!ENTITY staff.item.batch.hold.failures_and_settings "The settings above may be changed for retries and overrides.">
+<!ENTITY staff.search_prefs.search_lib.caption "Default Search Library">
+<!ENTITY staff.search_prefs.search_lib.description "The default search library setting determines what library is searched from the advanced search screen and portal page by default. Manual selection of a search library will override it. One recommendation is to set the search library to the highest point you would normally want to search.">
+<!ENTITY staff.search_prefs.pref_lib.caption "Preferred Library">
+<!ENTITY staff.search_prefs.pref_lib.description "The preferred library is used to show copies and URIs regardless of the library searched. One recommendation is to set this to your workstation library so that local copies show up first in search results.">
+<!ENTITY staff.search_prefs.save.label "Save">
+<!ENTITY staff.search_prefs.save.accesskey "S">
+<!ENTITY staff.search_prefs.saved_message "Preferences saved">
index d3eb6e2..8ec44a8 100644 (file)
@@ -522,7 +522,8 @@ var urls = {
     'ALT_HOLDS_PRINT' : 'oils://remote/opac/extras/circ/alt_holds_print.html',
     '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'
+    'EG_TRIGGER_EVENTS' : 'oils://remote/eg/actor/user/event_log',
+    'XUL_SEARCH_PREFS' : 'chrome://open_ils_staff_client/content/main/search_prefs.xul'
 }
 
 if(use_tpac) {
index c131bbe..53d8b87 100644 (file)
@@ -376,6 +376,15 @@ function main_init() {
             var url = G.auth.controller.view.server_prompt.value.match(/^[^\/]*/).toString() || urls.remote;
 
             G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
+            try {
+                G.data.search_lib = G.pref.getIntPref('open-ils.' + url + '.search_lib');
+                G.data.pref_lib = G.pref.getIntPref('open-ils.' + url + '.pref_lib');
+            } catch(E) {
+                G.data.search_lib = null;
+                G.data.pref_lib = null;
+            }
+            G.data.stash('search_lib');
+            G.data.stash('pref_lib');
 
             if (! url.match( '^(http|https)://' ) ) { url = 'http://' + url; }
 
index 55a3682..3214918 100644 (file)
@@ -1664,6 +1664,16 @@ main.menu.prototype = {
                     xulG.pref.setBoolPref('oils.copy_editor.copy_location_name_first', !curvalue);
                 }
             ],
+            'cmd_search_prefs' : [
+                ['oncommand'],
+                function() {
+                    try {
+                        obj.set_tab(obj.url_prefix('XUL_SEARCH_PREFS'));
+                    } catch(E) {
+                        alert(E)
+                    }
+                }
+            ],
         };
 
         JSAN.use('util.controller');
index 70128a9..58caf07 100644 (file)
              perm="DEBUG_CLIENT"
              />
     <command id="cmd_copy_editor_copy_location_first_toggle" />
+    <command id="cmd_search_prefs" />
 </commandset>
 
 <!-- The File menu on the main menu -->
                 <menuitem label="&staff.server.admin.index.printer;" command="cmd_local_admin_printer"/>
                 <menuitem label="&staff.main.menu.admin.template_edit.label;" accesskey="&staff.main.menu.admin.template_edit.accesskey;" command="cmd_print_list_template_edit"/>
                 <menuitem label="&staff.server.admin.index.fonts_and_sounds;" command="cmd_local_admin_fonts_and_sounds"/>
+                <menuitem label="&staff.main.menu.admin.client.search_prefs.label;" command="cmd_search_prefs"/>
                 <menuitem type="checkbox" label="&staff.main.menu.admin.client.copy_editor.copy_location.label;" command="cmd_copy_editor_copy_location_first_toggle"/>
                 <menu id="main.menu.admin.client.hotkeys" label="&staff.main.menu.admin.client.hotkeys;">
                     <menupopup id="main.menu.admin.client.hotkeys.popup">
diff --git a/Open-ILS/xul/staff_client/chrome/content/main/search_prefs.xul b/Open-ILS/xul/staff_client/chrome/content/main/search_prefs.xul
new file mode 100644 (file)
index 0000000..c36c7eb
--- /dev/null
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<!-- Application: Evergreen Staff Client -->
+<!-- Screen: Workstation level search preferences -->
+<!--
+ vim:noet:sw=4:ts=4:
+-->
+
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+<?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
+
+<!DOCTYPE window SYSTEM "chrome://open_ils_staff_client/locale/lang.dtd">
+
+<?xul-overlay href="chrome://open_ils_staff_client/content/OpenILS/util_overlay_chrome.xul"?>
+
+<window id="search_prefs_diag" 
+    onload="try { my_init(); } catch(E) { alert(E); }"
+    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+    <script type="text/javascript">
+        var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true;
+    </script>
+    <scripts id="openils_util_scripts"/>
+    <script type="text/javascript" src="JSAN.js"/>
+
+    <script>
+    <![CDATA[
+        var g = {};
+        var search_lib_box;
+        var pref_lib_box;
+        var prefSvc;
+        var data;
+        var saved_message;
+        function my_init() {
+            JSAN.use('OpenILS.data');
+            data = new OpenILS.data();
+            data.init({'via':'stash'});
+            search_lib_box = document.getElementById('search_lib');
+            pref_lib_box = document.getElementById('pref_lib');
+            // NOTE: If this ever deals with custom trees, this is where you likely want to mess with things.
+            add_aou(data.tree.aou, '');
+            prefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).QueryInterface(Components.interfaces.nsIPrefBranch2);
+            saved_message = document.getElementById('saved_message').textContent;
+            if (data.search_lib) {
+                search_lib_box.value = data.search_lib;
+                pref_lib_box.value = data.pref_lib;
+            } else {
+                search_lib_box.selectedIndex = 0;
+                pref_lib_box.selectedIndex = 0;;
+            }
+        }
+        function add_aou(aou, depth) {
+            search_lib_box.appendItem(depth + aou.name(), aou.id(), '');
+            pref_lib_box.appendItem(depth + aou.name(), aou.id(), '');
+            for(var i = 0; i < aou.children().length; i++)
+                add_aou(aou.children()[i], depth + '  ');
+        }
+        function update_prefs() {
+            prefSvc.setIntPref('open-ils.' + data.server_unadorned + '.search_lib', search_lib_box.value);
+            prefSvc.setIntPref('open-ils.' + data.server_unadorned + '.pref_lib', pref_lib_box.value);
+            data.search_lib = search_lib_box.value;
+            data.pref_lib = pref_lib_box.value;
+            data.stash('search_lib');
+            data.stash('pref_lib');
+            alert(saved_message);
+        }
+    ]]>
+    </script>
+    <commandset id="search_prefs_cmds">
+        <command id="save_search_prefs" oncommand="update_prefs()" />
+    </commandset>
+    <vbox id="search_prefs_main">
+        <groupbox>
+            <caption label="&staff.search_prefs.search_lib.caption;"/>
+            <description>&staff.search_prefs.search_lib.description;</description>
+            <menulist id="search_lib">
+                <menupopup>
+                </menupopup>
+            </menulist>
+        </groupbox>
+        <groupbox>
+            <caption label="&staff.search_prefs.pref_lib.caption;"/>
+            <description>&staff.search_prefs.pref_lib.description;</description>
+            <menulist id="pref_lib">
+                <menupopup>
+                </menupopup>
+            </menulist>
+        </groupbox>
+        <button id="save_button" command="save_search_prefs" label="&staff.search_prefs.save.label;" accesskey="&staff.search_prefs.save.accesskey;"/>
+    </vbox>
+    <description id="saved_message" style="display:none">&staff.search_prefs.saved_message;</description>
+</window>
index d986aa8..27a2356 100644 (file)
@@ -192,9 +192,9 @@ oilsProtocol.prototype = {
     newChannel: function(aURI) {
         var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
         var host;
+        var data_cache = Components.classes["@open-ils.org/openils_data_cache;1"].getService().wrappedJSObject.data;
         switch(aURI.host) {
             case 'remote':
-                var data_cache = Components.classes["@open-ils.org/openils_data_cache;1"].getService().wrappedJSObject.data;
                 host = data_cache.server_unadorned;
                 break;
             case 'selfcheck':
@@ -208,7 +208,12 @@ oilsProtocol.prototype = {
             return ios.newChannel("about:blank", null, null); // Bad input. Not really sure what to do. Returning a dummy channel does prevent a crash, though!
         var chunk = aURI.spec.replace(/^oils:\/\/[^\/]*\//,'');
         var channel = ios.newChannel("https://" + host + "/" + chunk, null, null).QueryInterface(Components.interfaces.nsIHttpChannel);
-        channel.QueryInterface(Components.interfaces.nsIHttpChannel).setRequestHeader("OILS-Wrapper", "true", false);
+        channel.setRequestHeader("OILS-Wrapper", "true", false);
+        // If we have a search/pref lib, set them too!
+        if (data_cache.search_lib && data_cache.search_lib != null)
+            channel.setRequestHeader("OILS-Search-Lib", data_cache.search_lib, false);
+        if (data_cache.pref_lib && data_cache.pref_lib != null)
+            channel.setRequestHeader("OILS-Pref-Lib", data_cache.pref_lib, false);
         if(this._system_principal == null) {
             // We don't have the owner?
             var chrome_service = Components.classesByID['{61ba33c0-3031-11d3-8cd0-0060b0fc14a3}'].getService().QueryInterface(Components.interfaces.nsIProtocolHandler);