LP#1084758 store staff client tpac (etc) zoom pref
authorBill Erickson <berick@esilibrary.com>
Wed, 11 Sep 2013 17:49:07 +0000 (13:49 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 12 Sep 2013 17:39:25 +0000 (13:39 -0400)
Staff client pages loaded via browser.xul which have a name (via
internal XUL URL param) now have the ability to store and load a per-
page zoom value preference.  This includes (at minimum) the embedded
TPAC.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/xul/staff_client/chrome/content/util/browser.js
Open-ILS/xul/staff_client/chrome/content/util/browser.xul

index fb0078a..20cb4dc 100644 (file)
@@ -166,6 +166,39 @@ util.browser.prototype = {
         }
     },
 
         }
     },
 
+    /*
+     * If the browser page is given a name (e.g. the catalog is "Catalog") 
+     * and the user applies a zoom value (ctrl+ / ctrl-), store the value
+     * in the oils.util.browser.zoom.<name> pref.  On page load, if a value
+     * is set for the given page, load and apply the value to the page.
+     */
+    'apply_zoom' : function(val, delta) {
+        var name = xul_param('name');
+        if (!name) return;
+        var key = 'oils.util.browser.zoom.' + name; // pref key
+        var viewer = this.controller.view.browser_browser.markupDocumentViewer;
+
+        var prefs = Components.classes[
+            '@mozilla.org/preferences-service;1'].getService(
+                Components.interfaces['nsIPrefBranch']);
+
+        if (!val) {
+            if (delta) {
+                val = viewer.fullZoom;
+                val += delta
+            } else {
+                if (prefs.prefHasUserValue(key))
+                    val = prefs.getCharPref(key);
+            }
+        } 
+
+        val = Number(val);
+        if (!val || isNaN(val) || val < 0) return;
+
+        viewer.fullZoom = val;
+        prefs.setCharPref(key, ''+val);
+    },
+
     'reload' : function() {
         var obj = this;
         if (obj.lock_reload) {
     'reload' : function() {
         var obj = this;
         if (obj.lock_reload) {
@@ -465,6 +498,7 @@ util.browser.prototype = {
                                 var alert_string = 'document has stopped: ' + new Date() + '\n'; dump(alert_string);
                                 try {
                                     obj.push_variables(); obj.updateNavButtons();
                                 var alert_string = 'document has stopped: ' + new Date() + '\n'; dump(alert_string);
                                 try {
                                     obj.push_variables(); obj.updateNavButtons();
+                                    obj.apply_zoom();
                                 } catch(E) {
                                     var err_msg = 'browser.js STATE_IS_DOCUMENT STATE_STOP error with push_variables or updateNavButtons: ' + E + '\n';
                                     dump(err_msg);
                                 } catch(E) {
                                     var err_msg = 'browser.js STATE_IS_DOCUMENT STATE_STOP error with push_variables or updateNavButtons: ' + E + '\n';
                                     dump(err_msg);
index 616c63b..29ab51f 100644 (file)
         <command id="cmd_back" label="&common.browser.backward.label;" accesskey="&common.browser.backward.accesskey;" />
         <command id="cmd_reload" label="&common.browser.reload.label;" accesskey="&common.browser.reload.accesskey;" />
         <command id="cmd_forward" label="&common.browser.forward.label;" accesskey="&common.browser.forward.accesskey;" />
         <command id="cmd_back" label="&common.browser.backward.label;" accesskey="&common.browser.backward.accesskey;" />
         <command id="cmd_reload" label="&common.browser.reload.label;" accesskey="&common.browser.reload.accesskey;" />
         <command id="cmd_forward" label="&common.browser.forward.label;" accesskey="&common.browser.forward.accesskey;" />
-        <command id="cmd_zoom_in" oncommand="g.browser.controller.view.browser_browser.markupDocumentViewer.fullZoom += 0.1;" />
-        <command id="cmd_zoom_out" oncommand="g.browser.controller.view.browser_browser.markupDocumentViewer.fullZoom -= 0.1;" />
-        <command id="cmd_zoom_reset" oncommand="g.browser.controller.view.browser_browser.markupDocumentViewer.fullZoom = 1;" />
+        <command id="cmd_zoom_in" oncommand="g.browser.apply_zoom(null, 0.1);" />
+        <command id="cmd_zoom_out" oncommand="g.browser.apply_zoom(null, -0.1);" />
+        <command id="cmd_zoom_reset" oncommand="g.browser.apply_zoom(1);" />
     </commandset>
 
     <keyset>
     </commandset>
 
     <keyset>