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;
68 if(getAudience()) args.audience = getAudience().split(/,/);
69 if(getLitForm()) args.lit_form = getLitForm().split(/,/);
70 if(getLanguage()) args.language = getLanguage().split(/,/);
72 var req = new Request(method, args);
73 req.callback(handler);
81 /* set the search result info, number of hits, which results we're
82 displaying, links to the next/prev pages, etc. */
83 function resultSetHitInfo() {
86 /* tell the user where the results are coming from */
87 var baseorg = findOrgUnit(getLocation());
88 var depth = getDepth();
89 var mydepth = findOrgDepth(baseorg);
90 if( findOrgDepth(baseorg) != depth ) {
92 while( mydepth > depth ) {
94 tmporg = findOrgUnit(tmporg.parent_ou());
96 unHideMe($('including_results_for'));
97 $('including_results_location').appendChild(text(tmporg.name()));
101 try{searchTimer.stop()}catch(e){}
103 if( findCurrentPage() == MRESULT ) {
104 if(getHitCount() <= lowHitCount && getTerm())
105 runEvt('result', 'lowHits');
106 if(getHitCount() == 0) {
107 runEvt('result', 'zeroHits');
113 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
114 else c = getDisplayCount() + getOffset();
116 var pages = getHitCount() / getDisplayCount();
117 if(pages % 1) pages = parseInt(pages) + 1;
119 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
120 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
122 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
123 G.ui.result.offset_end.appendChild(text(c));
124 G.ui.result.result_count.appendChild(text(getHitCount()));
125 unHideMe(G.ui.result.info);
128 function resultLowHits() {
130 unHideMe($('result_low_hits'));
131 if(getHitCount() > 0)
132 unHideMe($('result_low_hits_msg'));
134 var sreq = new Request(CHECK_SPELL, getTerm());
135 sreq.callback(resultSuggestSpelling);
138 var words = getTerm().split(' ');
140 while( word = words.shift() ) {
141 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
142 areq.callback(resultLowHitXRef);
146 if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
148 a[PARAM_FORM] = "all";
149 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
150 unHideMe($('low_hits_remove_format'));
153 resultSuggestSearchClass();
157 var lowHitsXRefLinkParent;
158 function resultLowHitXRef(r) {
159 if(!lowHitsXRefLink){
160 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
161 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
163 var res = r.getResultObject();
165 arr.concat(res.also);
166 if(arr && arr.length > 0) {
167 unHideMe($('low_hits_cross_ref'));
170 while( word = arr.shift() ) {
173 a[PARAM_TERM] = word;
174 var template = lowHitsXRefLink.cloneNode(true);
175 template.setAttribute('href',buildOPACLink(a));
176 template.appendChild(text(word));
177 lowHitsXRefLinkParent.appendChild(template);
178 lowHitsXRefLinkParent.appendChild(text(' '));
183 function resultZeroHits() {
185 unHideMe($('result_low_hits'));
186 unHideMe($('result_zero_hits_msg'));
187 if(getTerm()) resultExpandSearch(); /* advanced search */
190 function resultExpandSearch() {
191 var top = findOrgDepth(globalOrgTree);
192 if(getDepth() == top) return;
193 unHideMe($('low_hits_expand_range'));
194 var par = $('low_hits_expand_link').parentNode;
195 var template = par.removeChild($('low_hits_expand_link'));
197 var bottom = getDepth();
198 while( top < bottom ) {
200 a[PARAM_DEPTH] = top;
201 var temp = template.cloneNode(true);
202 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
203 temp.setAttribute('href',buildOPACLink(a));
204 par.appendChild(temp);
209 function resultSuggestSearchClass() {
210 var stype = getStype();
211 if(stype == STYPE_KEYWORD) return;
213 unHideMe($('low_hits_search_type'));
214 if(stype != STYPE_TITLE) {
215 ref = $('low_hits_title_search');
217 a[PARAM_STYPE] = STYPE_TITLE;
218 ref.setAttribute('href',buildOPACLink(a));
220 if(stype != STYPE_AUTHOR) {
221 ref = $('low_hits_author_search');
223 a[PARAM_STYPE] = STYPE_AUTHOR;
224 ref.setAttribute('href',buildOPACLink(a));
226 if(stype != STYPE_SUBJECT) {
227 ref = $('low_hits_subject_search');
229 a[PARAM_STYPE] = STYPE_SUBJECT;
230 ref.setAttribute('href',buildOPACLink(a));
232 if(stype != STYPE_KEYWORD) {
233 ref = $('low_hits_keyword_search');
235 a[PARAM_STYPE] = STYPE_KEYWORD;
236 ref.setAttribute('href',buildOPACLink(a));
238 if(stype != STYPE_SERIES) {
239 ref = $('low_hits_series_search');
241 a[PARAM_STYPE] = STYPE_SERIES;
242 ref.setAttribute('href',buildOPACLink(a));
246 function resultSuggestSpelling(r) {
247 var res = r.getResultObject();
249 unHideMe($('did_you_mean'));
251 arg[PARAM_TERM] = res;
252 $('spell_check_link').setAttribute(
253 'href', buildOPACLink(arg) );
254 $('spell_check_link').appendChild(text(res));
259 function resultPaginate() {
262 if( !((o + getDisplayCount()) >= getHitCount()) ) {
265 args[PARAM_OFFSET] = o + getDisplayCount();
266 args[PARAM_SORT] = SORT;
267 args[PARAM_SORT_DIR] = SORT_DIR;
268 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
270 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
271 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
273 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
274 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
275 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
281 args[PARAM_SORT] = SORT;
282 args[PARAM_SORT_DIR] = SORT_DIR;
283 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
285 args[PARAM_OFFSET] = o - getDisplayCount();
286 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
287 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
289 args[PARAM_OFFSET] = 0;
290 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
291 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
293 if(getDisplayCount() < getHitCount())
294 unHideMe($('start_end_links_span'));
297 try{searchTimer.stop()}catch(e){}
300 function buildunAPISpan (span, type, id) {
304 addCSSClass(span,'unapi-uri');
306 span.appendChild(text('unAPI'));
309 'tag:' + cgi.server_name + ',' +
311 ':' + type + '/' + id
315 /* display the record info in the record display table 'pos' is the
316 zero based position the record should have in the display table */
317 function resultDisplayRecord(rec, pos, is_mr) {
319 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
321 recordsCache.push(rec);
323 var r = table.rows[pos + 1];
327 var rank = parseFloat(ranks[pos + getOffset()]);
328 rank = parseInt( rank * 100 );
329 var relspan = $n(r, "relevancy_span");
330 relspan.appendChild(text(rank));
331 unHideMe(relspan.parentNode);
334 var pic = $n(r, config.names.result.item_jacket);
335 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
337 var title_link = $n(r, config.names.result.item_title);
338 var author_link = $n(r, config.names.result.item_author);
341 var onlyrec = onlyrecord[ getOffset() + pos ];
343 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
347 args[PARAM_OFFSET] = 0;
348 args[PARAM_RID] = onlyrec;
349 args[PARAM_MRID] = rec.doc_id();
350 pic.parentNode.setAttribute("href", buildOPACLink(args));
351 title_link.setAttribute("href", buildOPACLink(args));
352 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
355 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
357 buildTitleLink(rec, title_link);
360 args[PARAM_OFFSET] = 0;
361 args[PARAM_MRID] = rec.doc_id();
362 pic.parentNode.setAttribute("href", buildOPACLink(args));
366 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
368 buildTitleDetailLink(rec, title_link);
371 args[PARAM_OFFSET] = 0;
372 args[PARAM_RID] = rec.doc_id();
373 pic.parentNode.setAttribute("href", buildOPACLink(args));
375 unHideMe($n(r,'place_hold_span'));
376 $n(r,'place_hold_link').setAttribute(
377 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
380 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
384 if(!isNull(rec.edition())) {
385 unHideMe( $n(r, "result_table_extra_span"));
386 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
388 if(!isNull(rec.pubdate())) {
389 unHideMe( $n(r, "result_table_extra_span"));
390 unHideMe($n(r, "result_table_pub_span"));
391 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
393 if(!isNull(rec.publisher()) ) {
394 unHideMe( $n(r, "result_table_extra_span"));
395 unHideMe($n(r, "result_table_pub_span"));
396 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
399 if(!isNull(rec.physical_description()) ) {
401 unHideMe( $n(r, "result_table_extra_span"));
402 unHideMe($n(r, "result_table_pub_span"));
404 unHideMe( $n(r, "result_table_extra_span"));
405 var t = " " + rec.physical_description();
406 //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
407 $n(r, "result_table_phys_span").appendChild( text(t));
412 resultBuildFormatIcons( r, rec, is_mr );
416 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
419 if(resultPageIsDone()) {
420 runEvt('result', 'allRecordsReceived', recordsCache);
425 function _resultFindRec(id) {
426 for( var i = 0; i != recordsCache.length; i++ ) {
427 var rec = recordsCache[i];
428 if( rec && rec.doc_id() == id )
435 function resultBuildFormatIcons( row, rec, is_mr ) {
437 var ress = rec.types_of_resource();
439 for( var i in ress ) {
444 var link = $n(row, res + "_link");
446 var img = link.getElementsByTagName("img")[0];
447 removeCSSClass( img, config.css.dim );
451 if( f == modsFormatToMARC(res) )
452 addCSSClass( img, "dim2_border");
456 args[PARAM_OFFSET] = 0;
460 args[PARAM_TFORM] = modsFormatToMARC(res);
461 args[PARAM_MRID] = rec.doc_id();
465 args[PARAM_RID] = rec.doc_id();
468 link.setAttribute("href", buildOPACLink(args));
474 function resultPageIsDone(pos) {
475 return (recordsHandled == getDisplayCount()
476 || recordsHandled + getOffset() == getHitCount());
479 var resultCCHeaderApplied = false;
481 /* -------------------------------------------------------------------- */
482 /* dynamically add the copy count rows based on the org type 'countsrow'
483 is the row into which we will add TD's to hold the copy counts
484 This code generates copy count cells with an id of
485 'copy_count_cell_<depth>_<pagePosition>' */
486 function resultAddCopyCounts(rec, pagePosition) {
488 var r = table.rows[pagePosition + 1];
489 var countsrow = $n(r, config.names.result.counts_row );
490 var ccell = $n(countsrow, config.names.result.count_cell);
492 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
494 var type = findOrgType(node.ou_type());
495 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
496 ccell.title = type.opac_label();
497 //addCSSClass(ccell, config.css.result.cc_cell_even);
499 var lastcell = ccell;
500 var lastheadcell = null;
503 var ccheadcell = null;
504 if(!resultCCHeaderApplied) {
505 ccrow = $('result_thead_row');
506 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
507 var t = ccheadcell.cloneNode(true);
509 t.appendChild(text(type.opac_label()));
510 ccrow.appendChild(t);
511 resultCCHeaderApplied = true;
517 var d = findOrgDepth(nodes[1]);
518 var d2 = findOrgDepth(nodes[nodes.length -1]);
520 for( var i = d; i <= d2 ; i++ ) {
522 ccell = ccell.cloneNode(true);
524 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
525 //else addCSSClass(ccell, "copy_count_cell_even");
527 var node = nodes[x++];
528 var type = findOrgType(node.ou_type());
530 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
531 ccell.title = type.opac_label();
532 countsrow.insertBefore(ccell, lastcell);
536 var t = ccheadcell.cloneNode(true);
537 t.appendChild(text(type.opac_label()));
538 ccrow.insertBefore(t, lastheadcell);
544 unHideMe($("search_info_table"));
547 /* collect copy counts for a record using method 'methodName' */
548 function resultCollectCopyCounts(rec, pagePosition, methodName) {
549 if(rec == null || rec.doc_id() == null) return;
550 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
551 req.request.userdata = [ rec, pagePosition ];
552 req.callback(resultHandleCopyCounts);
556 function resultHandleCopyCounts(r) {
557 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
561 /* display the collected copy counts */
562 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
563 if(copy_counts == null || rec == null) return;
565 while(copy_counts[i] != null) {
566 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
568 var span = cell.getElementsByTagName("div")[0];
570 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));