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 = parseInt(getHitCount() / getDisplayCount());
118 if(pages % 1) pages = parseInt(pages) + 1;
120 var cpage = (getOffset()/getDisplayCount()) + 1;
122 G.ui.result.current_page.appendChild(text(cpage));
123 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
125 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
126 G.ui.result.offset_end.appendChild(text(c));
127 G.ui.result.result_count.appendChild(text(getHitCount()));
128 unHideMe(G.ui.result.info);
131 function resultLowHits() {
133 unHideMe($('result_low_hits'));
134 if(getHitCount() > 0)
135 unHideMe($('result_low_hits_msg'));
137 var sreq = new Request(CHECK_SPELL, getTerm());
138 sreq.callback(resultSuggestSpelling);
141 var words = getTerm().split(' ');
143 while( word = words.shift() ) {
144 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
145 areq.callback(resultLowHitXRef);
149 if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
151 a[PARAM_FORM] = "all";
152 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
153 unHideMe($('low_hits_remove_format'));
156 resultSuggestSearchClass();
160 var lowHitsXRefLinkParent;
161 function resultLowHitXRef(r) {
162 if(!lowHitsXRefLink){
163 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
164 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
166 var res = r.getResultObject();
168 arr.concat(res.also);
169 if(arr && arr.length > 0) {
170 unHideMe($('low_hits_cross_ref'));
173 while( word = arr.shift() ) {
176 a[PARAM_TERM] = word;
177 var template = lowHitsXRefLink.cloneNode(true);
178 template.setAttribute('href',buildOPACLink(a));
179 template.appendChild(text(word));
180 lowHitsXRefLinkParent.appendChild(template);
181 lowHitsXRefLinkParent.appendChild(text(' '));
186 function resultZeroHits() {
188 unHideMe($('result_low_hits'));
189 unHideMe($('result_zero_hits_msg'));
190 if(getTerm()) resultExpandSearch(); /* advanced search */
193 function resultExpandSearch() {
194 var top = findOrgDepth(globalOrgTree);
195 if(getDepth() == top) return;
196 unHideMe($('low_hits_expand_range'));
197 var par = $('low_hits_expand_link').parentNode;
198 var template = par.removeChild($('low_hits_expand_link'));
200 var bottom = getDepth();
201 while( top < bottom ) {
203 a[PARAM_DEPTH] = top;
204 var temp = template.cloneNode(true);
205 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
206 temp.setAttribute('href',buildOPACLink(a));
207 par.appendChild(temp);
212 function resultSuggestSearchClass() {
213 var stype = getStype();
214 if(stype == STYPE_KEYWORD) return;
216 unHideMe($('low_hits_search_type'));
217 if(stype != STYPE_TITLE) {
218 ref = $('low_hits_title_search');
220 a[PARAM_STYPE] = STYPE_TITLE;
221 ref.setAttribute('href',buildOPACLink(a));
223 if(stype != STYPE_AUTHOR) {
224 ref = $('low_hits_author_search');
226 a[PARAM_STYPE] = STYPE_AUTHOR;
227 ref.setAttribute('href',buildOPACLink(a));
229 if(stype != STYPE_SUBJECT) {
230 ref = $('low_hits_subject_search');
232 a[PARAM_STYPE] = STYPE_SUBJECT;
233 ref.setAttribute('href',buildOPACLink(a));
235 if(stype != STYPE_KEYWORD) {
236 ref = $('low_hits_keyword_search');
238 a[PARAM_STYPE] = STYPE_KEYWORD;
239 ref.setAttribute('href',buildOPACLink(a));
241 if(stype != STYPE_SERIES) {
242 ref = $('low_hits_series_search');
244 a[PARAM_STYPE] = STYPE_SERIES;
245 ref.setAttribute('href',buildOPACLink(a));
249 function resultSuggestSpelling(r) {
250 var res = r.getResultObject();
252 unHideMe($('did_you_mean'));
254 arg[PARAM_TERM] = res;
255 $('spell_check_link').setAttribute(
256 'href', buildOPACLink(arg) );
257 $('spell_check_link').appendChild(text(res));
262 function resultPaginate() {
265 if( !(( (o+1) + getDisplayCount()) >= getHitCount()) ) {
268 args[PARAM_OFFSET] = o + getDisplayCount();
269 args[PARAM_SORT] = SORT;
270 args[PARAM_SORT_DIR] = SORT_DIR;
271 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
273 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
274 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
276 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount()) - getDisplayCount();
277 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
278 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
284 args[PARAM_SORT] = SORT;
285 args[PARAM_SORT_DIR] = SORT_DIR;
286 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
288 args[PARAM_OFFSET] = o - getDisplayCount();
289 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
290 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
292 args[PARAM_OFFSET] = 0;
293 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
294 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
296 if(getDisplayCount() < getHitCount())
297 unHideMe($('start_end_links_span'));
300 try{searchTimer.stop()}catch(e){}
303 function buildunAPISpan (span, type, id) {
307 addCSSClass(span,'unapi-id');
311 'tag:' + cgi.server_name + ',' +
313 ':' + type + '/' + id
317 /* display the record info in the record display table 'pos' is the
318 zero based position the record should have in the display table */
319 function resultDisplayRecord(rec, pos, is_mr) {
321 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
323 recordsCache.push(rec);
325 var r = table.rows[pos + 1];
329 var rank = parseFloat(ranks[pos + getOffset()]);
330 rank = parseInt( rank * 100 );
331 var relspan = $n(r, "relevancy_span");
332 relspan.appendChild(text(rank));
333 unHideMe(relspan.parentNode);
336 var pic = $n(r, config.names.result.item_jacket);
337 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
339 var title_link = $n(r, config.names.result.item_title);
340 var author_link = $n(r, config.names.result.item_author);
343 var onlyrec = onlyrecord[ getOffset() + pos ];
345 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
349 args[PARAM_OFFSET] = 0;
350 args[PARAM_RID] = onlyrec;
351 args[PARAM_MRID] = rec.doc_id();
352 pic.parentNode.setAttribute("href", buildOPACLink(args));
353 title_link.setAttribute("href", buildOPACLink(args));
354 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
357 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
359 buildTitleLink(rec, title_link);
362 args[PARAM_OFFSET] = 0;
363 args[PARAM_MRID] = rec.doc_id();
364 pic.parentNode.setAttribute("href", buildOPACLink(args));
368 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
370 buildTitleDetailLink(rec, title_link);
373 args[PARAM_OFFSET] = 0;
374 args[PARAM_RID] = rec.doc_id();
375 pic.parentNode.setAttribute("href", buildOPACLink(args));
377 unHideMe($n(r,'place_hold_span'));
378 $n(r,'place_hold_link').setAttribute(
379 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
382 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
386 if(!isNull(rec.edition())) {
387 unHideMe( $n(r, "result_table_extra_span"));
388 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
390 if(!isNull(rec.pubdate())) {
391 unHideMe( $n(r, "result_table_extra_span"));
392 unHideMe($n(r, "result_table_pub_span"));
393 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
395 if(!isNull(rec.publisher()) ) {
396 unHideMe( $n(r, "result_table_extra_span"));
397 unHideMe($n(r, "result_table_pub_span"));
398 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
401 if(!isNull(rec.physical_description()) ) {
402 unHideMe( $n(r, "result_table_extra_span"));
403 var t = " " + rec.physical_description();
404 //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
405 $n(r, "result_table_phys_span").appendChild( text(t));
410 resultBuildFormatIcons( r, rec, is_mr );
414 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
417 if(resultPageIsDone()) {
418 runEvt('result', 'allRecordsReceived', recordsCache);
423 function _resultFindRec(id) {
424 for( var i = 0; i != recordsCache.length; i++ ) {
425 var rec = recordsCache[i];
426 if( rec && rec.doc_id() == id )
433 function resultBuildFormatIcons( row, rec, is_mr ) {
435 var ress = rec.types_of_resource();
437 for( var i in ress ) {
442 var link = $n(row, res + "_link");
444 var img = link.getElementsByTagName("img")[0];
445 removeCSSClass( img, config.css.dim );
449 if( f == modsFormatToMARC(res) )
450 addCSSClass( img, "dim2_border");
454 args[PARAM_OFFSET] = 0;
458 args[PARAM_TFORM] = modsFormatToMARC(res);
459 args[PARAM_MRID] = rec.doc_id();
463 args[PARAM_RID] = rec.doc_id();
466 link.setAttribute("href", buildOPACLink(args));
472 function resultPageIsDone(pos) {
473 return (recordsHandled == getDisplayCount()
474 || recordsHandled + getOffset() == getHitCount());
477 var resultCCHeaderApplied = false;
479 /* -------------------------------------------------------------------- */
480 /* dynamically add the copy count rows based on the org type 'countsrow'
481 is the row into which we will add TD's to hold the copy counts
482 This code generates copy count cells with an id of
483 'copy_count_cell_<depth>_<pagePosition>' */
484 function resultAddCopyCounts(rec, pagePosition) {
486 var r = table.rows[pagePosition + 1];
487 var countsrow = $n(r, config.names.result.counts_row );
488 var ccell = $n(countsrow, config.names.result.count_cell);
490 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
492 var type = findOrgType(node.ou_type());
493 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
494 ccell.title = type.opac_label();
495 //addCSSClass(ccell, config.css.result.cc_cell_even);
497 var lastcell = ccell;
498 var lastheadcell = null;
501 var ccheadcell = null;
502 if(!resultCCHeaderApplied) {
503 ccrow = $('result_thead_row');
504 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
505 var t = ccheadcell.cloneNode(true);
507 t.appendChild(text(type.opac_label()));
508 ccrow.appendChild(t);
509 resultCCHeaderApplied = true;
515 var d = findOrgDepth(nodes[1]);
516 var d2 = findOrgDepth(nodes[nodes.length -1]);
518 for( var i = d; i <= d2 ; i++ ) {
520 ccell = ccell.cloneNode(true);
522 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
523 //else addCSSClass(ccell, "copy_count_cell_even");
525 var node = nodes[x++];
526 var type = findOrgType(node.ou_type());
528 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
529 ccell.title = type.opac_label();
530 countsrow.insertBefore(ccell, lastcell);
534 var t = ccheadcell.cloneNode(true);
535 t.appendChild(text(type.opac_label()));
536 ccrow.insertBefore(t, lastheadcell);
542 unHideMe($("search_info_table"));
545 /* collect copy counts for a record using method 'methodName' */
546 function resultCollectCopyCounts(rec, pagePosition, methodName) {
547 if(rec == null || rec.doc_id() == null) return;
548 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
549 req.request.userdata = [ rec, pagePosition ];
550 req.callback(resultHandleCopyCounts);
554 function resultHandleCopyCounts(r) {
555 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
559 /* display the collected copy counts */
560 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
561 if(copy_counts == null || rec == null) return;
563 while(copy_counts[i] != null) {
564 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
566 var span = cell.getElementsByTagName("div")[0];
568 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));