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;
33 /* generic search method */
34 function resultCollectSearchIds( type, method, handler ) {
36 var sort = (getSort() == SORT_TYPE_REL) ? null : getSort();
37 var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
45 args.searches[getStype()] = {};
46 args.searches[getStype()].term = getTerm();
48 var form = parseForm(getForm());
49 item_type = form.item_type;
50 item_form = form.item_form;
53 args.searches = JSON2js(getSearches());
54 item_type = (getItemType()) ? getItemType().split(/,/) : null;
55 item_form = (getItemForm()) ? getItemForm().split(/,/) : null;
58 args.org_unit = getLocation();
59 args.depth = getDepth();
61 args.offset = getOffset();
63 if(sort) args.sort = sort;
64 if(sortdir) args.sort_dir = sortdir;
65 if(item_type) args.item_type = item_type;
66 if(item_form) args.item_form = item_form;
69 if(getAudience()) args.audience = getAudience().split(/,/);
70 if(getLitForm()) args.lit_form = getLitForm().split(/,/);
71 if(getLanguage()) args.language = getLanguage().split(/,/);
73 var req = new Request(method, args);
74 req.callback(handler);
82 /* set the search result info, number of hits, which results we're
83 displaying, links to the next/prev pages, etc. */
84 function resultSetHitInfo() {
87 /* tell the user where the results are coming from */
88 var baseorg = findOrgUnit(getLocation());
89 var depth = getDepth();
90 var mydepth = findOrgDepth(baseorg);
91 if( findOrgDepth(baseorg) != depth ) {
93 while( mydepth > depth ) {
95 tmporg = findOrgUnit(tmporg.parent_ou());
97 unHideMe($('including_results_for'));
98 $('including_results_location').appendChild(text(tmporg.name()));
102 try{searchTimer.stop()}catch(e){}
104 if( findCurrentPage() == MRESULT ) {
105 if(getHitCount() <= lowHitCount && getTerm())
106 runEvt('result', 'lowHits');
107 if(getHitCount() == 0) {
108 runEvt('result', 'zeroHits');
114 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
115 else c = getDisplayCount() + getOffset();
117 var pages = getHitCount() / getDisplayCount();
118 if(pages % 1) pages = parseInt(pages) + 1;
120 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
121 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
123 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
124 G.ui.result.offset_end.appendChild(text(c));
125 G.ui.result.result_count.appendChild(text(getHitCount()));
126 unHideMe(G.ui.result.info);
129 function resultLowHits() {
131 unHideMe($('result_low_hits'));
132 if(getHitCount() > 0)
133 unHideMe($('result_low_hits_msg'));
135 var sreq = new Request(CHECK_SPELL, getTerm());
136 sreq.callback(resultSuggestSpelling);
139 var words = getTerm().split(' ');
141 while( word = words.shift() ) {
142 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
143 areq.callback(resultLowHitXRef);
147 if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
149 a[PARAM_FORM] = "all";
150 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
151 unHideMe($('low_hits_remove_format'));
154 resultSuggestSearchClass();
158 var lowHitsXRefLinkParent;
159 function resultLowHitXRef(r) {
160 if(!lowHitsXRefLink){
161 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
162 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
164 var res = r.getResultObject();
166 arr.concat(res.also);
167 if(arr && arr.length > 0) {
168 unHideMe($('low_hits_cross_ref'));
171 while( word = arr.shift() ) {
174 a[PARAM_TERM] = word;
175 var template = lowHitsXRefLink.cloneNode(true);
176 template.setAttribute('href',buildOPACLink(a));
177 template.appendChild(text(word));
178 lowHitsXRefLinkParent.appendChild(template);
179 lowHitsXRefLinkParent.appendChild(text(' '));
184 function resultZeroHits() {
186 unHideMe($('result_low_hits'));
187 unHideMe($('result_zero_hits_msg'));
188 if(getTerm()) resultExpandSearch(); /* advanced search */
191 function resultExpandSearch() {
192 var top = findOrgDepth(globalOrgTree);
193 if(getDepth() == top) return;
194 unHideMe($('low_hits_expand_range'));
195 var par = $('low_hits_expand_link').parentNode;
196 var template = par.removeChild($('low_hits_expand_link'));
198 var bottom = getDepth();
199 while( top < bottom ) {
201 a[PARAM_DEPTH] = top;
202 var temp = template.cloneNode(true);
203 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
204 temp.setAttribute('href',buildOPACLink(a));
205 par.appendChild(temp);
210 function resultSuggestSearchClass() {
211 var stype = getStype();
212 if(stype == STYPE_KEYWORD) return;
214 unHideMe($('low_hits_search_type'));
215 if(stype != STYPE_TITLE) {
216 ref = $('low_hits_title_search');
218 a[PARAM_STYPE] = STYPE_TITLE;
219 ref.setAttribute('href',buildOPACLink(a));
221 if(stype != STYPE_AUTHOR) {
222 ref = $('low_hits_author_search');
224 a[PARAM_STYPE] = STYPE_AUTHOR;
225 ref.setAttribute('href',buildOPACLink(a));
227 if(stype != STYPE_SUBJECT) {
228 ref = $('low_hits_subject_search');
230 a[PARAM_STYPE] = STYPE_SUBJECT;
231 ref.setAttribute('href',buildOPACLink(a));
233 if(stype != STYPE_KEYWORD) {
234 ref = $('low_hits_keyword_search');
236 a[PARAM_STYPE] = STYPE_KEYWORD;
237 ref.setAttribute('href',buildOPACLink(a));
239 if(stype != STYPE_SERIES) {
240 ref = $('low_hits_series_search');
242 a[PARAM_STYPE] = STYPE_SERIES;
243 ref.setAttribute('href',buildOPACLink(a));
247 function resultSuggestSpelling(r) {
248 var res = r.getResultObject();
250 unHideMe($('did_you_mean'));
252 arg[PARAM_TERM] = res;
253 $('spell_check_link').setAttribute(
254 'href', buildOPACLink(arg) );
255 $('spell_check_link').appendChild(text(res));
260 function resultPaginate() {
263 if( !((o + getDisplayCount()) >= getHitCount()) ) {
266 args[PARAM_OFFSET] = o + getDisplayCount();
267 args[PARAM_SORT] = SORT;
268 args[PARAM_SORT_DIR] = SORT_DIR;
269 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
271 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
272 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
274 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
275 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
276 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
282 args[PARAM_SORT] = SORT;
283 args[PARAM_SORT_DIR] = SORT_DIR;
284 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
286 args[PARAM_OFFSET] = o - getDisplayCount();
287 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
288 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
290 args[PARAM_OFFSET] = 0;
291 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
292 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
294 if(getDisplayCount() < getHitCount())
295 unHideMe($('start_end_links_span'));
298 try{searchTimer.stop()}catch(e){}
301 function buildunAPISpan (span, type, id) {
305 addCSSClass(span,'unapi-uri');
307 span.appendChild(text('unAPI'));
310 'tag:' + cgi.server_name + ',' +
312 ':' + type + '/' + id
316 /* display the record info in the record display table 'pos' is the
317 zero based position the record should have in the display table */
318 function resultDisplayRecord(rec, pos, is_mr) {
320 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
322 recordsCache.push(rec);
324 var r = table.rows[pos + 1];
328 var rank = parseFloat(ranks[pos + getOffset()]);
329 rank = parseInt( rank * 100 );
330 var relspan = $n(r, "relevancy_span");
331 relspan.appendChild(text(rank));
332 unHideMe(relspan.parentNode);
335 var pic = $n(r, config.names.result.item_jacket);
336 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
338 var title_link = $n(r, config.names.result.item_title);
339 var author_link = $n(r, config.names.result.item_author);
342 var onlyrec = onlyrecord[ getOffset() + pos ];
344 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
348 args[PARAM_OFFSET] = 0;
349 args[PARAM_RID] = onlyrec;
350 args[PARAM_MRID] = rec.doc_id();
351 pic.parentNode.setAttribute("href", buildOPACLink(args));
352 title_link.setAttribute("href", buildOPACLink(args));
353 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
356 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
358 buildTitleLink(rec, title_link);
361 args[PARAM_OFFSET] = 0;
362 args[PARAM_MRID] = rec.doc_id();
363 pic.parentNode.setAttribute("href", buildOPACLink(args));
367 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
369 buildTitleDetailLink(rec, title_link);
372 args[PARAM_OFFSET] = 0;
373 args[PARAM_RID] = rec.doc_id();
374 pic.parentNode.setAttribute("href", buildOPACLink(args));
376 unHideMe($n(r,'place_hold_span'));
377 $n(r,'place_hold_link').setAttribute(
378 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
381 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
385 if(!isNull(rec.edition())) {
386 unHideMe( $n(r, "result_table_extra_span"));
387 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
389 if(!isNull(rec.pubdate())) {
390 unHideMe( $n(r, "result_table_extra_span"));
391 unHideMe($n(r, "result_table_pub_span"));
392 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
394 if(!isNull(rec.publisher()) ) {
395 unHideMe( $n(r, "result_table_extra_span"));
396 unHideMe($n(r, "result_table_pub_span"));
397 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
400 if(!isNull(rec.physical_description()) ) {
401 unHideMe( $n(r, "result_table_extra_span"));
402 var t = " " + rec.physical_description();
403 //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
404 $n(r, "result_table_phys_span").appendChild( text(t));
409 resultBuildFormatIcons( r, rec, is_mr );
413 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
416 if(resultPageIsDone()) {
417 runEvt('result', 'allRecordsReceived', recordsCache);
422 function _resultFindRec(id) {
423 for( var i = 0; i != recordsCache.length; i++ ) {
424 var rec = recordsCache[i];
425 if( rec && rec.doc_id() == id )
432 function resultBuildFormatIcons( row, rec, is_mr ) {
434 var ress = rec.types_of_resource();
436 for( var i in ress ) {
441 var link = $n(row, res + "_link");
443 var img = link.getElementsByTagName("img")[0];
444 removeCSSClass( img, config.css.dim );
448 if( f == modsFormatToMARC(res) )
449 addCSSClass( img, "dim2_border");
453 args[PARAM_OFFSET] = 0;
457 args[PARAM_TFORM] = modsFormatToMARC(res);
458 args[PARAM_MRID] = rec.doc_id();
462 args[PARAM_RID] = rec.doc_id();
465 link.setAttribute("href", buildOPACLink(args));
471 function resultPageIsDone(pos) {
472 return (recordsHandled == getDisplayCount()
473 || recordsHandled + getOffset() == getHitCount());
476 var resultCCHeaderApplied = false;
478 /* -------------------------------------------------------------------- */
479 /* dynamically add the copy count rows based on the org type 'countsrow'
480 is the row into which we will add TD's to hold the copy counts
481 This code generates copy count cells with an id of
482 'copy_count_cell_<depth>_<pagePosition>' */
483 function resultAddCopyCounts(rec, pagePosition) {
485 var r = table.rows[pagePosition + 1];
486 var countsrow = $n(r, config.names.result.counts_row );
487 var ccell = $n(countsrow, config.names.result.count_cell);
489 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
491 var type = findOrgType(node.ou_type());
492 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
493 ccell.title = type.opac_label();
494 //addCSSClass(ccell, config.css.result.cc_cell_even);
496 var lastcell = ccell;
497 var lastheadcell = null;
500 var ccheadcell = null;
501 if(!resultCCHeaderApplied) {
502 ccrow = $('result_thead_row');
503 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
504 var t = ccheadcell.cloneNode(true);
506 t.appendChild(text(type.opac_label()));
507 ccrow.appendChild(t);
508 resultCCHeaderApplied = true;
514 var d = findOrgDepth(nodes[1]);
515 var d2 = findOrgDepth(nodes[nodes.length -1]);
517 for( var i = d; i <= d2 ; i++ ) {
519 ccell = ccell.cloneNode(true);
521 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
522 //else addCSSClass(ccell, "copy_count_cell_even");
524 var node = nodes[x++];
525 var type = findOrgType(node.ou_type());
527 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
528 ccell.title = type.opac_label();
529 countsrow.insertBefore(ccell, lastcell);
533 var t = ccheadcell.cloneNode(true);
534 t.appendChild(text(type.opac_label()));
535 ccrow.insertBefore(t, lastheadcell);
541 unHideMe($("search_info_table"));
544 /* collect copy counts for a record using method 'methodName' */
545 function resultCollectCopyCounts(rec, pagePosition, methodName) {
546 if(rec == null || rec.doc_id() == null) return;
547 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
548 req.request.userdata = [ rec, pagePosition ];
549 req.callback(resultHandleCopyCounts);
553 function resultHandleCopyCounts(r) {
554 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
558 /* display the collected copy counts */
559 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
560 if(copy_counts == null || rec == null) return;
562 while(copy_counts[i] != null) {
563 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
565 var span = cell.getElementsByTagName("div")[0];
567 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));