2 var recordsHandled = 0;
6 /* set up the event handlers */
7 G.evt.result.hitCountReceived.push(resultSetHitInfo);
8 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
9 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
10 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
11 //G.evt.result.allRecordsReceived.push(resultBuildCaches );
13 attachEvt('result','lowHits',resultLowHits);
14 attachEvt('result','zeroHits',resultZeroHits);
16 attachEvt( "common", "locationUpdated", resultSBSubmit );
17 function resultSBSubmit(){searchBarSubmit();}
19 /* do this after we have ID's so the rank for mr pages will be correct */
20 attachEvt("result", "preCollectRecords", resultPaginate);
22 /* returns the last 'index' postion ocurring in this page */
23 function resultFinalPageIndex() {
24 if(getHitCount() < (getOffset() + getDisplayCount()))
25 return getHitCount() - 1;
26 return getOffset() + getDisplayCount() - 1;
29 /* set the search result info, number of hits, which results we're
30 displaying, links to the next/prev pages, etc. */
31 function resultSetHitInfo() {
33 try{searchTimer.stop()}catch(e){}
35 if( findCurrentPage() == MRESULT ) {
36 if(getHitCount() <= lowHitCount && getTerm())
37 runEvt('result', 'lowHits');
38 if(getHitCount() == 0) {
39 runEvt('result', 'zeroHits');
45 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
46 else c = getDisplayCount() + getOffset();
48 var pages = getHitCount() / getDisplayCount();
49 if(pages % 1) pages = parseInt(pages) + 1;
51 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
52 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
54 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
55 G.ui.result.offset_end.appendChild(text(c));
56 G.ui.result.result_count.appendChild(text(getHitCount()));
57 unHideMe(G.ui.result.info);
60 function resultLowHits() {
62 unHideMe($('result_low_hits'));
64 unHideMe($('result_low_hits_msg'));
66 var sreq = new Request(CHECK_SPELL, getTerm());
67 sreq.callback(resultSuggestSpelling);
70 var words = getTerm().split(' ');
72 while( word = words.shift() ) {
73 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
74 areq.callback(resultLowHitXRef);
78 if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
80 a[PARAM_FORM] = "all";
81 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
82 unHideMe($('low_hits_remove_format'));
85 resultSuggestSearchClass();
89 var lowHitsXRefLinkParent;
90 function resultLowHitXRef(r) {
92 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
93 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
95 var res = r.getResultObject();
98 if(arr && arr.length > 0) {
99 unHideMe($('low_hits_cross_ref'));
102 while( word = arr.shift() ) {
105 a[PARAM_TERM] = word;
106 var template = lowHitsXRefLink.cloneNode(true);
107 template.setAttribute('href',buildOPACLink(a));
108 template.appendChild(text(word));
109 lowHitsXRefLinkParent.appendChild(template);
110 lowHitsXRefLinkParent.appendChild(text(' '));
115 function resultZeroHits() {
117 unHideMe($('result_low_hits'));
118 unHideMe($('result_zero_hits_msg'));
119 if(getTerm()) resultExpandSearch(); /* advanced search */
122 function resultExpandSearch() {
123 var top = findOrgDepth(globalOrgTree);
124 if(getDepth() == top) return;
125 unHideMe($('low_hits_expand_range'));
126 var par = $('low_hits_expand_link').parentNode;
127 var template = par.removeChild($('low_hits_expand_link'));
129 var bottom = getDepth();
130 while( top < bottom ) {
132 a[PARAM_DEPTH] = top;
133 var temp = template.cloneNode(true);
134 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
135 temp.setAttribute('href',buildOPACLink(a));
136 par.appendChild(temp);
141 function resultSuggestSearchClass() {
142 var stype = getStype();
143 if(stype == STYPE_KEYWORD) return;
145 unHideMe($('low_hits_search_type'));
146 if(stype != STYPE_TITLE) {
147 ref = $('low_hits_title_search');
149 a[PARAM_STYPE] = STYPE_TITLE;
150 ref.setAttribute('href',buildOPACLink(a));
152 if(stype != STYPE_AUTHOR) {
153 ref = $('low_hits_author_search');
155 a[PARAM_STYPE] = STYPE_AUTHOR;
156 ref.setAttribute('href',buildOPACLink(a));
158 if(stype != STYPE_SUBJECT) {
159 ref = $('low_hits_subject_search');
161 a[PARAM_STYPE] = STYPE_SUBJECT;
162 ref.setAttribute('href',buildOPACLink(a));
164 if(stype != STYPE_KEYWORD) {
165 ref = $('low_hits_keyword_search');
167 a[PARAM_STYPE] = STYPE_KEYWORD;
168 ref.setAttribute('href',buildOPACLink(a));
170 if(stype != STYPE_SERIES) {
171 ref = $('low_hits_series_search');
173 a[PARAM_STYPE] = STYPE_SERIES;
174 ref.setAttribute('href',buildOPACLink(a));
178 function resultSuggestSpelling(r) {
179 var res = r.getResultObject();
181 unHideMe($('did_you_mean'));
183 arg[PARAM_TERM] = res;
184 $('spell_check_link').setAttribute(
185 'href', buildOPACLink(arg) );
186 $('spell_check_link').appendChild(text(res));
191 function resultPaginate() {
194 if( !((o + getDisplayCount()) >= getHitCount()) ) {
197 args[PARAM_OFFSET] = o + getDisplayCount();
198 args[PARAM_SORT] = SORT;
199 args[PARAM_SORT_DIR] = SORT_DIR;
200 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
202 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
203 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
205 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
206 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
207 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
213 args[PARAM_SORT] = SORT;
214 args[PARAM_SORT_DIR] = SORT_DIR;
215 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
217 args[PARAM_OFFSET] = o - getDisplayCount();
218 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
219 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
221 args[PARAM_OFFSET] = 0;
222 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
223 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
225 if(getDisplayCount() < getHitCount())
226 unHideMe($('start_end_links_span'));
229 try{searchTimer.stop()}catch(e){}
232 function buildunAPISpan (span, type, id) {
236 addCSSClass(span,'unapi-uri');
238 span.appendChild(text('unAPI'));
241 'tag:' + cgi.server_name + ',' +
243 ':' + type + '/' + id
247 /* display the record info in the record display table 'pos' is the
248 zero based position the record should have in the display table */
249 function resultDisplayRecord(rec, pos, is_mr) {
251 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
253 recordsCache.push(rec);
255 var r = table.rows[pos + 1];
258 var rank = parseFloat(ranks[pos + getOffset()]);
259 rank = parseInt( rank * 100 );
260 var relspan = $n(r, "relevancy_span");
261 relspan.appendChild(text(rank));
262 unHideMe(relspan.parentNode);
265 var pic = $n(r, config.names.result.item_jacket);
266 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
268 var title_link = $n(r, config.names.result.item_title);
269 var author_link = $n(r, config.names.result.item_author);
272 var onlyrec = onlyrecord[ getOffset() + pos ];
274 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
278 args[PARAM_OFFSET] = 0;
279 args[PARAM_RID] = onlyrec;
280 args[PARAM_MRID] = rec.doc_id();
281 pic.parentNode.setAttribute("href", buildOPACLink(args));
282 title_link.setAttribute("href", buildOPACLink(args));
283 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
286 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
288 buildTitleLink(rec, title_link);
291 args[PARAM_OFFSET] = 0;
292 args[PARAM_MRID] = rec.doc_id();
293 pic.parentNode.setAttribute("href", buildOPACLink(args));
297 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
299 buildTitleDetailLink(rec, title_link);
302 args[PARAM_OFFSET] = 0;
303 args[PARAM_RID] = rec.doc_id();
304 pic.parentNode.setAttribute("href", buildOPACLink(args));
306 unHideMe($n(r,'place_hold_span'));
307 $n(r,'place_hold_link').setAttribute(
308 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
311 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
315 if(!isNull(rec.edition())) {
316 unHideMe( $n(r, "result_table_extra_span"));
317 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
319 if(!isNull(rec.pubdate())) {
320 unHideMe( $n(r, "result_table_extra_span"));
321 unHideMe($n(r, "result_table_pub_span"));
322 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
324 if(!isNull(rec.publisher()) ) {
325 unHideMe( $n(r, "result_table_extra_span"));
326 unHideMe($n(r, "result_table_pub_span"));
327 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
331 resultBuildFormatIcons( r, rec, is_mr );
335 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
338 if(resultPageIsDone()) {
339 runEvt('result', 'allRecordsReceived', recordsCache);
344 function _resultFindRec(id) {
345 for( var i = 0; i != recordsCache.length; i++ ) {
346 var rec = recordsCache[i];
347 if( rec && rec.doc_id() == id )
354 function resultBuildFormatIcons( row, rec, is_mr ) {
356 var ress = rec.types_of_resource();
358 for( var i in ress ) {
361 var link = $n(row, res + "_link");
363 var img = link.getElementsByTagName("img")[0];
364 removeCSSClass( img, config.css.dim );
368 if( f == modsFormatToMARC(res) )
369 addCSSClass( img, "dim2_border");
373 args[PARAM_OFFSET] = 0;
374 args[PARAM_FORM] = modsFormatToMARC(res);
378 args[PARAM_MRID] = rec.doc_id();
381 args[PARAM_RID] = rec.doc_id();
384 link.setAttribute("href", buildOPACLink(args));
390 function resultPageIsDone(pos) {
391 return (recordsHandled == getDisplayCount()
392 || recordsHandled + getOffset() == getHitCount());
395 var resultCCHeaderApplied = false;
397 /* -------------------------------------------------------------------- */
398 /* dynamically add the copy count rows based on the org type 'countsrow'
399 is the row into which we will add TD's to hold the copy counts
400 This code generates copy count cells with an id of
401 'copy_count_cell_<depth>_<pagePosition>' */
402 function resultAddCopyCounts(rec, pagePosition) {
404 var r = table.rows[pagePosition + 1];
405 var countsrow = $n(r, config.names.result.counts_row );
406 var ccell = $n(countsrow, config.names.result.count_cell);
408 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
410 var type = findOrgType(node.ou_type());
411 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
412 ccell.title = type.opac_label();
413 //addCSSClass(ccell, config.css.result.cc_cell_even);
415 var lastcell = ccell;
416 var lastheadcell = null;
419 var ccheadcell = null;
420 if(!resultCCHeaderApplied) {
421 ccrow = $('result_thead_row');
422 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
423 var t = ccheadcell.cloneNode(true);
425 t.appendChild(text(type.opac_label()));
426 ccrow.appendChild(t);
427 resultCCHeaderApplied = true;
433 var d = findOrgDepth(nodes[1]);
434 var d2 = findOrgDepth(nodes[nodes.length -1]);
436 for( var i = d; i <= d2 ; i++ ) {
438 ccell = ccell.cloneNode(true);
440 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
441 //else addCSSClass(ccell, "copy_count_cell_even");
443 var node = nodes[x++];
444 var type = findOrgType(node.ou_type());
446 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
447 ccell.title = type.opac_label();
448 countsrow.insertBefore(ccell, lastcell);
452 var t = ccheadcell.cloneNode(true);
453 t.appendChild(text(type.opac_label()));
454 ccrow.insertBefore(t, lastheadcell);
460 unHideMe($("search_info_table"));
463 /* collect copy counts for a record using method 'methodName' */
464 function resultCollectCopyCounts(rec, pagePosition, methodName) {
465 if(rec == null || rec.doc_id() == null) return;
466 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
467 req.request.userdata = [ rec, pagePosition ];
468 req.callback(resultHandleCopyCounts);
472 function resultHandleCopyCounts(r) {
473 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
477 /* display the collected copy counts */
478 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
479 if(copy_counts == null || rec == null) return;
481 while(copy_counts[i] != null) {
482 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
484 var span = cell.getElementsByTagName("div")[0];
486 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));