]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/mresult.js
wired ISBN and ISSN search for opac (currently go to metarecord page..)
[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() ) {
35                         if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
36                         if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvMARCIds();
37                         if(getAdvType() == ADVTYPE_ISBN ) mresultCollectAdvISBNIds();
38                         if(getAdvType() == ADVTYPE_ISSN ) mresultCollectAdvISSNIds();
39                 }
40                 else {
41                         mresultCollectIds(FETCH_MRIDS_FULL); 
42                         ADVTERM = "";
43                         ADVTYPE = "";
44                 }
45
46         } else  {
47                 if( getAdvTerm() && !getTerm() ) {
48                         if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
49                         if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvIds();
50                 }
51                 else {
52                         mresultCollectIds(FETCH_MRIDS);
53                         ADVTERM = "";
54                         ADVTYPE = "";
55                 }
56         }
57 }
58
59 /*
60 function mresultGetCount() {
61         var form = (getForm() == "all") ? null : getForm();
62         var req = new Request(FETCH_MRCOUNT, 
63                         getStype(), getTerm(), getLocation(), getDepth(), form );
64         req.callback(mresultHandleCount);
65         req.send();
66 }
67
68 function mresultHandleCount(r) {
69         HITCOUNT = parseInt(r.getResultObject());
70         alert('mresultHandleCount()');
71         runEvt('result', 'hitCountReceived');
72 }
73 */
74
75
76 function mresultLoadCachedSearch() {
77         if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
78                 var c = JSON2js(idsCookie.read(COOKIE_IDS));
79                 if(c) { records = c[0]; ranks = c[1]; }
80         }
81 }
82
83 function mresultTryCachedSearch() {
84         mresultLoadCachedSearch();
85         if(     getOffset() != 0 && records[getOffset()] != null && 
86                         records[resultFinalPageIndex()] != null) {
87
88                 runEvt('result', 'hitCountReceived');
89                 mresultCollectRecords(); 
90                 return true;
91         }
92         return false;
93 }
94
95
96 /* performs the actual search */
97 function mresultCollectIds(method) {
98         if(!mresultTryCachedSearch()) {
99                 var form = (getForm() == "all") ? null : getForm();
100                 var req = new Request(method, getStype(), getTerm(), 
101                         getLocation(), getDepth(), mresultPreCache, getOffset(), form );
102                 req.callback(mresultHandleMRIds);
103                 req.send();
104         }
105 }
106
107
108 function mresultCollectAdvIds() {
109         if(!mresultTryCachedSearch()) {
110                 var form = (getForm() == "all") ? null : getForm();
111                 var req = new Request(FETCH_ADV_MRIDS, 
112                         JSON2js(getAdvTerm()), getLocation(), form, mresultPreCache );
113                 req.callback(mresultHandleMRIds);
114                 req.send();
115         }
116 }
117
118 function mresultCollectAdvMARCIds() {
119         if(!mresultTryCachedSearch()) {
120                 var form = (getForm() == "all") ? null : getForm();
121                 var req = new Request(FETCH_ADV_MARC_MRIDS, 
122                         JSON2js(getAdvTerm()), getLocation(), form );
123                 req.callback(mresultHandleMRIds);
124                 req.send();
125         }
126 }
127
128 function mresultCollectAdvISBNIds() {
129         if(!mresultTryCachedSearch()) {
130                 var req = new Request(FETCH_ADV_ISBN_MRIDS, getAdvTerm() );
131                 req.callback(mresultHandleMRIds);
132                 req.send();
133         }
134 }
135
136 function mresultCollectAdvISSNIds() {
137         if(!mresultTryCachedSearch()) {
138                 var req = new Request(FETCH_ADV_ISSN_MRIDS, getAdvTerm() );
139                 req.callback(mresultHandleMRIds);
140                 req.send();
141         }
142 }
143
144
145
146 function mresultHandleMRIds(r) {
147         var res = r.getResultObject();
148
149         if(res.count != null) {
150                 if( getOffset() == 0 ) HITCOUNT = res.count;
151                 runEvt('result', 'hitCountReceived');
152         } 
153         runEvt('result', 'idsReceived', res.ids);
154 }
155
156 function mresultSetRecords(idstruct) {
157         if(!idstruct) return;
158         var o = getOffset();
159
160         for( var x = o; x < idstruct.length + o; x++ ) {
161                 if( idstruct[x-o] != null ) {
162                         var r = parseInt(idstruct[x - o][0]);
163                         var ra = parseFloat(idstruct[x - o][1]);
164                         var or = parseInt(idstruct[x - o][2]);
165                         if(!isNull(r) && !isNaN(r)) records[x] = r;
166                         if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
167                         if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
168                 }
169         }
170
171         if(getOffset() == 0) {
172                 idsCookie.remove(COOKIE_IDS);
173                 idsCookie.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
174                 //alert('Set cookies: ' + idsCookie.read(COOKIE_IDS) + ' : ' + idsCookie.read(COOKIE_IDS).length );
175         }
176
177         TOPRANK = ranks[getOffset()];
178 }
179
180 function mresultCollectRecords() {
181         if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
182         var i = 0;
183         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
184                 if(isNull(records[x])) break;
185                 if(isNaN(records[x])) continue;
186                 var req = new Request(FETCH_MRMODS, records[x]);
187                 req.request.userdata = i++;
188                 req.callback(mresultHandleMods);
189                 req.send();
190         }
191 }
192
193 function mresultHandleMods(r) {
194         var rec = r.getResultObject();
195         var pagePosition = r.userdata;
196         runEvt('result', 'recordReceived', rec, pagePosition, true);
197         resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
198 }
199
200