memory leak debugging, removed closures
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 10 Aug 2005 17:03:17 +0000 (17:03 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 10 Aug 2005 17:03:17 +0000 (17:03 +0000)
added flesh user method

git-svn-id: svn://svn.open-ils.org/ILS/trunk@1629 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/lib/js/opac/RemoteRequest.js
Open-ILS/src/javascript/lib/js/opac/Request.js [deleted file]
Open-ILS/src/javascript/lib/js/opac/init.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/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/altcanvas.xml

index 0894e05..174f820 100644 (file)
@@ -2,10 +2,25 @@ var XML_HTTP_GATEWAY = "gateway";
 var XML_HTTP_SERVER = "gapines.org";
 var XML_HTTP_MAX_TRIES = 3;
 
+var _allrequests = new Array();
+
+function cleanRemoteRequests() {
+       for( var i = 0; i!= _allrequests.length; i++ ) {
+               var r = _allrequests[i];
+               r.xmlhttp.onreadystatechange = function(){};
+               r.xmlhttp                       = null;
+               r.callback                      = null;
+               r.userdata                      = null;
+               _allrequests[i]         = null;
+       }
+}
+
 /* ----------------------------------------------------------------------- */
 /* Request object */
 function RemoteRequest( service, method ) {
 
+       _allrequests.push(this);
+
        this.service    = service;
        this.method             = method;
        this.xmlhttp    = false;
@@ -95,21 +110,8 @@ RemoteRequest.prototype.setCompleteCallback = function(callback) {
                                                object.send();
                                                return;
                                        }
-                               } else {
-                                       /* any other exception is alerted for now */
-                                       //RemoteRequest.prunePending(object.id);
-                                       //alert("Exception: " + E);
-                                       throw E;
-                               }
-
-                       }  finally {
-
-                               object.callback = null;
-                               object.xmlhttp.onreadystatechange = function(){};
-                               object.xmlhttp = null;
-                               object.params = null;
-                               object.param_string = null;
-                       }
+                               } else { throw E; }
+                       } finally { object = null; }  
                }
        }
 }
diff --git a/Open-ILS/src/javascript/lib/js/opac/Request.js b/Open-ILS/src/javascript/lib/js/opac/Request.js
deleted file mode 100644 (file)
index 571c8ad..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-function Request(type) {
-       var s = type.split(":");
-       this.request = new RemoteRequest(s[0], s[1]);
-       for( var x = 1; x!= arguments.length; x++ ) 
-               this.request.addParam(arguments[x]);
-}
-
-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 6ef9059..80efc3f 100644 (file)
@@ -2,6 +2,7 @@
 function init() {
 
        document.body.onunload = unload;
+       window.onunload = unload;
 
        loadUIObjects();
        initParams();
@@ -20,7 +21,8 @@ function init() {
 function unload() {
        _tree_killer();
        clearUIObjects();
-       if(IE) window.CollectGarbage();
+       cleanRemoteRequests();
+       try{mresultUnload();} catch(E){}
 }
 
 
index c731571..b8fb911 100644 (file)
@@ -3,6 +3,9 @@ var ranks = new Array();
 var table;
 var rowtemplate;
 
+function mresultUnload() { removeChildren(table); table = null;}
+
+
 function mresultDoSearch() {
 
        table = G.ui.result.main_table;
@@ -21,26 +24,29 @@ function mresultDoSearch() {
 function mresultGetCount() {
        var req = new Request(FETCH_MRCOUNT, 
                        getStype(), getTerm(), getLocation(), getDepth(), getForm() );
-       req.callback( function(r) {
-               HITCOUNT = parseInt(r.getResultObject());
-               resultSetInfo(); });
+       req.callback(mresultHandleCount);
        req.send();
 }
 
+function mresultHandleCount(r) {
+       HITCOUNT = parseInt(r.getResultObject());
+       resultSetInfo(); 
+}
+
 
 /* performs the actual search */
 function mresultCollectIds() {
        var req = new Request(FETCH_MRIDS, getStype(), getTerm(), 
                        getLocation(), getDepth(), getDisplayCount(), getOffset(), getForm() );
-       req.callback( function(r) {
-               mresultSetRecords(r.getResultObject().ids);
-               mresultCollectRecords(); 
-               req.request = null;
-               r.callback = null;
-       });
+       req.callback(mresultHandleMRIds);
        req.send();
 }
 
+function mresultHandleMRIds(r) {
+       mresultSetRecords(r.getResultObject().ids);
+       mresultCollectRecords(); 
+}
+
 function mresultSetRecords(idstruct) {
        var o = getOffset();
        for( var x = o; x!= idstruct.length + o; x++ ) {
@@ -49,25 +55,19 @@ function mresultSetRecords(idstruct) {
        }
 }
 
+function mresultHandleMods(r) {
+       var rec = r.getResultObject();
+       resultDisplayRecord(rec, rowtemplate, true);
+       resultCollectCopyCounts(rec, FETCH_MR_COPY_COUNTS);
+}
+
 
 function mresultCollectRecords() {
        for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
                if(isNull(records[x])) break;
-
                var req = new Request(FETCH_MRMODS, records[x]);
-               req.callback(function(r){
-                               var rec = r.getResultObject();
-                               resultDisplayRecord(rec, rowtemplate, true);
-                               resultCollectCopyCounts(rec, FETCH_MR_COPY_COUNTS);
-               });
+               req.callback(mresultHandleMods);
                req.send();
-
-               /*              
-               if( x == (getDisplayCount() + getOffset()) - 1 ) {
-                       G.ui.result.top_div.appendChild(
-                               G.ui.result.nav_links.cloneNode(true));
-               }
-               */
        }
 }
 
index ec796e2..f5011b3 100644 (file)
@@ -213,8 +213,26 @@ function grabUser(ses, force) {
                return false;
        }
 
-               
-   var req = new Request(FETCH_FLESHED_USER, ses);
+       G.user = user;
+       G.user.fleshed = false;
+       G.user.session = ses;
+       cookie.put(COOKIE_SES, ses);
+       cookie.write();
+
+       return G.user;
+
+}
+
+function grabFleshedUser() {
+
+       if(!G.user || !G.user.session) {
+               grabUser();     
+               if(!G.user || !G.user.session) return null;
+       }
+
+       if(G.user.fleshed) return G.user;
+
+   var req = new Request(FETCH_FLESHED_USER, G.user.session);
        req.send(true);
 
        G.user = req.result();
@@ -225,11 +243,12 @@ function grabUser(ses, force) {
        }
 
        G.user.session = ses;
-       cookie.put(COOKIE_SES, ses);
+       G.user.fleshed = true;
+
+       cookie.put(COOKIE_SES, ses); /*  update the cookie */
        cookie.write();
 
        return G.user;
-
 }
 
 
index 6d6e341..77383cc 100644 (file)
@@ -128,7 +128,6 @@ function resultAddCopyCounts(countsrow, rec) {
                        ccell.title = type.opac_label();
                        countsrow.insertBefore(ccell, lastcell);
                        lastcell = ccell;
-
                }
        }
 
@@ -136,15 +135,19 @@ function resultAddCopyCounts(countsrow, rec) {
 
 }
 
-
 /* collect copy counts for a record using method 'methodName' */
 function resultCollectCopyCounts(rec, methodName) {
        if(rec == null || rec.doc_id() == null) return;
        var req = new Request(methodName, getLocation(), rec.doc_id() );
-       req.callback(function(r){ resultDisplayCopyCounts(rec, r.getResultObject()); });
+       req.request.userdata = rec;
+       req.callback(resultHandleCopyCounts);
        req.send();
 }
 
+function resultHandleCopyCounts(r) {
+       resultDisplayCopyCounts(r.userdata, r.getResultObject()); 
+}
+
 
 /* display the collected copy counts */
 function resultDisplayCopyCounts(rec, copy_counts) {
index 100424c..d04b078 100644 (file)
@@ -11,23 +11,28 @@ function rresultDoSearch() {
 
 function rresultCollectIds() {
        var req = new Request(FETCH_RIDS, getMrid(), getForm() );
-       req.callback( function(r) {
-               var res = r.getResultObject();
-               HITCOUNT = parseInt(res.count);
-               resultSetInfo();
-               rresultCollectRecords(res.ids); });
+       req.callback( rresultHandleRIds );
        req.send();
 }
 
+function rresultHandleRIds(r) {
+       var res = r.getResultObject();
+       HITCOUNT = parseInt(res.count);
+       resultSetInfo();
+       rresultCollectRecords(res.ids);
+}
+
 function rresultCollectRecords(ids) {
        for( var i = getOffset(); i!= getDisplayCount() + getOffset(); i++ ) {
                var req = new Request(FETCH_RMODS, parseInt(ids[i]));
-               req.callback( function(r) {
-                       var rec = r.getResultObject();
-                       resultDisplayRecord(rec, rowtemplate, false);
-                       resultCollectCopyCounts(rec, FETCH_R_COPY_COUNTS);
-               });
+               req.callback(rresultHandleMods);
                req.send();
        }
 }
 
+function rresultHandleMods(r) {
+       var rec = r.getResultObject();
+       resultDisplayRecord(rec, rowtemplate, false);
+       resultCollectCopyCounts(rec, FETCH_R_COPY_COUNTS);
+}
+
index a8c7c7c..cf7ebf7 100644 (file)
@@ -18,19 +18,20 @@ function searchBarInit() {
                function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
 
        G.ui.searchbar.submit.onclick = searchBarSubmit;
-       G.ui.searchbar.tag.onclick = function(){searchBarToggle();}
+       G.ui.searchbar.tag.onclick = searchBarToggle;
 
        /* set up the selector objects, etc */
        G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
        setSelector(_ts,        getStype());
        setSelector(_ds,        getDepth());
        setSelector(_fs,        getForm());
+       G.ui.searchbar.location_tag.onclick = _opacHandleLocationTagClick;
+}
 
-       G.ui.searchbar.location_tag.onclick = function() {
-               orgTreeSelector.openTo(  
-                       (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
-               swapCanvas(G.ui.common.org_container);
-       }
+function _opacHandleLocationTagClick() {
+       orgTreeSelector.openTo(  
+               (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
+       swapCanvas(G.ui.common.org_container);
 }
 
 function updateLoc(location, depth) {
index a06beea..60bd607 100644 (file)
@@ -13,7 +13,7 @@
                <div id='org_link_container' class='color_1'>
                        <span class='org_link'><a onclick='orgTreeSelector.openAll();' href='javascript:void(0);'>Expand All</a></span>
                        <span class='org_link'><a onclick='orgTreeSelector.closeAll();' href='javascript:void(0);'>Close All</a></span>
-                       <span class='org_link'><a onclick='showCanvas();' href='javascript:void(0);'>Exit</a></span>
+                       <span class='org_link'><a onclick='showCanvas();' href='javascript:void(0);'> Exit </a></span>
                </div>
                <div id='org_tree' class='org_tree'> </div>
        </div>