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 /* add an extra row so IE and safari won't complain */
27 while( table.parentNode.rows.length <= (getDisplayCount() + 1) )
28 table.appendChild(G.ui.result.row_template.cloneNode(true));
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();
43 function mresultLoadCachedSearch() {
44 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
45 var c = JSON2js(cookieManager.read(COOKIE_IDS));
46 if(c) { records = c[0]; ranks = c[1]; }
50 function mresultTryCachedSearch() {
51 mresultLoadCachedSearch();
52 if( getOffset() != 0 && records[getOffset()] != null &&
53 records[resultFinalPageIndex()] != null) {
54 runEvt('result', 'hitCountReceived');
55 mresultCollectRecords();
61 function _mresultCollectIds() {
63 if( getOffset() == 0 || !mresultTryCachedSearch() ) {
65 var form = (!getForm() || getForm() == "all") ? null : getForm();
66 var sort = (getSort() == SORT_TYPE_REL) ? null : getSort();
67 var sortdir = (sort) ? getSortDir() : null;
69 var req = new Request(FETCH_MRIDS_, getStype(),
73 org_unit : getLocation(),
75 limit : mresultPreCache,
79 req.callback(mresultHandleMRIds);
85 function mresultCollectAdvIds() {
87 if(getOffset() == 0 || !mresultTryCachedSearch()) {
89 var form = (getForm() == "all") ? null : getForm();
90 var sort = (getSort() == SORT_TYPE_REL) ? null : getSort();
91 var sortdir = (sort) ? getSortDir() : null;
93 var req = new Request(FETCH_ADV_MRIDS,
96 org_unit : getLocation(),
98 limit : mresultPreCache,
101 searches : JSON2js(getAdvTerm()) } );
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);
118 function mresultCollectAdvISBNIds() {
119 if(!mresultTryCachedSearch()) {
120 var req = new Request(FETCH_ADV_ISBN_MRIDS, getAdvTerm() );
121 req.callback(mresultHandleMRIds);
126 function mresultCollectAdvISSNIds() {
127 if(!mresultTryCachedSearch()) {
128 var req = new Request(FETCH_ADV_ISSN_MRIDS, getAdvTerm() );
129 req.callback(mresultHandleMRIds);
135 function mresultHandleMRIds(r) {
136 var res = r.getResultObject();
137 if(res.count != null) {
138 if( getOffset() == 0 ) HITCOUNT = res.count;
139 runEvt('result', 'hitCountReceived');
141 runEvt('result', 'idsReceived', res.ids);
144 function mresultSetRecords(idstruct) {
145 if(!idstruct) return;
148 for( var x = o; x < idstruct.length + o; x++ ) {
149 if( idstruct[x-o] != null ) {
150 var r = parseInt(idstruct[x - o][0]);
151 var ra = parseFloat(idstruct[x - o][1]);
152 var or = parseInt(idstruct[x - o][2]);
153 if(!isNull(r) && !isNaN(r)) records[x] = r;
154 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
155 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
159 if(getOffset() == 0) {
160 cookieManager.remove(COOKIE_IDS);
161 cookieManager.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
164 TOPRANK = ranks[getOffset()];
167 function mresultCollectRecords() {
168 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
170 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
171 if(isNull(records[x])) break;
172 if(isNaN(records[x])) continue;
173 var req = new Request(FETCH_MRMODS, records[x]);
174 req.request.userdata = i++;
175 req.callback(mresultHandleMods);
180 function mresultHandleMods(r) {
181 var rec = r.getResultObject();
182 var pagePosition = r.userdata;
183 runEvt('result', 'recordReceived', rec, pagePosition, true);
184 resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);