staff client locale switcher and minor tweaks
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 13 Nov 2008 20:05:09 +0000 (20:05 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 13 Nov 2008 20:05:09 +0000 (20:05 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11169 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/locale/en-US/lang.dtd
Open-ILS/xul/staff_client/chrome/content/auth/controller.js
Open-ILS/xul/staff_client/chrome/content/main/main.js
Open-ILS/xul/staff_client/chrome/content/main/main.xul
Open-ILS/xul/staff_client/chrome/content/util/mozilla.js [new file with mode: 0644]
Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties

index 4e146cb..008b40b 100644 (file)
 <!ENTITY staff.auth.quit_prompt.key "x">
 <!ENTITY staff.auth.submit_prompt "Submit">
 <!ENTITY staff.auth.submit_prompt.key "S">
-<!ENTITY staff.auth.title "Evergreen Staff Client 3">
-<!ENTITY staff.auth.version "Evergreen 0.1.0 20051202">
+<!ENTITY staff.auth.title "Evergreen Staff Client">
+<!ENTITY staff.auth.about_btn.label "About this client...">
+<!ENTITY staff.auth.about_btn.accesskey "">
+<!ENTITY staff.auth.new_window_btn.label "Open New Window">
+<!ENTITY staff.auth.new_window_btn.accesskey "N">
+<!ENTITY staff.auth.locale.label "Locale:">
+<!ENTITY staff.auth.locale.accesskey "e">
+<!ENTITY staff.auth.apply_locale_btn.label "Apply Locale">
+<!ENTITY staff.auth.apply_locale_btn.accesskey "A">
 <!ENTITY staff.auth.verify.caption "Verify Credentials">
 <!ENTITY staff.auth.verify.submit.label "Verify">
 <!ENTITY staff.auth.verify.submit.accesskey "V">
index 784c878..c0c9df3 100644 (file)
@@ -131,6 +131,10 @@ auth.controller.prototype = {
                                                ['render'],
                                                function(e) { return function() {} }
                                        ],
+                                       'apply_locale_btn' : [
+                                               ['render'],
+                                               function(e) { return function() {} }
+                                       ],
                                        'progress_bar' : [
                                                ['render'],
                                                function(e) { return function() {} }
@@ -369,6 +373,7 @@ auth.controller.prototype = {
                this.controller.view.name_prompt.disabled = true;
                this.controller.view.password_prompt.disabled = true;
                this.controller.view.submit_button.disabled = true;
+               this.controller.view.apply_locale_btn.disabled = true;
                XML_HTTP_SERVER = this.controller.view.server_prompt.value;
 
                try {
@@ -458,6 +463,7 @@ auth.controller.prototype = {
                this.controller.view.progress_bar.value = 0; 
                this.controller.view.progress_bar.setAttribute('real','0.0');
                this.controller.view.submit_button.disabled = false;
+               this.controller.view.apply_locale_btn.disabled = false;
                this.controller.view.password_prompt.disabled = false;
                this.controller.view.password_prompt.value = '';
                this.controller.view.name_prompt.disabled = false;
index aa3c635..da357b7 100644 (file)
@@ -236,10 +236,7 @@ function main_init() {
                        document.getElementById('debug_gb').hidden = false;
                }
         window.title = authStrings.getFormattedString('staff.auth.titlebar.label', version);
-               //var x = document.getElementById('version_label');
-               //x.setAttribute('value','Build ID: ' + version);
                var x = document.getElementById('about_btn');
-               x.setAttribute('label', offlineStrings.getString('main.about_btn.label'));
                x.addEventListener(
                        'command',
                        function() {
@@ -251,7 +248,6 @@ function main_init() {
                );
 
                var y = document.getElementById('new_window_btn');
-               y.setAttribute('label', offlineStrings.getString('main.new_window_btn.label'));
                y.addEventListener(
                        'command',
                        function() {
@@ -268,6 +264,50 @@ function main_init() {
                        false
                );
 
+               JSAN.use('util.mozilla');
+               var z = document.getElementById('locale_menupopup');
+               if (z) {
+                       while (z.lastChild) z.removeChild(z.lastChild);
+                       var locales = util.mozilla.chromeRegistry().getLocalesForPackage( String( location.href ).split(/\//)[2] );
+                       var current_locale = util.mozilla.prefs().getCharPref('general.useragent.locale');
+            while (locales.hasMore()) {
+                var locale = locales.getNext();
+                var parts = locale.split(/-/);
+                var label;
+                try {
+                    label = locale + ' : ' + util.mozilla.languages().GetStringFromName(parts[0]);
+                    if (parts.length > 1) {
+                        try {
+                            label += ' (' + util.mozilla.regions().GetStringFromName(parts[1].toLowerCase()) + ')';
+                        } catch(E) {
+                            label += ' (' + parts[1] + ')';
+                        }
+                    }
+                } catch(E) {
+                    label = locale;
+                }
+                               var mi = document.createElement('menuitem');
+                               mi.setAttribute('label',label);
+                               mi.setAttribute('value',locale);
+                if (locale == current_locale) {
+                    if (z.parentNode.tagName == 'menulist') {
+                        mi.setAttribute('selected','true');
+                        z.parentNode.setAttribute('label',label);
+                        z.parentNode.setAttribute('value',locale);
+                    }
+                }
+                z.appendChild( mi );
+            }
+               }
+               var xx = document.getElementById('apply_locale_btn');
+               xx.addEventListener(
+                       'command',
+                       function() {
+                               util.mozilla.change_locale(z.parentNode.value);
+                       },
+                       false
+               );
+
         var pref = Components.classes["@mozilla.org/preferences-service;1"]
                 .getService(Components.interfaces.nsIPrefBranch);
 
index 4f20549..9fa643e 100644 (file)
        <groupbox id="main_groupbox" flex="1" style="overflow: auto;">
                <caption id="main_caption" label="&staff.main.auth.caption;"/>
                <hbox>
-                       <label id="version_label"/>
-                       <button id="about_btn"/>
+                       <button id="about_btn" label="&staff.auth.about_btn.label;" accesskey="&staff.auth.about_btn.accesskey;" />
 
-                       <label id="new_window_label"/>
-                       <button id="new_window_btn"/>
+                       <button id="new_window_btn" label="&staff.auth.new_window_btn.label;" accesskey="&staff.auth.new_window_btn.accesskey;" />
+
+            <label value="&staff.auth.locale.label;" accesskey="&staff.auth.locale.accesskey;" control="locale_menu"/>
+            <menulist id="locale_menu">
+                <menupopup id="locale_menupopup">
+                </menupopup>
+            </menulist>
+                       <button id="apply_locale_btn" label="&staff.auth.apply_locale_btn.label;" accesskey="&staff.auth.apply_locale_btn.accesskey;" />
                </hbox>
                <label value=" "/>
 
diff --git a/Open-ILS/xul/staff_client/chrome/content/util/mozilla.js b/Open-ILS/xul/staff_client/chrome/content/util/mozilla.js
new file mode 100644 (file)
index 0000000..a758387
--- /dev/null
@@ -0,0 +1,75 @@
+dump('entering util/mozilla.js\n');
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+if (typeof util == 'undefined') var util = {};
+util.mozilla = {};
+
+util.mozilla.EXPORT_OK = [ 
+       'chromeRegistry', 'languages', 'regions', 'prefs'
+];
+util.mozilla.EXPORT_TAGS       = { ':all' : util.mozilla.EXPORT_OK };
+
+util.mozilla.chromeRegistry = function() {
+       try {
+
+        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        return Cc['@mozilla.org/chrome/chrome-registry;1'].getService(Ci['nsIToolkitChromeRegistry']);
+
+       } catch(E) {
+               alert("FIXME: util.mozilla.reloadChrome() = " + E);
+       }
+}
+
+util.mozilla.languages = function() {
+       try {
+
+        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        var stringBundles = Cc['@mozilla.org/intl/stringbundle;1'].getService(Ci['nsIStringBundleService']);
+        return stringBundles.createBundle('chrome://global/locale/languageNames.properties');
+
+       } catch(E) {
+               alert("FIXME: util.mozilla.reloadChrome() = " + E);
+       }
+}
+
+util.mozilla.regions = function() {
+       try {
+
+        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        var stringBundles = Cc['@mozilla.org/intl/stringbundle;1'].getService(Ci['nsIStringBundleService']);
+        return stringBundles.createBundle('chrome://global/locale/regionNames.properties');
+
+       } catch(E) {
+               alert("FIXME: util.mozilla.reloadChrome() = " + E);
+       }
+}
+
+util.mozilla.prefs = function() {
+       try {
+
+        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        return Cc['@mozilla.org/preferences-service;1'].getService(Ci['nsIPrefBranch']);
+
+       } catch(E) {
+               alert("FIXME: util.mozilla.reloadChrome() = " + E);
+       }
+}
+
+util.mozilla.change_locale = function( locale ) {
+       try {
+        var current_locale = 'en-US';
+        try { current_locale = util.mozilla.prefs().getCharPref('general.useragent.locale'); } catch(E) { alert('util.locale.change, prefs() = ' + E); }
+        if (locale != current_locale) {
+            util.mozilla.prefs().setCharPref('general.useragent.locale',locale);
+            util.mozilla.chromeRegistry().reloadChrome();
+        }
+
+       } catch(E) {
+               alert('FIXME: util.mozilla.change_locale( "' + locale + ") = " + E);
+       }
+}
+
+
+dump('exiting util/mozilla.js\n');
index 2f3a478..9e7dd30 100644 (file)
@@ -154,8 +154,6 @@ main.transaction_import.delete.prompt=Your transactions have been successfully m
 main.transaction_import.success=Transaction Import Successful
 main.on_debug.clear_cache=cache cleared
 main.on_debug.debug=debug the debug :D
-main.about_btn.label=About this client...
-main.new_window_btn.label=Open New Window
 main.new_window_btn.login_first_warning=Please login first!
 main.settings.migrate=This version of the staff client stores local settings in a different location than your previous installation.  Should we attempt to migrate these settings?
 main.settings.migrate.failed=WARNING: Unable to migrate legacy settings.  The settings and configuration files appear to exist in multiple locations. \nTo resolve this problem manually, please consider:\n\t%1$s\nwhich is in the directory where we want to store settings for the current operating system account, and:\n\t%2$s\nwhich is where we used to store such information.\n