]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
cdd07f1d50fbe4e8eeb53a4be8584e87ae40f953
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / mresult.js
1 var records = {};
2 var ranks = {};
3 var onlyrecord = {};
4 var table;
5 var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
6
7 attachEvt("common", "unload", mresultUnload);
8 attachEvt("common", "run", mresultDoSearch);
9 attachEvt("result", "idsReceived", mresultSetRecords); 
10 attachEvt("result", "idsReceived", mresultCollectRecords); 
11
12
13 function mresultUnload() { removeChildren(table); table = null;}
14
15 function mresultDoSearch() {
16
17         table = G.ui.result.main_table;
18
19         while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  /* add an extra row so IE and safari won't complain */
20                 table.appendChild(G.ui.result.row_template.cloneNode(true));
21
22         if(getOffset() == 0 || getHitCount() == null ) 
23                 mresultCollectIds(FETCH_MRIDS_FULL); 
24         else  
25                 mresultCollectIds(FETCH_MRIDS);
26 }
27
28 function mresultGetCount() {
29         var form = (getForm() == "all") ? null : getForm();
30         var req = new Request(FETCH_MRCOUNT, 
31                         getStype(), getTerm(), getLocation(), getDepth(), form );
32         req.callback(mresultHandleCount);
33         req.send();
34 }
35
36 function mresultHandleCount(r) {
37         HITCOUNT = parseInt(r.getResultObject());
38         runEvt('result', 'hitCountReceived');
39 }
40
41
42 /* performs the actual search */
43 function mresultCollectIds(method) {
44
45         if(getOffset() == 0) {
46                 idsCookie.put(COOKIE_IDS,"[]");
47                 idsCookie.write();
48
49         } else {
50                 var c = JSON2js(idsCookie.get(COOKIE_IDS));
51                 if(c && c.recs) { records = c.recs; ranks = c.ranks; } 
52         }
53
54         if(     getOffset() != 0 && 
55                         records[getOffset()] != null && 
56                         records[resultFinalPageIndex()] != null) {
57                         runEvt('result', 'hitCountReceived');
58                         mresultCollectRecords(); 
59
60         } else {
61
62                 var form = (getForm() == "all") ? null : getForm();
63                 var req = new Request(method, getStype(), getTerm(), 
64                         getLocation(), getDepth(), 100, getOffset(), form );
65                 req.callback(mresultHandleMRIds);
66                 req.send();
67         }
68 }
69
70 function mresultHandleMRIds(r) {
71         var res = r.getResultObject();
72
73         if(res.count != null) {
74                 if( getOffset() == 0 ) HITCOUNT = res.count;
75                 runEvt('result', 'hitCountReceived');
76         } 
77         runEvt('result', 'idsReceived', res.ids);
78 }
79
80 function mresultSetRecords(idstruct) {
81         if(!idstruct) return;
82         var o = getOffset();
83         for( var x = o; x < idstruct.length + o; x++ ) {
84                 if(idstruct[x-o] == null) break;
85                 records[x] = parseInt(idstruct[x - o][0]);
86                 ranks[x] = parseFloat(idstruct[x - o][1]);
87                 onlyrecord[x] = parseInt(idstruct[x - o][2]);
88         }
89         idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
90         idsCookie.write();
91         TOPRANK = ranks[getOffset()];
92 }
93
94 function mresultCollectRecords() {
95         runEvt("result", "preCollectRecords");
96         var i = 0;
97         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
98                 if(isNull(records[x])) break;
99                 if(isNaN(records[x])) continue;
100                 var req = new Request(FETCH_MRMODS, records[x]);
101                 req.request.userdata = i++;
102                 req.callback(mresultHandleMods);
103                 req.send();
104         }
105 }
106
107 function mresultHandleMods(r) {
108         var rec = r.getResultObject();
109         var pagePosition = r.userdata;
110         runEvt('result', 'recordReceived', rec, pagePosition, true);
111         resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
112 }
113
114