]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
f632e3b18dec6fca25cab8f2ec848c35f96f8231
[working/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 rowtemplate;
6 var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
7
8 attachEvt("common", "unload", mresultUnload);
9 attachEvt("common", "run", mresultDoSearch);
10 attachEvt("mresult", "idsReceived", mresultSetRecords); 
11 attachEvt("mresult", "idsReceived", mresultCollectRecords); 
12
13
14 function mresultUnload() { removeChildren(table); table = null;}
15
16 function mresultDoSearch() {
17
18         table = G.ui.result.main_table;
19
20         hideMe(G.ui.result.row_template);
21         while( table.parentNode.rows.length <= getDisplayCount() )  /* add an extra row so IE and safari won't complain */
22                 hideMe(table.appendChild(G.ui.result.row_template.cloneNode(true)));
23
24         if(getOffset() == 0 || getHitCount() == null ) {
25         //      mresultGetCount(); 
26                 mresultCollectIds(FETCH_MRIDS_FULL); 
27         } else { 
28                 runEvt('result', 'hitCountReceived');
29                 mresultCollectIds(FETCH_MRIDS);
30         }
31 }
32
33 function mresultGetCount() {
34         var form = (getForm() == "all") ? null : getForm();
35         var req = new Request(FETCH_MRCOUNT, 
36                         getStype(), getTerm(), getLocation(), getDepth(), form );
37         req.callback(mresultHandleCount);
38         req.send();
39 }
40
41 function mresultHandleCount(r) {
42         HITCOUNT = parseInt(r.getResultObject());
43         runEvt('result', 'hitCountReceived');
44 }
45
46
47 /* performs the actual search */
48 function mresultCollectIds(method) {
49
50         if(getOffset() == 0) {
51                 idsCookie.put(COOKIE_IDS,"");
52                 idsCookie.write();
53
54         } else {
55                 var c = JSON2js(idsCookie.get(COOKIE_IDS));
56                 if(c && c.recs) { records = c.recs; ranks = c.ranks; } 
57         }
58
59         if(     getOffset() != 0 && 
60                         records[getOffset()] != null && 
61                         records[resultFinalPageIndex()] != null) {
62                         mresultCollectRecords(); 
63
64         } else {
65
66                 var form = (getForm() == "all") ? null : getForm();
67                 var req = new Request(method, getStype(), getTerm(), 
68                         getLocation(), getDepth(), getDisplayCount() * 10, getOffset(), form );
69                 req.callback(mresultHandleMRIds);
70                 req.send();
71         }
72 }
73
74 function mresultHandleMRIds(r) {
75         var res = r.getResultObject();
76
77         if(res.count != null) {
78                 HITCOUNT = res.count;
79                 runEvt('result', 'hitCountReceived');
80         } 
81         runEvt('mresult', 'idsReceived', res.ids);
82 }
83
84 function mresultSetRecords(idstruct) {
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][4]);
91         }
92         idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
93         idsCookie.write();
94 }
95
96 function mresultCollectRecords() {
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