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