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() ));
400 resultBuildFormatIcons( r, rec, is_mr );
404 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
407 if(resultPageIsDone()) {
408 runEvt('result', 'allRecordsReceived', recordsCache);
413 function _resultFindRec(id) {
414 for( var i = 0; i != recordsCache.length; i++ ) {
415 var rec = recordsCache[i];
416 if( rec && rec.doc_id() == id )
423 function resultBuildFormatIcons( row, rec, is_mr ) {
425 var ress = rec.types_of_resource();
427 for( var i in ress ) {
430 var link = $n(row, res + "_link");
432 var img = link.getElementsByTagName("img")[0];
433 removeCSSClass( img, config.css.dim );
437 if( f == modsFormatToMARC(res) )
438 addCSSClass( img, "dim2_border");
442 args[PARAM_OFFSET] = 0;
444 args[PARAM_FORM] = modsFormatToMARC(res);
449 args[PARAM_TFORM] = modsFormatToMARC(res);
450 args[PARAM_MRID] = rec.doc_id();
454 args[PARAM_RID] = rec.doc_id();
457 link.setAttribute("href", buildOPACLink(args));
463 function resultPageIsDone(pos) {
464 return (recordsHandled == getDisplayCount()
465 || recordsHandled + getOffset() == getHitCount());
468 var resultCCHeaderApplied = false;
470 /* -------------------------------------------------------------------- */
471 /* dynamically add the copy count rows based on the org type 'countsrow'
472 is the row into which we will add TD's to hold the copy counts
473 This code generates copy count cells with an id of
474 'copy_count_cell_<depth>_<pagePosition>' */
475 function resultAddCopyCounts(rec, pagePosition) {
477 var r = table.rows[pagePosition + 1];
478 var countsrow = $n(r, config.names.result.counts_row );
479 var ccell = $n(countsrow, config.names.result.count_cell);
481 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
483 var type = findOrgType(node.ou_type());
484 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
485 ccell.title = type.opac_label();
486 //addCSSClass(ccell, config.css.result.cc_cell_even);
488 var lastcell = ccell;
489 var lastheadcell = null;
492 var ccheadcell = null;
493 if(!resultCCHeaderApplied) {
494 ccrow = $('result_thead_row');
495 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
496 var t = ccheadcell.cloneNode(true);
498 t.appendChild(text(type.opac_label()));
499 ccrow.appendChild(t);
500 resultCCHeaderApplied = true;
506 var d = findOrgDepth(nodes[1]);
507 var d2 = findOrgDepth(nodes[nodes.length -1]);
509 for( var i = d; i <= d2 ; i++ ) {
511 ccell = ccell.cloneNode(true);
513 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
514 //else addCSSClass(ccell, "copy_count_cell_even");
516 var node = nodes[x++];
517 var type = findOrgType(node.ou_type());
519 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
520 ccell.title = type.opac_label();
521 countsrow.insertBefore(ccell, lastcell);
525 var t = ccheadcell.cloneNode(true);
526 t.appendChild(text(type.opac_label()));
527 ccrow.insertBefore(t, lastheadcell);
533 unHideMe($("search_info_table"));
536 /* collect copy counts for a record using method 'methodName' */
537 function resultCollectCopyCounts(rec, pagePosition, methodName) {
538 if(rec == null || rec.doc_id() == null) return;
539 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
540 req.request.userdata = [ rec, pagePosition ];
541 req.callback(resultHandleCopyCounts);
545 function resultHandleCopyCounts(r) {
546 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
550 /* display the collected copy counts */
551 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
552 if(copy_counts == null || rec == null) return;
554 while(copy_counts[i] != null) {
555 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
557 var span = cell.getElementsByTagName("div")[0];
559 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));