testing commit, please ignore
[kcls-web.git] / opac / skin / login1 / js / mresult.js
1 //var records = {};
2 var records = [];
3 var ranks = [];
4 var onlyrecord = {};
5 var table;
6 var mresultPreCache = 200;
7 var searchTimer;
8
9 attachEvt("common", "unload", mresultUnload);
10 attachEvt("common", "run", mresultDoSearch);
11 attachEvt("result", "idsReceived", mresultSetRecords); 
12 attachEvt("result", "idsReceived", mresultCollectRecords); 
13
14 function mresultUnload() { removeChildren(table); table = null;}
15
16 hideMe($('copyright_block')); 
17
18 function mresultDoSearch() {
19
20
21         TFORM = null; /* clear the rresult tform var so it's not propogated */
22
23         swapCanvas($('loading_alt'));
24         table = G.ui.result.main_table;
25
26     var holdTarget = new CGI().param('hold_target');
27     if(holdTarget != null) {
28         mresultHandlePlaceHold(holdTarget);
29         return;
30     }
31
32
33         while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  
34                 table.appendChild(G.ui.result.row_template.cloneNode(true));
35
36         if( (getSearches() || getAdvTerm()) && !getTerm() ) {
37                 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
38
39         } else {
40                 _mresultCollectIds(); 
41                 ADVTERM = "";
42                 ADVTYPE = "";
43         }
44 }
45
46 function _mresultCollectIds() { 
47         resultCollectSearchIds(true, SEARCH_MRS_QUERY, mresultHandleMRIds ); 
48 }
49
50 function mresultCollectAdvIds() { 
51         resultCollectSearchIds(false, SEARCH_MRS_QUERY, mresultHandleMRIds ); 
52 }
53
54
55 function mresultHandleMRIds(r) {
56         var res = r.getResultObject();
57     resultCompiledSearch = res.compiled_search;
58     cookieManager.write(COOKIE_SEARCH, js2JSON(res.compiled_search), -1);
59         if(res.count != null) {
60                 if( getOffset() == 0 ) HITCOUNT = res.count;
61                 runEvt('result', 'hitCountReceived');
62         } 
63         runEvt('result', 'idsReceived', res.ids);
64 }
65
66
67
68 function mresultSetRecords(idstruct) {
69         if(!idstruct) return;
70         var o = getOffset();
71         for( var x = o; x < idstruct.length + o; x++ ) {
72                 if( idstruct[x-o] != null ) {
73                         var r = parseInt(idstruct[x - o][0]);
74                         var ra = parseFloat(idstruct[x - o][1]);
75                         var or = parseInt(idstruct[x - o][2]);
76                         if(!isNull(r) && !isNaN(r)) records[x] = r;
77                         if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
78                         if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
79                 }
80         }
81
82         TOPRANK = ranks[getOffset()];
83 }
84
85
86
87 var recsReceivedCalled = false;
88 function mresultCollectRecords() {
89         if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
90         var i = 0;
91         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
92                 if(isNull(records[x])) break;
93                 if(isNaN(records[x])) continue;
94                 var req = new Request(FETCH_MRMODS, records[x]);
95
96                 req.request.userdata = i++;
97
98                 /* wait at most 10 seconds for the mods rec to come back */
99                 /* this needs more testing  */
100                 req.request.timeout(10); 
101                 req.request.abortCallback(
102                         function(){
103                                 recordsHandled++;
104                 if(resultPageIsDone()  && !recsReceivedCalled) {
105                     recsReceivedCalled = true;
106                                         runEvt('result', 'allRecordsReceived', recordsCache);
107                                         unHideMe($('copyright_block'));
108                                 }
109                         }
110                 );
111
112                 req.callback(mresultHandleMods);
113                 req.send();
114         }
115 }
116
117 function mresultHandleMods(r) {
118         var rec = r.getResultObject();
119         var pagePosition = r.userdata;
120         runEvt('result', 'recordReceived', rec, pagePosition, true);
121         if(rec) resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
122         if(resultPageIsDone()) {
123                 runEvt('result', 'allRecordsReceived', recordsCache);
124                 unHideMe($('copyright_block')); /* *** */
125         }
126 }
127
128 function mresultHandlePlaceHold(target) {
129     function reload() {
130         location.href = location.href.replace(/&hold_target=\d+/, '');
131     }
132     attachEvt("common", "holdUpdated", reload);
133     attachEvt("common", "holdUpdateCanceled", reload);
134     attachEvt("common", "loginCanceled", reload);
135     holdsDrawEditor({record:target, type: 'M'});
136 }
137
138
139