]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
some stubs for future facet UI support
[working/Evergreen.git] / Open-ILS / web / 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 = result.facet_key;
51     resultCompiledSearch = res.compiled_search;
52     cookieManager.write(COOKIE_SEARCH, js2JSON(res.compiled_search), -1);
53         if(res.count != null) {
54                 if( getOffset() == 0 ) HITCOUNT = res.count;
55                 runEvt('result', 'hitCountReceived');
56         } 
57         runEvt('result', 'idsReceived', res.ids);
58 }
59
60
61
62 function mresultSetRecords(idstruct) {
63         if(!idstruct) return;
64         var o = getOffset();
65         for( var x = o; x < idstruct.length + o; x++ ) {
66                 if( idstruct[x-o] != null ) {
67                         var r = parseInt(idstruct[x - o][0]);
68                         var ra = parseFloat(idstruct[x - o][1]);
69                         var or = parseInt(idstruct[x - o][2]);
70                         if(!isNull(r) && !isNaN(r)) records[x] = r;
71                         if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
72                         if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
73                 }
74         }
75
76         TOPRANK = ranks[getOffset()];
77 }
78
79
80
81 function mresultCollectRecords() {
82         if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
83         var i = 0;
84         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
85                 if(isNull(records[x])) break;
86                 if(isNaN(records[x])) continue;
87                 var req = new Request(FETCH_MRMODS, records[x]);
88
89                 req.request.userdata = i++;
90
91                 /* wait at most 10 seconds for the mods rec to come back */
92                 /* this needs more testing  */
93                 req.request.timeout(10); 
94                 req.request.abortCallback(
95                         function(){
96                                 recordsHandled++;
97                                 if(resultPageIsDone()) {
98                                         runEvt('result', 'allRecordsReceived', recordsCache);
99                                         unHideMe($('copyright_block'));
100                                 }
101                         }
102                 );
103
104                 req.callback(mresultHandleMods);
105                 req.send();
106         }
107 }
108
109 function mresultHandleMods(r) {
110         var rec = r.getResultObject();
111         var pagePosition = r.userdata;
112         runEvt('result', 'recordReceived', rec, pagePosition, true);
113         if(rec) resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
114         if(resultPageIsDone()) {
115                 runEvt('result', 'allRecordsReceived', recordsCache);
116                 unHideMe($('copyright_block')); /* *** */
117         }
118 }
119
120
121
122