adding methods, config vars, login code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Aug 2005 17:00:14 +0000 (17:00 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Aug 2005 17:00:14 +0000 (17:00 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1602 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/lib/js/opac/Request.js
Open-ILS/src/javascript/lib/js/opac/config.js
Open-ILS/src/javascript/lib/js/opac/init.js
Open-ILS/src/javascript/lib/js/opac/methods.js
Open-ILS/src/javascript/lib/js/opac/opac_utils.js
Open-ILS/src/javascript/lib/js/opac/org_utils.js
Open-ILS/src/webxml/js_common.xml
Open-ILS/src/webxml/login.xml
Open-ILS/src/webxml/sidebar.xml

index b0c5ac5..571c8ad 100644 (file)
@@ -8,3 +8,5 @@ function Request(type) {
 Request.prototype.callback = function(cal) { this.request.setCallback(cal); }
 Request.prototype.send         = function(block){this.request.send(block);}
 Request.prototype.result       = function(){return this.request.getResultObject();}
+
+alert(Request.prototype.result);
index e903e9c..710f114 100644 (file)
@@ -14,7 +14,8 @@ var PARAM_MRID                                        = "mrid";               /* metarecord id */
 var PARAM_RID                                  = "rid";                        /* metarecord id */
 
 /* cookies */
-var PARAM_SEARCHBAR_EXTRAS     = "searchbar_extras"
+var COOKIE_SB = "sbe";
+var COOKIE_SES = "ses";
 
 /* these are the actual param values - set on page load */
 
@@ -26,6 +27,33 @@ var ADVANCED = "advanced";
 var HOME                       = "home";
 var PREFS              = "prefs";
 
+/* search type (STYPE) options */
+STYPE_AUTHOR   = "author";
+STYPE_TITLE            = "title";
+STYPE_SUBJECT  = "subject";
+STYPE_SERIES   = "series";
+STYPE_KEYWORD  = "keyword";
+
+
+/* container for global variables shared accross pages */
+var G          = {};
+G.user = null; /* global user object */
+G.ui           = {} /* cache of UI components */
+
+
+/* call me after page init and I will load references 
+       to all of the ui object id's defined below 
+       They will be stored in G.ui.<page>.<thingy>
+ */
+function loadUIObjects() {
+       for( var p in config.ids ) {
+               G.ui[p] = {};
+               for( var o in config.ids[p] ) 
+                       G.ui[p][o] = getId(config.ids[p][o]);
+       }
+}
+
+
 
 /* ---------------------------------------------------------------------------- */
 /* Set up ID's and CSS classes */
@@ -36,18 +64,19 @@ config.text = {};
 config.ids = {};
 config.names = {};
 
-config.ids.loading     = "loading_div";
-config.ids.canvas              = "canvas";     
-config.ids.canvas_main         = "canvas_main";        
+config.ids.all = {};
+config.ids.all.loading         = "loading_div";        /* generic 'loading..' message */
+config.ids.all.canvas          = "canvas";                     /* outer UI canvas that holds the main canvas and any other hidden help components*/    
+config.ids.all.canvas_main     = "canvas_main";        /* main data display canvas */
 
 config.css = {};
 config.css.hide_me = "hide_me";
 
 config.page = {};
-config.page[HOME]              = "/webxml/index.xml";
+config.page[HOME]                      = "/webxml/index.xml";
 config.page[ADVANCED]  = "/webxml/advanced.xml";
-config.page[MRESULT]   = "/webxml/mresult.xml";
-config.page[RRESULT]   = "/webxml/rresult.xml";
+config.page[MRESULT]           = "/webxml/mresult.xml";
+config.page[RRESULT]           = "/webxml/rresult.xml";
 config.page[PREFS]             = "/webxml/webprefs.xml"
 config.page[MYOPAC]            = "/webxml/myopac/index.xml"
 
@@ -81,10 +110,11 @@ config.names.result.count_cell     = "copy_count_cell";
 
 config.ids.login = {};
 config.css.login = {};
-config.ids.login.box = "login_box";
+config.ids.login.box                   = "login_box";
 config.ids.login.username      = "login_username";
 config.ids.login.password      = "login_password";
 config.ids.login.button                = "login_button";
+config.ids.login.cancel                = "login_cancel_button";
 
 
 
@@ -116,5 +146,9 @@ config.css.sidebar.item.active      = 'side_bar_item_active';
 config.ids.sidebar.mresult                     = 'mresult_link_div';
 config.ids.sidebar.rresult                     = 'result_link_div';
 config.ids.sidebar.login                       = 'login_link';
+config.ids.sidebar.logged_in_as        = 'logged_in_as_div';
+config.ids.sidebar.username_dest       = 'username_dest';
+
+
 
 
index b0a23f5..365e50c 100644 (file)
@@ -1,36 +1,61 @@
 
 function init() {
+
+       loadUIObjects();
        initParams();
-       var page = findCurrentPage();
-       initSideBar(config.ids.sidebar[page]);
+       initSideBar();
        searchBarInit();
 
-       var login_div = getId(config.ids.sidebar.login);
-       if(login_div) login_div.onclick = initLogin;
+       var login = G.ui.sidebar.login
+       if(login) login.onclick = initLogin;
+
+       if(grabUser()) {
+               unHideMe(G.ui.sidebar.logged_in_as);
+               G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
+       }
 
-       switch(page) {
+       var page = findCurrentPage();
+       switch(findCurrentPage()) {
                case MRESULT: mresultDoSearch(); break;
                case RRESULT: rresultDoSearch(); break;
        }
 
 }
 
+/* sets up the login ui components */
 function initLogin() {
-       config.ids.login.button.onclick = function(){doLogin();}
-       addCSSClass(getId(config.ids.canvas_main), config.css.hide_me);
-       removeCSSClass(getId(config.ids.login.box), config.css.hide_me);
+
+
+       G.ui.login.button.onclick = function(){
+               if(doLogin()) {
+                       unHideMe(G.ui.all.canvas_main);
+                       hideMe(G.ui.login.box);
+                       hideMe(G.ui.all.loading);
+
+                       unHideMe(G.ui.sidebar.logged_in_as);
+                       G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
+               }
+       }
+
+       hideMe(G.ui.all.canvas_main);
+       unHideMe(G.ui.login.box);
+
+       G.ui.login.cancel.onclick = function(){
+               unHideMe(G.ui.all.canvas_main);
+               hideMe(G.ui.login.box);
+               hideMe(G.ui.all.loading);
+       }
 }
 
 
 /* set up the colors in the sidebar */
 function initSideBar() {
-       for( var p in config.ids.sidebar ) {
-               var page = config.ids.sidebar[p];
-               removeCSSClass(getId(page), config.css.sidebar.item.active);
-       }
+       for( var p in G.ui.sidebar ) 
+               removeCSSClass(p, config.css.sidebar.item.active);
+
        var page = findCurrentPage();
-       addCSSClass(getId(config.ids.sidebar[page]), config.css.sidebar.item.active);
-       removeCSSClass(getId(config.ids.sidebar[page]), config.css.hide_me);
+       addCSSClass(G.ui.sidebar[page], config.css.sidebar.item.active);
+       removeCSSClass(G.ui.sidebar[page], config.css.hide_me);
 }
 
 
index 39e3848..3f93f0d 100644 (file)
@@ -1,16 +1,19 @@
 /* Methods are defined as service:method */
 
-FETCH_MRCOUNT = "open-ils.search:open-ils.search.biblio.class.count"
+var FETCH_MRCOUNT = "open-ils.search:open-ils.search.biblio.class.count";
 if(isXUL()) FETCH_MRCOUNT += ".staff";
 
-FETCH_MRIDS = "open-ils.search:open-ils.search.biblio.class"
+var FETCH_MRIDS = "open-ils.search:open-ils.search.biblio.class";
 if(isXUL()) FETCH_MRIDS += ".staff";
 
-FETCH_MRMODS = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve";
+var FETCH_MRMODS = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve";
 
-FETCH_MR_COPY_COUNTS = "open-ils.search:open-ils.search.biblio.metarecord.copy_count"
+var FETCH_MR_COPY_COUNTS = "open-ils.search:open-ils.search.biblio.metarecord.copy_count";
 if(isXUL()) FETCH_MR_COPY_COUNTS += ".staff";
 
+var FETCH_FLESHED_USER = "open-ils.actor:open-ils.actor.user.fleshed.retrieve";
 
+var LOGIN_INIT                 = "open-ils.auth:open-ils.auth.authenticate.init";
+var LOGIN_COMPLETE     = "open-ils.auth:open-ils.auth.authenticate.complete";
 
 
index a26a196..d3e6553 100644 (file)
@@ -12,6 +12,7 @@ function Request(type) {
 
 Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); }
 Request.prototype.send         = function(block){this.request.send(block);}
+Request.prototype.result       = function(){return this.request.getResultObject();}
 /* ----------------------------------------------------------------------- */
 
 
@@ -105,8 +106,6 @@ function cleanISBN(isbn) {
 }       
 
 
-function doLogin() {
-}
 
 
 /* ----------------------------------------------------------------------- */
@@ -134,7 +133,7 @@ function buildAuthorLink(rec, link) {
        var args = {};
        args.page = MRESULT;
        args[PARAM_OFFSET] = 0;
-       args[PARAM_STYPE] = "author";
+       args[PARAM_STYPE] = STYPE_AUTHOR;
        args[PARAM_TERM] = rec.author();
        link.setAttribute("href", buildOPACLink(args));
 
@@ -143,6 +142,79 @@ function buildAuthorLink(rec, link) {
 
 
 
+/* ----------------------------------------------------------------------- */
+/* user session handling */
+/* ----------------------------------------------------------------------- */
+
+/* session is the login session.  If no session is provided, we attempt
+       to find one in the cookies.  
+       If 'force' is true we retrieve the 
+       user from the server even if there is already a global user present.
+       if ses != G.user.session, we also force a grab */
+var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
+function grabUser(ses, force) {
+
+       if(!ses) ses = cookie.get(COOKIE_SES);
+       if(!ses) return false;
+
+       if(!force) {
+               if(G.user && G.user.session == ses)
+                       return G.user;
+       }
+
+               
+   var req = new Request(FETCH_FLESHED_USER, ses);
+       req.send(true);
+
+       G.user = req.result();
+
+       if(!G.user || G.user.length == 0) { 
+               G.user = null; return false; 
+               cookie.remove(COOKIE_SES);
+       }
+
+       G.user.session = ses;
+       cookie.put(COOKIE_SES, ses);
+       return G.user;
+
+}
+
+
+/* returns a fleshed G.user on success, false on failure */
+function doLogin() {
+
+       var uname = G.ui.login.username.value;
+       var passwd = G.ui.login.password.value; 
+
+       var init_request = new Request( LOGIN_INIT, uname );
+   init_request.send(true);
+   var seed = init_request.result();
+
+   if( ! seed || seed == '0') {
+      alert( "Error Communicating with Authentication Server" );
+      return null;
+   }
+
+   var auth_request = new Request( LOGIN_COMPLETE, 
+               uname, hex_md5(seed + hex_md5(passwd)), "opac");
+
+   auth_request.send(true);
+   var auth_result = auth_request.result();
+
+   if(auth_result == '0' || auth_result == null || auth_request.length == 0) { return false; }
+
+       return grabUser(auth_result);
+}
+
+
+function hideMe(obj) { addCSSClass(obj, config.css.hide_me); } 
+function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
+
+
+
+
+
+
 
 
 
index 14fd4cf..493bbd9 100644 (file)
@@ -92,7 +92,7 @@ function orgNodeTrail(node) {
 }
 
 
-/* returns an array of sibling org units /
+/* returns an array of sibling org units */
 function findSiblingOrgs(node) {
        return findOrgUnit(node.parent_ou()).children();
 }
index d68b893..5000830 100644 (file)
@@ -4,10 +4,11 @@
 
 <div xmlns:xi="http://www.w3.org/2001/XInclude" xml:lang="en" lang="en">
 
+       <script language='javascript' src='/lib/js/util/utils.js'> </script>
        <script language='javascript' src='/lib/js/opac/config.js'> </script>
        <script language='javascript' src='/lib/js/util/CGI.js'> </script>
        <script language='javascript' src='/lib/js/util/Cookie.js'> </script>
-       <script language='javascript' src='/lib/js/util/utils.js'> </script>
+       <script language='javascript' src='/lib/js/util/md5.js'> </script>
        <script language='javascript' src='/lib/js/opac/init.js'> </script>
        <script language='javascript' src='/lib/js/opac/opac_utils.js'> </script>
        <script language='javascript' src='/lib/js/opac/RemoteRequest.js'> </script>
index c61980b..d74f513 100644 (file)
@@ -25,7 +25,7 @@
 
        <div class='login_links_div'>
                <span class='login_link'><a href="javascript:void(0);" id='login_button'> Login </a></span>
-               <span class=''><a href='javascript:void(0);'> Cancel </a></span>
+               <span class=''><a href='javascript:void(0);' id='login_cancel_button'> Cancel </a></span>
        </div>
 
 </div>
index 4052ff3..7fc1abc 100644 (file)
                        <span>Title Results</span>
                </div>
 
+               <div id='logged_in_as_div' Title="Logged In As..." class="side_bar_item hide_me">
+                       <span >You are logged in as <b id='username_dest'> </b></span>
+               </div>
+
+
        </div>
 
 </div>