6 var mresultPreCache = 200;
7 //var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
9 var idsCookie = new HTTP.Cookies();
12 attachEvt("common", "unload", mresultUnload);
13 attachEvt("common", "run", mresultDoSearch);
14 attachEvt("result", "idsReceived", mresultSetRecords);
15 attachEvt("result", "idsReceived", mresultCollectRecords);
18 function mresultUnload() { removeChildren(table); table = null;}
20 function mresultDoSearch() {
22 if(getOffset() == 0) {
23 swapCanvas($('loading_alt'));
24 searchTimer = new Timer('searchTimer',$('loading_alt_span'));
28 table = G.ui.result.main_table;
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));
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();
41 mresultCollectIds(FETCH_MRIDS_FULL);
47 if( getAdvTerm() && !getTerm() ) {
48 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
49 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvIds();
52 mresultCollectIds(FETCH_MRIDS);
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);
68 function mresultHandleCount(r) {
69 HITCOUNT = parseInt(r.getResultObject());
70 alert('mresultHandleCount()');
71 runEvt('result', 'hitCountReceived');
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]; }
83 function mresultTryCachedSearch() {
84 mresultLoadCachedSearch();
85 if( getOffset() != 0 && records[getOffset()] != null &&
86 records[resultFinalPageIndex()] != null) {
88 runEvt('result', 'hitCountReceived');
89 mresultCollectRecords();
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);
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);
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);
128 function mresultCollectAdvISBNIds() {
129 if(!mresultTryCachedSearch()) {
130 var req = new Request(FETCH_ADV_ISBN_MRIDS, getAdvTerm() );
131 req.callback(mresultHandleMRIds);
136 function mresultCollectAdvISSNIds() {
137 if(!mresultTryCachedSearch()) {
138 var req = new Request(FETCH_ADV_ISSN_MRIDS, getAdvTerm() );
139 req.callback(mresultHandleMRIds);
146 function mresultHandleMRIds(r) {
147 var res = r.getResultObject();
149 if(res.count != null) {
150 if( getOffset() == 0 ) HITCOUNT = res.count;
151 runEvt('result', 'hitCountReceived');
153 runEvt('result', 'idsReceived', res.ids);
156 function mresultSetRecords(idstruct) {
157 if(!idstruct) return;
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;
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 );
177 TOPRANK = ranks[getOffset()];
180 function mresultCollectRecords() {
181 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
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);
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);