opac, here we come
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 5 Aug 2005 12:31:51 +0000 (12:31 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 5 Aug 2005 12:31:51 +0000 (12:31 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1611 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/lib/js/opac/RemoteRequest.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/mresult.js
Open-ILS/src/javascript/lib/js/opac/opac_utils.js
Open-ILS/src/javascript/lib/js/opac/org_utils.js
Open-ILS/src/javascript/lib/js/opac/result_common.js
Open-ILS/src/javascript/lib/js/opac/rresult.js
Open-ILS/src/javascript/lib/js/opac/search_bar.js
Open-ILS/src/webxml/sidebar.xml

index 017a013..0894e05 100644 (file)
@@ -58,9 +58,6 @@ RemoteRequest.prototype.buildXMLRequest = function() {
                return null;
        }
 
-       if( this.callback )
-               this.setCompleteCallback( this.callback );
-
        return true;
 }
 
@@ -70,13 +67,11 @@ RemoteRequest.prototype.buildXMLRequest = function() {
 RemoteRequest.prototype.setCompleteCallback = function(callback) {
 
        if(this.cancelled) return;
-
        var object = this;
-       var obj = this.xmlhttp;
-       this.callback = callback;
+       var xml = this.xmlhttp;
 
-       this.xmlhttp.onreadystatechange = function() {
-               if( obj.readyState == 4 ) {
+       xml.onreadystatechange = function() {
+               if( xml.readyState == 4 ) {
 
                        try {
                                if(object.cancelled) return;
@@ -106,10 +101,15 @@ RemoteRequest.prototype.setCompleteCallback = function(callback) {
                                        //alert("Exception: " + E);
                                        throw E;
                                }
-                       } 
 
-                       /* on success, remove the request from the pending cache */
-                       //RemoteRequest.prunePending(object.id);
+                       }  finally {
+
+                               object.callback = null;
+                               object.xmlhttp.onreadystatechange = function(){};
+                               object.xmlhttp = null;
+                               object.params = null;
+                               object.param_string = null;
+                       }
                }
        }
 }
@@ -178,6 +178,7 @@ RemoteRequest.prototype.isReady = function() {
 
 /* returns the JSON->js result object  */
 RemoteRequest.prototype.getResultObject = function() {
+       //this.callback = null;
        if(this.cancelled) return null;
 
        var text = this.xmlhttp.responseText;
index 710f114..8af0e21 100644 (file)
@@ -53,6 +53,14 @@ function loadUIObjects() {
        }
 }
 
+function clearUIObjects() {
+       for( var p in config.ids ) {
+               for( var o in config.ids[p] ) 
+                       G.ui[p][o] = null;
+               G.ui[p] = null;
+       }
+}
+
 
 
 /* ---------------------------------------------------------------------------- */
@@ -146,6 +154,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.logout                      = 'logout_link';
+config.ids.sidebar.logoutbox           = 'logout_link_div';
+config.ids.sidebar.loginbox            = 'login_link_div';
 config.ids.sidebar.logged_in_as        = 'logged_in_as_div';
 config.ids.sidebar.username_dest       = 'username_dest';
 
index 365e50c..43f92ac 100644 (file)
@@ -1,19 +1,13 @@
 
 function init() {
 
+       document.body.onunload = unload;
+
        loadUIObjects();
        initParams();
        initSideBar();
        searchBarInit();
 
-       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()));
-       }
-
        var page = findCurrentPage();
        switch(findCurrentPage()) {
                case MRESULT: mresultDoSearch(); break;
@@ -22,18 +16,69 @@ function init() {
 
 }
 
+function unload() {
+
+       _tree_killer();
+
+       if(G.ui.sidebar.login)
+               G.ui.sidebar.login.onclick              = null;
+       if(G.ui.sidebar.logout)
+               G.ui.sidebar.logout.onclick     = null;
+       if(G.ui.login.button)
+               G.ui.login.button.onclick               = null;
+       if(G.ui.login.cancel)
+               G.ui.login.cancel.onclick               = null;
+       if(G.ui.searchbar.submit)
+               G.ui.searchbar.submit.onclick = null;
+       if(G.ui.searchbar.tag)
+               G.ui.searchbar.tag.onclick              = null;
+
+       clearUIObjects();
+
+       if(IE) {
+               window.CollectGarbage();
+       }
+}
+
+
+/* set up the colors in the sidebar 
+       Disables/Enables certain components based on various state data 
+ */
+function initSideBar() {
+
+       for( var p in G.ui.sidebar ) 
+               removeCSSClass(p, config.css.sidebar.item.active);
+
+       var page = findCurrentPage();
+       unHideMe(G.ui.sidebar[page]);
+       addCSSClass(G.ui.sidebar[page], config.css.sidebar.item.active);
+
+       /* if we're logged in, show it and replace the Login link with the Logout link */
+       if(grabUser()) {
+               G.ui.sidebar.username_dest.appendChild(text(G.user.usrname()));
+               unHideMe(G.ui.sidebar.logoutbox);
+               unHideMe(G.ui.sidebar.logged_in_as);
+               hideMe(G.ui.sidebar.loginbox);
+       }
+
+       if(G.ui.sidebar.login) G.ui.sidebar.login.onclick = initLogin;
+       if(G.ui.sidebar.logout) G.ui.sidebar.logout.onclick = doLogout; 
+
+}
+
 /* sets up the login ui components */
 function initLogin() {
 
-
        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()));
+                       unHideMe(G.ui.sidebar.logoutbox);
+                       unHideMe(G.ui.sidebar.logged_in_as);
+                       hideMe(G.ui.sidebar.loginbox);
                }
        }
 
@@ -48,16 +93,6 @@ function initLogin() {
 }
 
 
-/* set up the colors in the sidebar */
-function initSideBar() {
-       for( var p in G.ui.sidebar ) 
-               removeCSSClass(p, config.css.sidebar.item.active);
-
-       var page = findCurrentPage();
-       addCSSClass(G.ui.sidebar[page], config.css.sidebar.item.active);
-       removeCSSClass(G.ui.sidebar[page], config.css.hide_me);
-}
-
 
 /* sets all of the params values */
 var TERM,  STYPE,  LOCATION,  DEPTH,  FORM, OFFSET,  COUNT,  
index 3f93f0d..dee743f 100644 (file)
@@ -13,7 +13,9 @@ if(isXUL()) FETCH_MR_COPY_COUNTS += ".staff";
 
 var FETCH_FLESHED_USER = "open-ils.actor:open-ils.actor.user.fleshed.retrieve";
 
+var FETCH_SESSION              = "open-ils.auth:open-ils.auth.session.retrieve";
 var LOGIN_INIT                 = "open-ils.auth:open-ils.auth.authenticate.init";
 var LOGIN_COMPLETE     = "open-ils.auth:open-ils.auth.authenticate.complete";
+var LOGIN_DELETE               = "open-ils.auth:open-ils.auth.session.delete";
 
 
index b650eb5..c88bd73 100644 (file)
@@ -5,8 +5,8 @@ var rowtemplate;
 
 function mresultDoSearch() {
 
-       table = getId(config.ids.result.main_table);
-       rowtemplate = table.removeChild(getId(config.ids.result.row_template));
+       table = G.ui.result.main_table;
+       rowtemplate = table.removeChild(G.ui.result.row_template);
        removeChildren(table);
 
        if(getOffset() == 0 || getHitCount() == null ) {
@@ -15,7 +15,6 @@ function mresultDoSearch() {
        } else { 
                resultSetInfo();
                mresultCollectIds();
-               mresultCollectRecords(); 
        }
 }
 
@@ -35,7 +34,10 @@ function mresultCollectIds() {
                        getLocation(), getDepth(), getDisplayCount(), getOffset(), getForm() );
        req.callback( function(r) {
                mresultSetRecords(r.getResultObject().ids);
-               mresultCollectRecords(); });
+               mresultCollectRecords(); 
+               req.request = null;
+               r.callback = null;
+       });
        req.send();
 }
 
@@ -62,8 +64,8 @@ function mresultCollectRecords() {
 
                /*              
                if( x == (getDisplayCount() + getOffset()) - 1 ) {
-                       getId(config.ids.result.top_div).appendChild(
-                               getId(config.ids.result.nav_links).cloneNode(true));
+                       G.ui.result.top_div.appendChild(
+                               G.ui.result.nav_links.cloneNode(true));
                }
                */
        }
index d3e6553..c927e28 100644 (file)
@@ -157,9 +157,17 @@ function grabUser(ses, force) {
        if(!ses) ses = cookie.get(COOKIE_SES);
        if(!ses) return false;
 
-       if(!force) {
+       if(!force) 
                if(G.user && G.user.session == ses)
                        return G.user;
+
+
+       /* first make sure the session is valid */
+       var request = new Request(FETCH_SESSION, ses );
+       request.send(true);
+       var user = request.result();
+       if( !(typeof user == 'object' && user._isfieldmapper) ) {
+               return false;
        }
 
                
@@ -175,6 +183,8 @@ function grabUser(ses, force) {
 
        G.user.session = ses;
        cookie.put(COOKIE_SES, ses);
+       cookie.write();
+
        return G.user;
 
 }
@@ -203,7 +213,25 @@ function doLogin() {
 
    if(auth_result == '0' || auth_result == null || auth_request.length == 0) { return false; }
 
-       return grabUser(auth_result);
+       return grabUser(auth_result, true);
+}
+
+function doLogout() {
+
+       /* be nice and delete the session from the server */
+       if(G.user && G.user.session) { 
+               var req = new Request(LOGIN_DELETE, G.user.session);
+      req.send(true);
+               try { req.result(); } catch(E){}
+    }
+
+       G.user = null;
+       cookie.remove(COOKIE_SES);
+
+       hideMe(G.ui.sidebar.logoutbox);
+       unHideMe(G.ui.sidebar.loginbox);
+       hideMe(G.ui.sidebar.logged_in_as);
+
 }
 
 
index 493bbd9..fb5e1dc 100644 (file)
@@ -31,48 +31,11 @@ function findOrgType(type_id) {
 }
 
 
-/* locates a specific org unit by id, acts as a cache of orgs*/
-var orgArraySearcher = null;
-
-/* flatten the org tree for faster searching */
-function _flattenOrgs(node) { 
-
-       if(node == null) {
-               node = globalOrgTree;
-               orgArraySearcher = new Object();
-       }
-
-       orgArraySearcher[node.id()] = node;
-       for(var idx in node.children()) {
-               _flattenOrgs(node.children()[idx]);
-       }
-}
-
 /* returns an org unit by id.  if an object is passed in as the id,
        then the object is assumed to be an org unit and is returned */
-function findOrgUnit(org_id, branch) {
-
+function findOrgUnit(org_id) {
        if(org_id == null) return null;
        if(typeof org_id == 'object') return org_id;
-
-       /* if we don't have the global org tree, grab the org unit from the server */
-       var tree_exists = false;
-       try{if(globalOrgTree != null) tree_exists = true;}catch(E){}
-
-       if(!tree_exists) {
-               var org = orgArraySearcher[org_id];
-               if(org) return org;
-               var r = new RemoteRequest(
-                       "open-ils.actor",
-                       "open-ils.actor.org_unit.retrieve", null, org_id);
-               r.send(true);
-               orgArraySearcher[org_id] = r.getResultObject();
-               return orgArraySearcher[org_id];
-       }
-
-       if(orgArraySearcher == null)
-               _flattenOrgs();
-
        return orgArraySearcher[org_id];
 }
 
index 12d2512..c162d85 100644 (file)
@@ -5,8 +5,8 @@ function resultSetInfo() {
        else c = getDisplayCount() + getOffset();
 
        var pages = parseInt(getHitCount() / getDisplayCount()) + 1;
-       getId(config.ids.result.current_page).appendChild(text( (getOffset()/getDisplayCount()) + 1));
-       getId(config.ids.result.num_pages).appendChild(text(pages + ")"));
+       G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
+       G.ui.result.num_pages.appendChild(text(pages + ")"));
 
        var o = getOffset();
 
@@ -14,29 +14,29 @@ function resultSetInfo() {
 
                var args = {};
                args[PARAM_OFFSET] = o + getDisplayCount();
-               getId(config.ids.result.next_link).setAttribute("href", buildOPACLink(args)); 
-               addCSSClass(getId(config.ids.result.next_link), config.css.result.nav_active);
+               G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
 
                args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
-               getId(config.ids.result.end_link).setAttribute("href", buildOPACLink(args)); 
-               addCSSClass(getId(config.ids.result.end_link), config.css.result.nav_active);
+               G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
        }
 
        if( o > 0 ) {
 
                var args = {};
                args[PARAM_OFFSET] = o - getDisplayCount();
-               getId(config.ids.result.prev_link).setAttribute( "href", buildOPACLink(args)); 
-               addCSSClass(getId(config.ids.result.prev_link), config.css.result.nav_active);
+               G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
 
                args[PARAM_OFFSET] = 0;
-               getId(config.ids.result.home_link).setAttribute( "href", buildOPACLink(args)); 
-               addCSSClass(getId(config.ids.result.home_link), config.css.result.nav_active);
+               G.ui.result.home_link.setAttribute( "href", buildOPACLink(args)); 
+               addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
        }
 
-       getId(config.ids.result.offset_start).appendChild(text(o + 1));
-       getId(config.ids.result.offset_end).appendChild(text(c));
-       getId(config.ids.result.result_count).appendChild(text(getHitCount()));
+       G.ui.result.offset_start.appendChild(text(o + 1));
+       G.ui.result.offset_end.appendChild(text(c));
+       G.ui.result.result_count.appendChild(text(getHitCount()));
 
 
 }
@@ -44,10 +44,10 @@ function resultSetInfo() {
 
 function resultDisplayRecord(rec, rowtemplate, is_mr) {
 
-       if(rec == null) rec = {};
+       if(rec == null) rec = new mvr(); /* if we return we won't build some important UI components */
 
        /* hide the 'now loading...' message */
-       addCSSClass(getId(config.ids.loading), config.css.hide_me);
+       hideMe(G.ui.all.loading);
 
        var r = rowtemplate.cloneNode(true);
 
index 8b073e9..7ebefb2 100644 (file)
@@ -5,8 +5,8 @@ var mrid;
 
 function rresultDoSearch() {
 
-       table = getId(config.ids.result.main_table);
-       rowtemplate = table.removeChild(getId(config.ids.result.row_template));
+       table = G.ui.result.main_table;
+       rowtemplate = table.removeChild(G.ui.result.row_template);
        removeChildren(table);
        mrid = getMrid();
 
index 05f7cd1..cf93944 100644 (file)
@@ -11,26 +11,26 @@ var formSelector;
 
 function searchBarInit() {
 
-       getId(config.ids.searchbar.text).focus();
-       getId(config.ids.searchbar.text).onkeydown = 
+       G.ui.searchbar.text.focus();
+       G.ui.searchbar.text.onkeydown = 
                function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
-       getId(config.ids.searchbar.submit).onclick = searchBarSubmit;
+       G.ui.searchbar.submit.onclick = searchBarSubmit;
 
-       searchBarTable          = getId(config.ids.searchbar.table);
-       searchBarTagLink        = getId(config.ids.searchbar.tag);
-       searchBarExtraRow = getId(config.ids.searchbar.extra_row);
-       searchBarMainRow        = getId(config.ids.searchbar.main_row);
+       searchBarTable          = G.ui.searchbar.table;
+       searchBarTagLink        = G.ui.searchbar.tag;
+       searchBarExtraRow = G.ui.searchbar.extra_row;
+       searchBarMainRow        = G.ui.searchbar.main_row;
 
-       typeSelector = getId(config.ids.searchbar.type_selector);
-       depthSelector = getId(config.ids.searchbar.depth_selector);
-       formSelector = getId(config.ids.searchbar.form_selector);
+       typeSelector = G.ui.searchbar.type_selector;
+       depthSelector = G.ui.searchbar.depth_selector;
+       formSelector = G.ui.searchbar.form_selector;
 
        searchBarTagLink.onclick = function(){searchBarToggle();}
 
        /* set up the selector objects, etc */
        var t = getTerm();
        if(t == null) t = "";
-       getId(config.ids.searchbar.text).value = t;
+       G.ui.searchbar.text.value = t;
        setSelector(typeSelector,       getStype());
        setSelector(depthSelector, getDepth());
        setSelector(formSelector,       getForm());
@@ -69,9 +69,9 @@ function searchBarSelectorChanged(type) {
 */
 
 function searchBarSubmit() {
-       var text = getId(config.ids.searchbar.text).value;
+       var text = G.ui.searchbar.text.value;
        if(!text || text == "") return;
-       var type_s = getId(config.ids.searchbar.type_selector);
+       var type_s = G.ui.searchbar.type_selector;
 
        var args = {};
        args.page = MRESULT;
@@ -89,18 +89,18 @@ function searchBarToggle() {
 
        if(searchBarExpanded) {
 
-               addCSSClass(searchBarExtraRow,config.css.hide_me);
+               hideMe(searchBarExtraRow);
                searchBarExpanded = false;
-               getId(config.ids.searchbar.tag_off).className = "show_me_inline";
-               getId(config.ids.searchbar.tag_on).className = "hide_me";
+               G.ui.searchbar.tag_off.className = "show_me_inline";
+               hideMe(G.ui.searchbar.tag_on);
                //SEARCHBAR_EXTRAS = 0; set cookie...
 
        } else {
 
                removeCSSClass(searchBarExtraRow,config.css.hide_me);
                searchBarExpanded = true;
-               getId(config.ids.searchbar.tag_off).className = "hide_me";
-               getId(config.ids.searchbar.tag_on).className = "show_me_inline";
+               hideMe(G.ui.searchbar.tag_off);
+               G.ui.searchbar.tag_on.className = "show_me_inline";
                //SEARCHBAR_EXTRAS = 1; set cookie...
        }
 }
index 7fc1abc..0df07d2 100644 (file)
                        <a href='/webxml/advanced.xml'>Advanced Search</a>
                </div>
 
-               <div title="Log in"
+               <div title="Got to the MyOPAC Page"
+                       id='myopac_link_div' class="side_bar_item">
+                       <a  href='/webxml/myopac/index.xml'>My OPAC</a>
+               </div>
+
+               <div title="Login"
                        id='login_link_div' class="side_bar_item">
                        <a id='login_link' href='javascript:void(0);'>Login</a>
                </div>
 
-       
-               <div title="Got to the MyOPAC Page"
-                       id='myopac_link_div' class="side_bar_item">
-                       <a  href='/webxml/myopac/index.xml'>My OPAC</a>
+               <div title="Log out"
+                       id='logout_link_div' class="side_bar_item hide_me">
+                       <a id='logout_link' href='javascript:void(0);'>Log out</a>
                </div>
-       
-               <!--
-               <div title="Go to the Web Preferences Page"
-                       id='prefs_link_div' class="side_bar_item">
-                       <a href='/webxml/webprefs.xml'>My Preferences</a>
+
+               <!-- Informational sidebar components -->
+
+               <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 title="Title Group Results Page" 
                        id='mresult_link_div' class="side_bar_item hide_me">
                        <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>