]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
added search interface for the advanced search, marc search, and isbn search
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / mresult.js
1 //var records = {};
2 var records = [];
3 var ranks = [];
4 var onlyrecord = {};
5 var table;
6 var mresultPreCache = 200;
7 //var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
8 //var idsCookie;
9 var idsCookie = new HTTP.Cookies();
10 var searchTimer;
11
12 attachEvt("common", "unload", mresultUnload);
13 attachEvt("common", "run", mresultDoSearch);
14 attachEvt("result", "idsReceived", mresultSetRecords); 
15 attachEvt("result", "idsReceived", mresultCollectRecords); 
16
17
18 function mresultUnload() { removeChildren(table); table = null;}
19
20 function mresultDoSearch() {
21
22         if(getOffset() == 0) {
23                 swapCanvas($('loading_alt'));
24                 searchTimer = new Timer('searchTimer',$('loading_alt_span'));
25                 searchTimer.start();
26         }
27
28         table = G.ui.result.main_table;
29
30         while( table.parentNode.rows.length <= (getDisplayCount() + 1) )  /* add an extra row so IE and safari won't complain */
31                 table.appendChild(G.ui.result.row_template.cloneNode(true));
32
33         if(getOffset() == 0 || getHitCount() == null ) {
34                 if( getAdvTerm() && !getTerm() ) mresultCollectAdvIds(1);
35                 else mresultCollectIds(FETCH_MRIDS_FULL); 
36
37         } else  {
38                 if( getAdvTerm() && !getTerm()) mresultCollectAdvIds();
39                 else mresultCollectIds(FETCH_MRIDS);
40         }
41 }
42
43 /*
44 function mresultGetCount() {
45         var form = (getForm() == "all") ? null : getForm();
46         var req = new Request(FETCH_MRCOUNT, 
47                         getStype(), getTerm(), getLocation(), getDepth(), form );
48         req.callback(mresultHandleCount);
49         req.send();
50 }
51
52 function mresultHandleCount(r) {
53         HITCOUNT = parseInt(r.getResultObject());
54         alert('mresultHandleCount()');
55         runEvt('result', 'hitCountReceived');
56 }
57 */
58
59
60 /* performs the actual search */
61 function mresultCollectIds(method) {
62
63         if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
64                 //alert('cached: ' + idsCookie.read(COOKIE_IDS));
65                 var c = JSON2js(idsCookie.read(COOKIE_IDS));
66                 if(c) { records = c[0]; ranks = c[1]; }
67         }
68
69         if(     getOffset() != 0 && 
70                         records[getOffset()] != null && 
71                         records[resultFinalPageIndex()] != null) {
72                         //alert('we have cookies...  offset : ' + getOffset() );
73                         runEvt('result', 'hitCountReceived');
74                         mresultCollectRecords(); 
75
76         } else {
77
78                 var form = (getForm() == "all") ? null : getForm();
79                 var req = new Request(method, getStype(), getTerm(), 
80                         getLocation(), getDepth(), mresultPreCache, getOffset(), form );
81                 req.callback(mresultHandleMRIds);
82                 req.send();
83         }
84 }
85
86
87 function mresultCollectAdvIds() {
88
89         if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
90                 var c = JSON2js(idsCookie.read(COOKIE_IDS));
91                 if(c) { records = c[0]; ranks = c[1]; }
92         }
93
94         if(     getOffset() != 0 && 
95                         records[getOffset()] != null && 
96                         records[resultFinalPageIndex()] != null) {
97                         runEvt('result', 'hitCountReceived');
98                         mresultCollectRecords(); 
99
100         } else {
101
102                 var form = (getForm() == "all") ? null : getForm();
103                 var req = new Request(FETCH_ADV_MRIDS, 
104                         JSON2js(getAdvTerm()), getLocation(), form, mresultPreCache );
105                 req.callback(mresultHandleMRIds);
106                 req.send();
107         }
108 }
109
110
111
112 function mresultHandleMRIds(r) {
113         var res = r.getResultObject();
114
115         if(res.count != null) {
116                 if( getOffset() == 0 ) HITCOUNT = res.count;
117                 runEvt('result', 'hitCountReceived');
118         } 
119         runEvt('result', 'idsReceived', res.ids);
120 }
121
122 function mresultSetRecords(idstruct) {
123         if(!idstruct) return;
124         var o = getOffset();
125
126         for( var x = o; x < idstruct.length + o; x++ ) {
127                 if( idstruct[x-o] != null ) {
128                         var r = parseInt(idstruct[x - o][0]);
129                         var ra = parseFloat(idstruct[x - o][1]);
130                         var or = parseInt(idstruct[x - o][2]);
131                         if(!isNull(r) && !isNaN(r)) records[x] = r;
132                         if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
133                         if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
134                 }
135         }
136
137         if(getOffset() == 0) {
138                 idsCookie.remove(COOKIE_IDS);
139                 idsCookie.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
140                 //alert('Set cookies: ' + idsCookie.read(COOKIE_IDS) + ' : ' + idsCookie.read(COOKIE_IDS).length );
141         }
142
143         TOPRANK = ranks[getOffset()];
144 }
145
146 function mresultCollectRecords() {
147         if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
148         var i = 0;
149         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
150                 if(isNull(records[x])) break;
151                 if(isNaN(records[x])) continue;
152                 var req = new Request(FETCH_MRMODS, records[x]);
153                 req.request.userdata = i++;
154                 req.callback(mresultHandleMods);
155                 req.send();
156         }
157 }
158
159 function mresultHandleMods(r) {
160         var rec = r.getResultObject();
161         var pagePosition = r.userdata;
162         runEvt('result', 'recordReceived', rec, pagePosition, true);
163         resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
164 }
165
166