]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
2fdbad7e1922def8b1eafaed971bb75bb9bbec8c
[working/Evergreen.git] / Open-ILS / web / opac / skin / default / js / mresult.js
1 var records = {};
2 var ranks = {};
3 var table;
4 var rowtemplate;
5 var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
6
7 attachEvt("common", "unload", mresultUnload);
8 attachEvt("common", "run", mresultDoSearch);
9 attachEvt("mresult", "idsReceived", mresultSetRecords); 
10 attachEvt("mresult", "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         hideMe(G.ui.result.row_template);
20         while( table.parentNode.rows.length <= getDisplayCount() )  /* add an extra row so IE and safari won't complain */
21                 hideMe(table.appendChild(G.ui.result.row_template.cloneNode(true)));
22
23         if(getOffset() == 0 || getHitCount() == null ) {
24         //      mresultGetCount(); 
25                 mresultCollectIds(FETCH_MRIDS_FULL); 
26         } else { 
27                 runEvt('result', 'hitCountReceived');
28                 mresultCollectIds(FETCH_MRIDS);
29         }
30 }
31
32 function mresultGetCount() {
33         var form = (getForm() == "all") ? null : getForm();
34         var req = new Request(FETCH_MRCOUNT, 
35                         getStype(), getTerm(), getLocation(), getDepth(), form );
36         req.callback(mresultHandleCount);
37         req.send();
38 }
39
40 function mresultHandleCount(r) {
41         HITCOUNT = parseInt(r.getResultObject());
42         runEvt('result', 'hitCountReceived');
43 }
44
45
46 /* performs the actual search */
47 function mresultCollectIds(method) {
48
49         if(getOffset() == 0) {
50                 idsCookie.put(COOKIE_IDS,"");
51                 idsCookie.write();
52
53         } else {
54                 var c = JSON2js(idsCookie.get(COOKIE_IDS));
55                 if(c && c.recs) { records = c.recs; ranks = c.ranks; } 
56         }
57
58         if(     getOffset() != 0 && 
59                         records[getOffset()] != null && 
60                         records[resultFinalPageIndex()] != null) {
61                         mresultCollectRecords(); 
62
63         } else {
64
65                 var req = new Request(method, getStype(), getTerm(), 
66                         getLocation(), getDepth(), getDisplayCount() * 10, getOffset(), getForm() );
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('mresult', '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         }
89         idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
90         idsCookie.write();
91 }
92
93 function mresultCollectRecords() {
94         var i = 0;
95         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
96                 if(isNull(records[x])) break;
97                 var req = new Request(FETCH_MRMODS, records[x]);
98                 req.request.userdata = i++;
99                 req.callback(mresultHandleMods);
100                 req.send();
101         }
102 }
103
104 function mresultHandleMods(r) {
105         var rec = r.getResultObject();
106         var pagePosition = r.userdata;
107         runEvt('result', 'recordReceived', rec, pagePosition, true);
108         resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
109 }
110
111