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 hideMe($('copyright_block'));
18 function mresultDoSearch() {
21 if(getOffset() == 0) {
22 swapCanvas($('loading_alt'));
23 searchTimer = new Timer('searchTimer',$('loading_alt_span'));
27 table = G.ui.result.main_table;
29 /* add an extra row so IE and safari won't complain */
30 while( table.parentNode.rows.length <= (getDisplayCount() + 1) )
31 table.appendChild(G.ui.result.row_template.cloneNode(true));
33 if( getAdvTerm() && !getTerm() ) {
34 if(getAdvType() == ADVTYPE_MULTI ) mresultCollectAdvIds();
35 if(getAdvType() == ADVTYPE_MARC ) mresultCollectAdvMARCIds();
36 if(getAdvType() == ADVTYPE_ISBN ) mresultCollectAdvISBNIds();
37 if(getAdvType() == ADVTYPE_ISSN ) mresultCollectAdvISSNIds();
46 function mresultLoadCachedSearch() {
47 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
48 var c = JSON2js(cookieManager.read(COOKIE_IDS));
49 if(c) { records = c[0]; ranks = c[1]; }
53 function mresultTryCachedSearch() {
54 mresultLoadCachedSearch();
55 if( getOffset() != 0 && records[getOffset()] != null &&
56 records[resultFinalPageIndex()] != null) {
57 runEvt('result', 'hitCountReceived');
58 mresultCollectRecords();
64 function _mresultCollectIds() {
66 if( getOffset() == 0 || !mresultTryCachedSearch() ) {
68 var form = (!getForm() || getForm() == "all") ? null : getForm();
69 var sort = (getSort() == SORT_TYPE_REL) ? null : getSort();
70 var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
72 var req = new Request(FETCH_MRIDS_, getStype(),
76 org_unit : getLocation(),
78 limit : mresultPreCache,
82 req.callback(mresultHandleMRIds);
88 function mresultCollectAdvIds() {
90 if(getOffset() == 0 || !mresultTryCachedSearch()) {
92 var form = (getForm() == "all") ? null : getForm();
93 var sort = (getSort() == SORT_TYPE_REL) ? null : getSort();
94 var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
96 var req = new Request(FETCH_ADV_MRIDS,
99 org_unit : getLocation(),
101 limit : mresultPreCache,
102 offset : getOffset(),
104 searches : JSON2js(getAdvTerm()) } );
106 req.callback(mresultHandleMRIds);
111 function mresultCollectAdvMARCIds() {
112 if(!mresultTryCachedSearch()) {
113 var form = (getForm() == "all") ? null : getForm();
114 var req = new Request(FETCH_ADV_MARC_MRIDS,
115 JSON2js(getAdvTerm()), getLocation(), form );
116 req.callback(mresultHandleMRIds);
121 function mresultCollectAdvISBNIds() {
122 if(!mresultTryCachedSearch()) {
123 var req = new Request(FETCH_ADV_ISBN_MRIDS, getAdvTerm() );
124 req.callback(mresultHandleMRIds);
129 function mresultCollectAdvISSNIds() {
130 if(!mresultTryCachedSearch()) {
131 var req = new Request(FETCH_ADV_ISSN_MRIDS, getAdvTerm() );
132 req.callback(mresultHandleMRIds);
138 function mresultHandleMRIds(r) {
139 var res = r.getResultObject();
140 if(res.count != null) {
141 if( getOffset() == 0 ) HITCOUNT = res.count;
142 runEvt('result', 'hitCountReceived');
144 runEvt('result', 'idsReceived', res.ids);
147 function mresultSetRecords(idstruct) {
148 if(!idstruct) return;
151 for( var x = o; x < idstruct.length + o; x++ ) {
152 if( idstruct[x-o] != null ) {
153 var r = parseInt(idstruct[x - o][0]);
154 var ra = parseFloat(idstruct[x - o][1]);
155 var or = parseInt(idstruct[x - o][2]);
156 if(!isNull(r) && !isNaN(r)) records[x] = r;
157 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
158 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
162 if(getOffset() == 0) {
163 cookieManager.remove(COOKIE_IDS);
164 cookieManager.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
167 TOPRANK = ranks[getOffset()];
170 function mresultCollectRecords() {
171 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
173 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
174 if(isNull(records[x])) break;
175 if(isNaN(records[x])) continue;
176 var req = new Request(FETCH_MRMODS, records[x]);
177 req.request.userdata = i++;
178 req.callback(mresultHandleMods);
183 function mresultHandleMods(r) {
184 var rec = r.getResultObject();
185 var pagePosition = r.userdata;
186 runEvt('result', 'recordReceived', rec, pagePosition, true);
187 resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);
188 if(resultPageIsDone()) {
189 runEvt('result', 'allRecordsReceived', recordsCache);
190 unHideMe($('copyright_block')); /* *** */