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-uri');
309 span.appendChild(text('unAPI'));
312 'tag:' + cgi.server_name + ',' +
314 ':' + type + '/' + id
318 /* display the record info in the record display table 'pos' is the
319 zero based position the record should have in the display table */
320 function resultDisplayRecord(rec, pos, is_mr) {
322 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
324 recordsCache.push(rec);
326 var r = table.rows[pos + 1];
330 var rank = parseFloat(ranks[pos + getOffset()]);
331 rank = parseInt( rank * 100 );
332 var relspan = $n(r, "relevancy_span");
333 relspan.appendChild(text(rank));
334 unHideMe(relspan.parentNode);
337 var pic = $n(r, config.names.result.item_jacket);
338 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
340 var title_link = $n(r, config.names.result.item_title);
341 var author_link = $n(r, config.names.result.item_author);
344 var onlyrec = onlyrecord[ getOffset() + pos ];
346 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
350 args[PARAM_OFFSET] = 0;
351 args[PARAM_RID] = onlyrec;
352 args[PARAM_MRID] = rec.doc_id();
353 pic.parentNode.setAttribute("href", buildOPACLink(args));
354 title_link.setAttribute("href", buildOPACLink(args));
355 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
358 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
360 buildTitleLink(rec, title_link);
363 args[PARAM_OFFSET] = 0;
364 args[PARAM_MRID] = rec.doc_id();
365 pic.parentNode.setAttribute("href", buildOPACLink(args));
369 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
371 buildTitleDetailLink(rec, title_link);
374 args[PARAM_OFFSET] = 0;
375 args[PARAM_RID] = rec.doc_id();
376 pic.parentNode.setAttribute("href", buildOPACLink(args));
378 unHideMe($n(r,'place_hold_span'));
379 $n(r,'place_hold_link').setAttribute(
380 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
383 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
387 if(!isNull(rec.edition())) {
388 unHideMe( $n(r, "result_table_extra_span"));
389 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
391 if(!isNull(rec.pubdate())) {
392 unHideMe( $n(r, "result_table_extra_span"));
393 unHideMe($n(r, "result_table_pub_span"));
394 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
396 if(!isNull(rec.publisher()) ) {
397 unHideMe( $n(r, "result_table_extra_span"));
398 unHideMe($n(r, "result_table_pub_span"));
399 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
402 if(!isNull(rec.physical_description()) ) {
403 unHideMe( $n(r, "result_table_extra_span"));
404 var t = " " + rec.physical_description();
405 //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
406 $n(r, "result_table_phys_span").appendChild( text(t));
411 resultBuildFormatIcons( r, rec, is_mr );
415 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
418 if(resultPageIsDone()) {
419 runEvt('result', 'allRecordsReceived', recordsCache);
424 function _resultFindRec(id) {
425 for( var i = 0; i != recordsCache.length; i++ ) {
426 var rec = recordsCache[i];
427 if( rec && rec.doc_id() == id )
434 function resultBuildFormatIcons( row, rec, is_mr ) {
436 var ress = rec.types_of_resource();
438 for( var i in ress ) {
443 var link = $n(row, res + "_link");
445 var img = link.getElementsByTagName("img")[0];
446 removeCSSClass( img, config.css.dim );
450 if( f == modsFormatToMARC(res) )
451 addCSSClass( img, "dim2_border");
455 args[PARAM_OFFSET] = 0;
459 args[PARAM_TFORM] = modsFormatToMARC(res);
460 args[PARAM_MRID] = rec.doc_id();
464 args[PARAM_RID] = rec.doc_id();
467 link.setAttribute("href", buildOPACLink(args));
473 function resultPageIsDone(pos) {
474 return (recordsHandled == getDisplayCount()
475 || recordsHandled + getOffset() == getHitCount());
478 var resultCCHeaderApplied = false;
480 /* -------------------------------------------------------------------- */
481 /* dynamically add the copy count rows based on the org type 'countsrow'
482 is the row into which we will add TD's to hold the copy counts
483 This code generates copy count cells with an id of
484 'copy_count_cell_<depth>_<pagePosition>' */
485 function resultAddCopyCounts(rec, pagePosition) {
487 var r = table.rows[pagePosition + 1];
488 var countsrow = $n(r, config.names.result.counts_row );
489 var ccell = $n(countsrow, config.names.result.count_cell);
491 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
493 var type = findOrgType(node.ou_type());
494 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
495 ccell.title = type.opac_label();
496 //addCSSClass(ccell, config.css.result.cc_cell_even);
498 var lastcell = ccell;
499 var lastheadcell = null;
502 var ccheadcell = null;
503 if(!resultCCHeaderApplied) {
504 ccrow = $('result_thead_row');
505 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
506 var t = ccheadcell.cloneNode(true);
508 t.appendChild(text(type.opac_label()));
509 ccrow.appendChild(t);
510 resultCCHeaderApplied = true;
516 var d = findOrgDepth(nodes[1]);
517 var d2 = findOrgDepth(nodes[nodes.length -1]);
519 for( var i = d; i <= d2 ; i++ ) {
521 ccell = ccell.cloneNode(true);
523 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
524 //else addCSSClass(ccell, "copy_count_cell_even");
526 var node = nodes[x++];
527 var type = findOrgType(node.ou_type());
529 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
530 ccell.title = type.opac_label();
531 countsrow.insertBefore(ccell, lastcell);
535 var t = ccheadcell.cloneNode(true);
536 t.appendChild(text(type.opac_label()));
537 ccrow.insertBefore(t, lastheadcell);
543 unHideMe($("search_info_table"));
546 /* collect copy counts for a record using method 'methodName' */
547 function resultCollectCopyCounts(rec, pagePosition, methodName) {
548 if(rec == null || rec.doc_id() == null) return;
549 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
550 req.request.userdata = [ rec, pagePosition ];
551 req.callback(resultHandleCopyCounts);
555 function resultHandleCopyCounts(r) {
556 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
560 /* display the collected copy counts */
561 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
562 if(copy_counts == null || rec == null) return;
564 while(copy_counts[i] != null) {
565 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
567 var span = cell.getElementsByTagName("div")[0];
569 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));