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