]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
JSPAC: remove index.xml from apache example configs and examples in documentation
[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     var holdTarget = new CGI().param('hold_target');
28     if(holdTarget != null) {
29         mresultHandlePlaceHold(holdTarget);
30         return;
31     }
32
33
34         while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  
35                 table.appendChild(G.ui.result.row_template.cloneNode(true));
36
37         if( (getSearches() || getAdvTerm()) && !getTerm() ) {
38                 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
39
40         } else {
41                 _mresultCollectIds(); 
42                 ADVTERM = "";
43                 ADVTYPE = "";
44         }
45 }
46
47 function _mresultCollectIds() { 
48         resultCollectSearchIds(true, SEARCH_MRS_QUERY, mresultHandleMRIds ); 
49 }
50
51 function mresultCollectAdvIds() { 
52         resultCollectSearchIds(false, SEARCH_MRS_QUERY, mresultHandleMRIds ); 
53 }
54
55 function mresultHandleMRIds(r) {
56         var res = r.getResultObject();
57     resultFacetKey = res.facet_key;
58     resultCompiledSearch = res.compiled_search;
59     dojo.require('dojo.cookie');
60     dojo.cookie(COOKIE_SEARCH, js2JSON(res.compiled_search));
61         if(res.count != null) {
62                 if( getOffset() == 0 ) HITCOUNT = res.count;
63                 runEvt('result', 'hitCountReceived');
64         } 
65         runEvt('result', 'idsReceived', res.ids);
66 }
67
68
69
70 function mresultSetRecords(idstruct) {
71         if(!idstruct) return;
72         var o = getOffset();
73         for( var x = o; x < idstruct.length + o; x++ ) {
74                 if( idstruct[x-o] != null ) {
75                         var r = parseInt(idstruct[x - o][0]);
76                         var ra = parseFloat(idstruct[x - o][1]);
77                         var or = parseInt(idstruct[x - o][2]);
78                         if(!isNull(r) && !isNaN(r)) records[x] = r;
79                         if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
80                         if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
81                 }
82         }
83
84         TOPRANK = ranks[getOffset()];
85 }
86
87
88
89 var recsReceivedCalled = false;
90 function mresultCollectRecords() {
91         if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
92         var i = 0;
93         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
94                 if(isNull(records[x])) break;
95                 if(isNaN(records[x])) continue;
96                 var req = new Request(FETCH_MRMODS, records[x]);
97
98                 req.request.userdata = i++;
99
100                 /* wait at most 10 seconds for the mods rec to come back */
101                 /* this needs more testing  */
102                 req.request.timeout(10); 
103                 req.request.abortCallback(
104                         function(){
105                                 recordsHandled++;
106                                 if(resultPageIsDone()  && !recsReceivedCalled) {
107                     recsReceivedCalled = true;
108                                         runEvt('result', 'allRecordsReceived', recordsCache);
109                                         unHideMe($('copyright_block'));
110                                 }
111                         }
112                 );
113
114                 req.callback(mresultHandleMods);
115                 req.send();
116         }
117 }
118
119 function mresultHandleMods(r) {
120         var rec = r.getResultObject();
121         var pagePosition = r.userdata;
122         runEvt('result', 'recordReceived', rec, pagePosition, true);
123         if(rec) resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
124         if(resultPageIsDone()) {
125                 runEvt('result', 'allRecordsReceived', recordsCache);
126                 unHideMe($('copyright_block')); /* *** */
127         }
128 }
129
130
131 function mresultHandlePlaceHold(target) {
132     function reload() {
133         location.href = location.href.replace(/&hold_target=\d+/, '');
134     }
135     attachEvt("common", "holdUpdated", reload);
136     attachEvt("common", "holdUpdateCanceled", reload);
137     attachEvt("common", "loginCanceled", reload);
138     holdsDrawEditor({record:target, type: 'M'});
139 }
140
141