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