Staff client initial hostname
authorThomas Berezansky <tsbere@mvlc.org>
Thu, 2 Aug 2012 17:28:44 +0000 (13:28 -0400)
committerBen Shum <bshum@biblio.org>
Wed, 31 Oct 2012 14:48:50 +0000 (22:48 +0800)
Add support for an initial staff client hostname.

It can be specified during building the staff client or via configure.

During making the staff client:

make INITIAL_HOST=hostname build

During configure:

./configure --with-initialhost=hostname

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>

Open-ILS/xul/staff_client/Makefile.am
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/defaults/preferences/initialhost.js [new file with mode: 0644]
configure.ac
docs/RELEASE_NOTES_NEXT/initial_host.txt [new file with mode: 0644]

index 9556dfe..2e165a6 100644 (file)
@@ -160,6 +160,8 @@ stamp:
        @if [ -n "${AUTOUPDATE_HOST}" ]; then echo "Applying automatic update host ${AUTOUPDATE_HOST}"; fi
        @if [ -n "${AUTOUPDATE_HOST}" ]; then sed -i -e "s|::HOSTNAME::|${AUTOUPDATE_HOST}|" -e "s|https\?://\(https\?://\)|\1|" build/defaults/preferences/autoupdate.js; fi
        @if [ -n "${AUTOUPDATE_HOST}" ]; then sed -i -e "s|::HOSTNAME::|${AUTOUPDATE_HOST}|" -e "s|https\?://\(https\?://\)|\1|" build/install.rdf; fi
+       @if [ -z "${INITIAL_HOST}" ]; then rm -f build/defaults/preferences/initialhost.js; fi
+       @if [ -n "${INITIAL_HOST}" ]; then sed -i -e "s/%INITIAL_HOST%/${INITIAL_HOST}/" build/defaults/preferences/initialhost.js; fi
        @cp build/STAMP_ID PREV_STAMP_ID
        @cp build/VERSION PREV_VERSION
 
index d437a7a..11b9e1a 100644 (file)
@@ -276,7 +276,6 @@ auth.controller.prototype = {
         obj.session = new auth.session(obj.controller.view);
 
         obj.controller.render();
-        obj.test_server( obj.controller.view.server_prompt.value );
         obj.controller.render('ws_deck'); 
 
         if (typeof this.on_init == 'function') {
@@ -320,9 +319,15 @@ auth.controller.prototype = {
                     if (x.status == 200) {
                         s.setAttribute('style','color: green;');
                     } else {
+                        if(x.status == 0) {
+                            s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
+                            obj.controller.view.server_prompt.disabled = false;
+                            obj.controller.view.server_prompt.focus();
+                        }
                         s.setAttribute('style','color: red;');
                     }
-                    obj.test_version(url);
+                    if(x.status > 0)
+                        obj.test_version(url);
                 } catch(E) {
                     obj.controller.view.server_prompt.disabled = false;
                     obj.controller.view.server_prompt.focus();
index 139828a..a86b642 100644 (file)
@@ -724,13 +724,20 @@ function main_init() {
             document.getElementById('offline_import_btn').disabled = true;
         }
 
+        var should_test_server = true;
         // Attempt auto-login, if provided
         if("arguments" in window && window.arguments.length > 0 && window.arguments[0].wrappedJSObject != undefined && window.arguments[0].wrappedJSObject.loginInfo != undefined) {
-            auto_login(window.arguments[0].wrappedJSObject.loginInfo);
+            should_test_server = auto_login(window.arguments[0].wrappedJSObject.loginInfo);
             // Regardless of success, clear that variable now, so we don't possibly have passwords hanging around.
             window.arguments[0].wrappedJSObject.loginInfo = null;
         }
 
+        if (should_test_server) {
+            G.auth.test_server(G.auth.controller.view.server_prompt.value);
+            G.auth.controller.render('ws_deck');
+        }
+        setTimeout(load_init_hostname, 500);
+
     } catch(E) {
         var error = offlineStrings.getFormattedString('common.exception', [E, '']);
         try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
@@ -739,6 +746,18 @@ function main_init() {
     dump('exiting main_init()\n');
 }
 
+function load_init_hostname() {
+    G.data.stash_retrieve();
+    if(!G.auth.controller.view.server_prompt.value) {
+        try {
+            G.auth.controller.view.server_prompt.value = G.pref.getCharPref('open-ils.initial_hostname');
+            G.auth.test_server(G.pref.getCharPref('open-ils.initial_hostname'));
+            G.auth.controller.render('ws_deck');
+        } catch(E) {
+        }
+    }
+}
+
 function found_ws_info_in_Achrome() {
     JSAN.use('util.file');
     var f = new util.file();
@@ -784,13 +803,21 @@ function handle_migration() {
 
 function auto_login(loginInfo) {
     G.data.stash_retrieve();
+    var should_test_server = true;
     if(G.data.session) return; // We are logged in. No auto-logoff supported.
-    if(loginInfo.host) G.auth.controller.view.server_prompt.value = loginInfo.host;
+    if(loginInfo.host) {
+        G.auth.controller.view.server_prompt.value = loginInfo.host;
+        G.auth.test_server(loginInfo.host);
+        G.auth.controller.render('ws_deck');
+        should_test_server = false;
+    }
     if(loginInfo.user) G.auth.controller.view.name_prompt.value = loginInfo.user;
     if(loginInfo.passwd) G.auth.controller.view.password_prompt.value = loginInfo.passwd;
     if(loginInfo.host && loginInfo.user && loginInfo.passwd && G.data.ws_info && G.data.ws_info[loginInfo.host]) {
-        G.auth.login();
+        // Give test_server time to finish
+        setTimeout(function() { G.auth.login(); }, 1000);
     }
+    return should_test_server;
 }
 
 dump('exiting main/main.js\n');
diff --git a/Open-ILS/xul/staff_client/defaults/preferences/initialhost.js b/Open-ILS/xul/staff_client/defaults/preferences/initialhost.js
new file mode 100644 (file)
index 0000000..3b5ad2d
--- /dev/null
@@ -0,0 +1,3 @@
+// Initial hostname
+// For clean installs
+pref("open-ils.initial_hostname", "%INITIAL_HOST%");
index 1d99e19..89e64f6 100644 (file)
@@ -106,6 +106,14 @@ AC_ARG_WITH([updateshost],
 [AUTOUPDATE_HOST=])
 AC_SUBST([AUTOUPDATE_HOST])
 
+# Default updates host?
+AC_ARG_WITH([initialhost],
+[  --with-initialhost=hostname    default hostname for staff client (default is blank)],
+[INITIAL_HOST=${withval}],
+[INITIAL_HOST=])
+AC_SUBST([INITIAL_HOST])
+
+
 # install Evergreen Apache modules?
 AC_ARG_ENABLE([apache-modules],
 [  --disable-apache-modules    disables installation of the Evergreen Apache modules ],
diff --git a/docs/RELEASE_NOTES_NEXT/initial_host.txt b/docs/RELEASE_NOTES_NEXT/initial_host.txt
new file mode 100644 (file)
index 0000000..7699480
--- /dev/null
@@ -0,0 +1,12 @@
+Staff Client Initial Hostname
+-----------------------------
+
+For fresh installs of the staff client a common issue is people remembering what hostname to specify. If you are building your own staff clients you can now fill this in automatically.
+
+You can specify this when configuring Evergreen with a new configure option:
+
+--with-initialhost=example.org
+
+It is also possible to specify when building the staff client itself using the INITIAL_HOST variable:
+
+make INITIAL_HOST=example.org build