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(/,/);
71 //alert(js2JSON(args));
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() ));
401 resultBuildFormatIcons( r, rec, is_mr );
405 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
408 if(resultPageIsDone()) {
409 runEvt('result', 'allRecordsReceived', recordsCache);
414 function _resultFindRec(id) {
415 for( var i = 0; i != recordsCache.length; i++ ) {
416 var rec = recordsCache[i];
417 if( rec && rec.doc_id() == id )
424 function resultBuildFormatIcons( row, rec, is_mr ) {
426 var ress = rec.types_of_resource();
428 for( var i in ress ) {
431 var link = $n(row, res + "_link");
433 var img = link.getElementsByTagName("img")[0];
434 removeCSSClass( img, config.css.dim );
438 if( f == modsFormatToMARC(res) )
439 addCSSClass( img, "dim2_border");
443 args[PARAM_OFFSET] = 0;
444 args[PARAM_FORM] = modsFormatToMARC(res);
448 args[PARAM_MRID] = rec.doc_id();
451 args[PARAM_RID] = rec.doc_id();
454 link.setAttribute("href", buildOPACLink(args));
460 function resultPageIsDone(pos) {
461 return (recordsHandled == getDisplayCount()
462 || recordsHandled + getOffset() == getHitCount());
465 var resultCCHeaderApplied = false;
467 /* -------------------------------------------------------------------- */
468 /* dynamically add the copy count rows based on the org type 'countsrow'
469 is the row into which we will add TD's to hold the copy counts
470 This code generates copy count cells with an id of
471 'copy_count_cell_<depth>_<pagePosition>' */
472 function resultAddCopyCounts(rec, pagePosition) {
474 var r = table.rows[pagePosition + 1];
475 var countsrow = $n(r, config.names.result.counts_row );
476 var ccell = $n(countsrow, config.names.result.count_cell);
478 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
480 var type = findOrgType(node.ou_type());
481 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
482 ccell.title = type.opac_label();
483 //addCSSClass(ccell, config.css.result.cc_cell_even);
485 var lastcell = ccell;
486 var lastheadcell = null;
489 var ccheadcell = null;
490 if(!resultCCHeaderApplied) {
491 ccrow = $('result_thead_row');
492 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
493 var t = ccheadcell.cloneNode(true);
495 t.appendChild(text(type.opac_label()));
496 ccrow.appendChild(t);
497 resultCCHeaderApplied = true;
503 var d = findOrgDepth(nodes[1]);
504 var d2 = findOrgDepth(nodes[nodes.length -1]);
506 for( var i = d; i <= d2 ; i++ ) {
508 ccell = ccell.cloneNode(true);
510 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
511 //else addCSSClass(ccell, "copy_count_cell_even");
513 var node = nodes[x++];
514 var type = findOrgType(node.ou_type());
516 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
517 ccell.title = type.opac_label();
518 countsrow.insertBefore(ccell, lastcell);
522 var t = ccheadcell.cloneNode(true);
523 t.appendChild(text(type.opac_label()));
524 ccrow.insertBefore(t, lastheadcell);
530 unHideMe($("search_info_table"));
533 /* collect copy counts for a record using method 'methodName' */
534 function resultCollectCopyCounts(rec, pagePosition, methodName) {
535 if(rec == null || rec.doc_id() == null) return;
536 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
537 req.request.userdata = [ rec, pagePosition ];
538 req.callback(resultHandleCopyCounts);
542 function resultHandleCopyCounts(r) {
543 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
547 /* display the collected copy counts */
548 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
549 if(copy_counts == null || rec == null) return;
551 while(copy_counts[i] != null) {
552 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
554 var span = cell.getElementsByTagName("div")[0];
556 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));