6 var mresultPreCache = 200;
9 attachEvt("common", "unload", mresultUnload);
10 attachEvt("common", "run", mresultDoSearch);
11 attachEvt("result", "idsReceived", mresultSetRecords);
12 attachEvt("result", "idsReceived", mresultCollectRecords);
14 function mresultUnload() { removeChildren(table); table = null;}
16 hideMe($('copyright_block'));
18 function mresultDoSearch() {
21 TFORM = null; /* clear the rresult tform var so it's not propogated */
23 swapCanvas($('loading_alt'));
24 table = G.ui.result.main_table;
26 while( table.parentNode.rows.length <= (getDisplayCount() + 1) )
27 table.appendChild(G.ui.result.row_template.cloneNode(true));
29 if( (getSearches() || getAdvTerm()) && !getTerm() ) {
30 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
32 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvMARCIds();
43 function mresultLoadCachedSearch() {
44 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
45 var c = JSON2js(cookieManager.read(COOKIE_IDS));
46 if(c) { records = c[0]; ranks = c[1]; }
51 function mresultTryCachedSearch() {
56 mresultLoadCachedSearch();
57 if( getOffset() != 0 && records[getOffset()] != null &&
58 records[resultFinalPageIndex()] != null) {
59 runEvt('result', 'hitCountReceived');
60 mresultCollectRecords();
67 function _mresultCollectIds() {
68 if(getOffset() != 0 && mresultTryCachedSearch()) return;
69 resultCollectSearchIds(true, SEARCH_MRS, mresultHandleMRIds );
72 function mresultCollectAdvIds() {
73 if(getOffset() != 0 && mresultTryCachedSearch()) return;
74 resultCollectSearchIds(false, SEARCH_MRS, mresultHandleMRIds );
78 function mresultCollectAdvMARCIds() {
79 if(!mresultTryCachedSearch()) {
80 var form = (getForm() == "all") ? null : getForm();
81 var req = new Request(FETCH_ADV_MARC_MRIDS,
82 JSON2js(getAdvTerm()), getLocation(), form );
83 req.callback(mresultHandleMRIds);
90 function mresultHandleMRIds(r) {
91 var res = r.getResultObject();
92 if(res.count != null) {
93 if( getOffset() == 0 ) HITCOUNT = res.count;
94 runEvt('result', 'hitCountReceived');
96 runEvt('result', 'idsReceived', res.ids);
101 function mresultSetRecords(idstruct) {
102 if(!idstruct) return;
104 for( var x = o; x < idstruct.length + o; x++ ) {
105 if( idstruct[x-o] != null ) {
106 var r = parseInt(idstruct[x - o][0]);
107 var ra = parseFloat(idstruct[x - o][1]);
108 var or = parseInt(idstruct[x - o][2]);
109 if(!isNull(r) && !isNaN(r)) records[x] = r;
110 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
111 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
116 if(getOffset() == 0) {
117 cookieManager.remove(COOKIE_IDS);
118 cookieManager.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
122 TOPRANK = ranks[getOffset()];
127 function mresultCollectRecords() {
128 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
130 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
131 if(isNull(records[x])) break;
132 if(isNaN(records[x])) continue;
133 var req = new Request(FETCH_MRMODS, records[x]);
135 req.request.userdata = i++;
137 /* wait at most 15 seconds for the mods rec to come back */
138 /* this needs more testing */
139 req.request.timeout(15);
140 req.request.abortCallback(
143 if(resultPageIsDone()) {
144 runEvt('result', 'allRecordsReceived', recordsCache);
145 unHideMe($('copyright_block'));
150 req.callback(mresultHandleMods);
155 function mresultHandleMods(r) {
156 var rec = r.getResultObject();
157 var pagePosition = r.userdata;
158 runEvt('result', 'recordReceived', rec, pagePosition, true);
159 if(rec) resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
160 if(resultPageIsDone()) {
161 runEvt('result', 'allRecordsReceived', recordsCache);
162 unHideMe($('copyright_block')); /* *** */