]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
patch from Bill Ott for a form-reset button to clear the advanced search inputs....
[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
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         while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  
27                 table.appendChild(G.ui.result.row_template.cloneNode(true));
28
29         if( (getSearches() || getAdvTerm()) && !getTerm() ) {
30                 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
31
32         } else {
33                 _mresultCollectIds(); 
34                 ADVTERM = "";
35                 ADVTYPE = "";
36         }
37 }
38
39 function _mresultCollectIds() { 
40         resultCollectSearchIds(true, SEARCH_MRS_QUERY, mresultHandleMRIds ); 
41 }
42
43 function mresultCollectAdvIds() { 
44         resultCollectSearchIds(false, SEARCH_MRS_QUERY, mresultHandleMRIds ); 
45 }
46
47
48 function mresultHandleMRIds(r) {
49         var res = r.getResultObject();
50     resultCompiledSearch = res.compiled_search;
51     cookieManager.write(COOKIE_SEARCH, js2JSON(res.compiled_search), -1);
52         if(res.count != null) {
53                 if( getOffset() == 0 ) HITCOUNT = res.count;
54                 runEvt('result', 'hitCountReceived');
55         } 
56         runEvt('result', 'idsReceived', res.ids);
57 }
58
59
60
61 function mresultSetRecords(idstruct) {
62         if(!idstruct) return;
63         var o = getOffset();
64         for( var x = o; x < idstruct.length + o; x++ ) {
65                 if( idstruct[x-o] != null ) {
66                         var r = parseInt(idstruct[x - o][0]);
67                         var ra = parseFloat(idstruct[x - o][1]);
68                         var or = parseInt(idstruct[x - o][2]);
69                         if(!isNull(r) && !isNaN(r)) records[x] = r;
70                         if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
71                         if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
72                 }
73         }
74
75         TOPRANK = ranks[getOffset()];
76 }
77
78
79
80 function mresultCollectRecords() {
81         if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
82         var i = 0;
83         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
84                 if(isNull(records[x])) break;
85                 if(isNaN(records[x])) continue;
86                 var req = new Request(FETCH_MRMODS, records[x]);
87
88                 req.request.userdata = i++;
89
90                 /* wait at most 10 seconds for the mods rec to come back */
91                 /* this needs more testing  */
92                 req.request.timeout(10); 
93                 req.request.abortCallback(
94                         function(){
95                                 recordsHandled++;
96                                 if(resultPageIsDone()) {
97                                         runEvt('result', 'allRecordsReceived', recordsCache);
98                                         unHideMe($('copyright_block'));
99                                 }
100                         }
101                 );
102
103                 req.callback(mresultHandleMods);
104                 req.send();
105         }
106 }
107
108 function mresultHandleMods(r) {
109         var rec = r.getResultObject();
110         var pagePosition = r.userdata;
111         runEvt('result', 'recordReceived', rec, pagePosition, true);
112         if(rec) resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
113         if(resultPageIsDone()) {
114                 runEvt('result', 'allRecordsReceived', recordsCache);
115                 unHideMe($('copyright_block')); /* *** */
116         }
117 }
118
119
120
121