6 var mresultPreCache = 200;
9 attachEvt("common", "unload", mresultUnload);
10 attachEvt("common", "run", mresultDoSearch);
11 attachEvt("result", "idsReceived", mresultSetRecords);
12 attachEvt("result", "idsReceived", mresultCollectRecords);
14 function mresultUnload() { removeChildren(table); table = null;}
16 function mresultDoSearch() {
18 if(getOffset() == 0) {
19 swapCanvas($('loading_alt'));
20 searchTimer = new Timer('searchTimer',$('loading_alt_span'));
24 table = G.ui.result.main_table;
26 while( table.parentNode.rows.length <= (getDisplayCount() + 1) ) /* add an extra row so IE and safari won't complain */
27 table.appendChild(G.ui.result.row_template.cloneNode(true));
29 if(getOffset() == 0 || getHitCount() == null ) {
30 if( getAdvTerm() && !getTerm() ) {
31 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
32 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvMARCIds();
33 if(getAdvType() == ADVTYPE_ISBN ) mresultCollectAdvISBNIds();
34 if(getAdvType() == ADVTYPE_ISSN ) mresultCollectAdvISSNIds();
37 mresultCollectIds(FETCH_MRIDS_FULL);
43 if( getAdvTerm() && !getTerm() ) {
44 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
45 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvIds();
48 mresultCollectIds(FETCH_MRIDS);
56 function mresultGetCount() {
57 var form = (getForm() == "all") ? null : getForm();
58 var req = new Request(FETCH_MRCOUNT,
59 getStype(), getTerm(), getLocation(), getDepth(), form );
60 req.callback(mresultHandleCount);
64 function mresultHandleCount(r) {
65 HITCOUNT = parseInt(r.getResultObject());
66 alert('mresultHandleCount()');
67 runEvt('result', 'hitCountReceived');
72 function mresultLoadCachedSearch() {
73 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
74 var c = JSON2js(cookieManager.read(COOKIE_IDS));
75 if(c) { records = c[0]; ranks = c[1]; }
79 function mresultTryCachedSearch() {
80 mresultLoadCachedSearch();
81 if( getOffset() != 0 && records[getOffset()] != null &&
82 records[resultFinalPageIndex()] != null) {
84 runEvt('result', 'hitCountReceived');
85 mresultCollectRecords();
92 /* performs the actual search */
93 function mresultCollectIds(method) {
94 if(!mresultTryCachedSearch()) {
95 var form = (getForm() == "all") ? null : getForm();
96 var req = new Request(method, getStype(), getTerm(),
97 getLocation(), getDepth(), mresultPreCache, getOffset(), form );
98 req.callback(mresultHandleMRIds);
104 function mresultCollectAdvIds() {
105 if(!mresultTryCachedSearch()) {
106 var form = (getForm() == "all") ? null : getForm();
107 var req = new Request(FETCH_ADV_MRIDS,
108 JSON2js(getAdvTerm()), getLocation(), form, mresultPreCache );
109 req.callback(mresultHandleMRIds);
114 function mresultCollectAdvMARCIds() {
115 if(!mresultTryCachedSearch()) {
116 var form = (getForm() == "all") ? null : getForm();
117 var req = new Request(FETCH_ADV_MARC_MRIDS,
118 JSON2js(getAdvTerm()), getLocation(), form );
119 req.callback(mresultHandleMRIds);
124 function mresultCollectAdvISBNIds() {
125 if(!mresultTryCachedSearch()) {
126 var req = new Request(FETCH_ADV_ISBN_MRIDS, getAdvTerm() );
127 req.callback(mresultHandleMRIds);
132 function mresultCollectAdvISSNIds() {
133 if(!mresultTryCachedSearch()) {
134 var req = new Request(FETCH_ADV_ISSN_MRIDS, getAdvTerm() );
135 req.callback(mresultHandleMRIds);
142 function mresultHandleMRIds(r) {
143 var res = r.getResultObject();
145 if(res.count != null) {
146 if( getOffset() == 0 ) HITCOUNT = res.count;
147 runEvt('result', 'hitCountReceived');
149 runEvt('result', 'idsReceived', res.ids);
152 function mresultSetRecords(idstruct) {
153 if(!idstruct) return;
156 for( var x = o; x < idstruct.length + o; x++ ) {
157 if( idstruct[x-o] != null ) {
158 var r = parseInt(idstruct[x - o][0]);
159 var ra = parseFloat(idstruct[x - o][1]);
160 var or = parseInt(idstruct[x - o][2]);
161 if(!isNull(r) && !isNaN(r)) records[x] = r;
162 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
163 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
167 if(getOffset() == 0) {
168 cookieManager.remove(COOKIE_IDS);
169 cookieManager.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
172 TOPRANK = ranks[getOffset()];
175 function mresultCollectRecords() {
176 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
178 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
179 if(isNull(records[x])) break;
180 if(isNaN(records[x])) continue;
181 var req = new Request(FETCH_MRMODS, records[x]);
182 req.request.userdata = i++;
183 req.callback(mresultHandleMods);
188 function mresultHandleMods(r) {
189 var rec = r.getResultObject();
190 var pagePosition = r.userdata;
191 runEvt('result', 'recordReceived', rec, pagePosition, true);
192 resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);