]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
73becea2510926cd63fe34d0eb7ce1eb22a3bdcd
[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                         runEvt('result', 'hitCountReceived');
61                         mresultCollectRecords(); 
62
63         } else {
64
65                 var form = (getForm() == "all") ? null : getForm();
66                 var req = new Request(method, getStype(), getTerm(), 
67                         getLocation(), getDepth(), 100, getOffset(), form );
68                 req.callback(mresultHandleMRIds);
69                 req.send();
70         }
71 }
72
73 function mresultHandleMRIds(r) {
74         var res = r.getResultObject();
75
76         if(res.count != null) {
77                 if( getOffset() == 0 ) HITCOUNT = res.count;
78                 runEvt('result', 'hitCountReceived');
79         } 
80         runEvt('result', 'idsReceived', res.ids);
81 }
82
83 function mresultSetRecords(idstruct) {
84         if(!idstruct) return;
85         var o = getOffset();
86         for( var x = o; x < idstruct.length + o; x++ ) {
87                 if(idstruct[x-o] == null) break;
88                 records[x] = parseInt(idstruct[x - o][0]);
89                 ranks[x] = parseFloat(idstruct[x - o][1]);
90                 onlyrecord[x] = parseInt(idstruct[x - o][2]);
91         }
92         idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
93         idsCookie.write();
94         TOPRANK = ranks[getOffset()];
95 }
96
97 function mresultCollectRecords() {
98         runEvt("result", "preCollectRecords");
99         var i = 0;
100         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
101                 if(isNull(records[x])) break;
102                 if(isNaN(records[x])) continue;
103                 var req = new Request(FETCH_MRMODS, records[x]);
104                 req.request.userdata = i++;
105                 req.callback(mresultHandleMods);
106                 req.send();
107         }
108 }
109
110 function mresultHandleMods(r) {
111         var rec = r.getResultObject();
112         var pagePosition = r.userdata;
113         runEvt('result', 'recordReceived', rec, pagePosition, true);
114         resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
115 }
116
117