]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
378090391a8c5bf9fe745cf071d53cdf44995c72
[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         //      mresultGetCount(); 
24                 mresultCollectIds(FETCH_MRIDS_FULL); 
25         } else { 
26                 runEvt('result', 'hitCountReceived');
27                 mresultCollectIds(FETCH_MRIDS);
28         }
29 }
30
31 function mresultGetCount() {
32         var form = (getForm() == "all") ? null : getForm();
33         var req = new Request(FETCH_MRCOUNT, 
34                         getStype(), getTerm(), getLocation(), getDepth(), form );
35         req.callback(mresultHandleCount);
36         req.send();
37 }
38
39 function mresultHandleCount(r) {
40         HITCOUNT = parseInt(r.getResultObject());
41         runEvt('result', 'hitCountReceived');
42 }
43
44
45 /* performs the actual search */
46 function mresultCollectIds(method) {
47
48         if(getOffset() == 0) {
49                 idsCookie.put(COOKIE_IDS,"");
50                 idsCookie.write();
51
52         } else {
53                 var c = JSON2js(idsCookie.get(COOKIE_IDS));
54                 if(c && c.recs) { records = c.recs; ranks = c.ranks; } 
55         }
56
57         if(     getOffset() != 0 && 
58                         records[getOffset()] != null && 
59                         records[resultFinalPageIndex()] != null) {
60                         mresultCollectRecords(); 
61
62         } else {
63
64                 var form = (getForm() == "all") ? null : getForm();
65                 var req = new Request(method, getStype(), getTerm(), 
66                         getLocation(), getDepth(), getDisplayCount() * 5, getOffset(), form );
67                 req.callback(mresultHandleMRIds);
68                 req.send();
69         }
70 }
71
72 function mresultHandleMRIds(r) {
73         var res = r.getResultObject();
74
75         if(res.count != null) {
76                 HITCOUNT = res.count;
77                 runEvt('result', 'hitCountReceived');
78         } 
79         runEvt('result', 'idsReceived', res.ids);
80 }
81
82 function mresultSetRecords(idstruct) {
83         var o = getOffset();
84         for( var x = o; x < idstruct.length + o; x++ ) {
85                 if(idstruct[x-o] == null) break;
86                 records[x] = parseInt(idstruct[x - o][0]);
87                 ranks[x] = parseFloat(idstruct[x - o][1]);
88                 onlyrecord[x] = parseInt(idstruct[x - o][2]);
89         }
90         idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
91         idsCookie.write();
92         TOPRANK = ranks[getOffset()];
93 }
94
95 function mresultCollectRecords() {
96         runEvt("result", "preCollectRecords");
97         var i = 0;
98         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
99                 if(isNull(records[x])) break;
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