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();
38 else mresultCollectIds(FETCH_MRIDS_FULL);
41 if( getAdvTerm() && !getTerm() ) {
42 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
43 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvIds();
45 else mresultCollectIds(FETCH_MRIDS);
50 function mresultGetCount() {
51 var form = (getForm() == "all") ? null : getForm();
52 var req = new Request(FETCH_MRCOUNT,
53 getStype(), getTerm(), getLocation(), getDepth(), form );
54 req.callback(mresultHandleCount);
58 function mresultHandleCount(r) {
59 HITCOUNT = parseInt(r.getResultObject());
60 alert('mresultHandleCount()');
61 runEvt('result', 'hitCountReceived');
66 function mresultLoadCachedSearch() {
67 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
68 var c = JSON2js(idsCookie.read(COOKIE_IDS));
69 if(c) { records = c[0]; ranks = c[1]; }
73 function mresultTryCachedSearch() {
74 mresultLoadCachedSearch();
75 if( getOffset() != 0 && records[getOffset()] != null &&
76 records[resultFinalPageIndex()] != null) {
78 runEvt('result', 'hitCountReceived');
79 mresultCollectRecords();
86 /* performs the actual search */
87 function mresultCollectIds(method) {
88 if(!mresultTryCachedSearch()) {
89 var form = (getForm() == "all") ? null : getForm();
90 var req = new Request(method, getStype(), getTerm(),
91 getLocation(), getDepth(), mresultPreCache, getOffset(), form );
92 req.callback(mresultHandleMRIds);
98 function mresultCollectAdvIds() {
99 if(!mresultTryCachedSearch()) {
100 var form = (getForm() == "all") ? null : getForm();
101 var req = new Request(FETCH_ADV_MRIDS,
102 JSON2js(getAdvTerm()), getLocation(), form, mresultPreCache );
103 req.callback(mresultHandleMRIds);
108 function mresultCollectAdvMARCIds() {
109 if(!mresultTryCachedSearch()) {
110 var form = (getForm() == "all") ? null : getForm();
111 var req = new Request(FETCH_ADV_MARC_MRIDS,
112 JSON2js(getAdvTerm()), getLocation(), form );
113 req.callback(mresultHandleMRIds);
120 function mresultHandleMRIds(r) {
121 var res = r.getResultObject();
123 if(res.count != null) {
124 if( getOffset() == 0 ) HITCOUNT = res.count;
125 runEvt('result', 'hitCountReceived');
127 runEvt('result', 'idsReceived', res.ids);
130 function mresultSetRecords(idstruct) {
131 if(!idstruct) return;
134 for( var x = o; x < idstruct.length + o; x++ ) {
135 if( idstruct[x-o] != null ) {
136 var r = parseInt(idstruct[x - o][0]);
137 var ra = parseFloat(idstruct[x - o][1]);
138 var or = parseInt(idstruct[x - o][2]);
139 if(!isNull(r) && !isNaN(r)) records[x] = r;
140 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
141 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
145 if(getOffset() == 0) {
146 idsCookie.remove(COOKIE_IDS);
147 idsCookie.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
148 //alert('Set cookies: ' + idsCookie.read(COOKIE_IDS) + ' : ' + idsCookie.read(COOKIE_IDS).length );
151 TOPRANK = ranks[getOffset()];
154 function mresultCollectRecords() {
155 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
157 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
158 if(isNull(records[x])) break;
159 if(isNaN(records[x])) continue;
160 var req = new Request(FETCH_MRMODS, records[x]);
161 req.request.userdata = i++;
162 req.callback(mresultHandleMods);
167 function mresultHandleMods(r) {
168 var rec = r.getResultObject();
169 var pagePosition = r.userdata;
170 runEvt('result', 'recordReceived', rec, pagePosition, true);
171 resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);