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();
39 mresultCollectIds(FETCH_MRIDS_FULL);
45 if( getAdvTerm() && !getTerm() ) {
46 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
47 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvIds();
50 mresultCollectIds(FETCH_MRIDS);
58 function mresultGetCount() {
59 var form = (getForm() == "all") ? null : getForm();
60 var req = new Request(FETCH_MRCOUNT,
61 getStype(), getTerm(), getLocation(), getDepth(), form );
62 req.callback(mresultHandleCount);
66 function mresultHandleCount(r) {
67 HITCOUNT = parseInt(r.getResultObject());
68 alert('mresultHandleCount()');
69 runEvt('result', 'hitCountReceived');
74 function mresultLoadCachedSearch() {
75 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
76 var c = JSON2js(idsCookie.read(COOKIE_IDS));
77 if(c) { records = c[0]; ranks = c[1]; }
81 function mresultTryCachedSearch() {
82 mresultLoadCachedSearch();
83 if( getOffset() != 0 && records[getOffset()] != null &&
84 records[resultFinalPageIndex()] != null) {
86 runEvt('result', 'hitCountReceived');
87 mresultCollectRecords();
94 /* performs the actual search */
95 function mresultCollectIds(method) {
96 if(!mresultTryCachedSearch()) {
97 var form = (getForm() == "all") ? null : getForm();
98 var req = new Request(method, getStype(), getTerm(),
99 getLocation(), getDepth(), mresultPreCache, getOffset(), form );
100 req.callback(mresultHandleMRIds);
106 function mresultCollectAdvIds() {
107 if(!mresultTryCachedSearch()) {
108 var form = (getForm() == "all") ? null : getForm();
109 var req = new Request(FETCH_ADV_MRIDS,
110 JSON2js(getAdvTerm()), getLocation(), form, mresultPreCache );
111 req.callback(mresultHandleMRIds);
116 function mresultCollectAdvMARCIds() {
117 if(!mresultTryCachedSearch()) {
118 var form = (getForm() == "all") ? null : getForm();
119 var req = new Request(FETCH_ADV_MARC_MRIDS,
120 JSON2js(getAdvTerm()), getLocation(), form );
121 req.callback(mresultHandleMRIds);
128 function mresultHandleMRIds(r) {
129 var res = r.getResultObject();
131 if(res.count != null) {
132 if( getOffset() == 0 ) HITCOUNT = res.count;
133 runEvt('result', 'hitCountReceived');
135 runEvt('result', 'idsReceived', res.ids);
138 function mresultSetRecords(idstruct) {
139 if(!idstruct) return;
142 for( var x = o; x < idstruct.length + o; x++ ) {
143 if( idstruct[x-o] != null ) {
144 var r = parseInt(idstruct[x - o][0]);
145 var ra = parseFloat(idstruct[x - o][1]);
146 var or = parseInt(idstruct[x - o][2]);
147 if(!isNull(r) && !isNaN(r)) records[x] = r;
148 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
149 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
153 if(getOffset() == 0) {
154 idsCookie.remove(COOKIE_IDS);
155 idsCookie.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
156 //alert('Set cookies: ' + idsCookie.read(COOKIE_IDS) + ' : ' + idsCookie.read(COOKIE_IDS).length );
159 TOPRANK = ranks[getOffset()];
162 function mresultCollectRecords() {
163 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
165 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
166 if(isNull(records[x])) break;
167 if(isNaN(records[x])) continue;
168 var req = new Request(FETCH_MRMODS, records[x]);
169 req.request.userdata = i++;
170 req.callback(mresultHandleMods);
175 function mresultHandleMods(r) {
176 var rec = r.getResultObject();
177 var pagePosition = r.userdata;
178 runEvt('result', 'recordReceived', rec, pagePosition, true);
179 resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);