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');
109 if(getHitCount() == 0) {
110 runEvt('result', 'zeroHits');
115 var pages = getHitCount() / getDisplayCount();
116 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 /* set the offsets */
126 var offsetEnd = getDisplayCount() + getOffset();
127 if( getDisplayCount() > (getHitCount() - getOffset()))
128 offsetEnd = getHitCount();
130 G.ui.result.offset_end.appendChild(text(offsetEnd));
131 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
133 G.ui.result.result_count.appendChild(text(getHitCount()));
134 unHideMe(G.ui.result.info);
137 function resultLowHits() {
139 unHideMe($('result_low_hits'));
140 if(getHitCount() > 0)
141 unHideMe($('result_low_hits_msg'));
143 var sreq = new Request(CHECK_SPELL, getTerm());
144 sreq.callback(resultSuggestSpelling);
147 var words = getTerm().split(' ');
149 while( word = words.shift() ) {
150 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
151 areq.callback(resultLowHitXRef);
155 if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
157 a[PARAM_FORM] = "all";
158 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
159 unHideMe($('low_hits_remove_format'));
162 resultSuggestSearchClass();
166 var lowHitsXRefLinkParent;
167 function resultLowHitXRef(r) {
168 if(!lowHitsXRefLink){
169 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
170 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
172 var res = r.getResultObject();
174 arr.concat(res.also);
175 if(arr && arr.length > 0) {
176 unHideMe($('low_hits_cross_ref'));
179 while( word = arr.shift() ) {
182 a[PARAM_TERM] = word;
183 var template = lowHitsXRefLink.cloneNode(true);
184 template.setAttribute('href',buildOPACLink(a));
185 template.appendChild(text(word));
186 lowHitsXRefLinkParent.appendChild(template);
187 lowHitsXRefLinkParent.appendChild(text(' '));
192 function resultZeroHits() {
194 unHideMe($('result_low_hits'));
195 unHideMe($('result_zero_hits_msg'));
196 if(getTerm()) resultExpandSearch(); /* advanced search */
199 function resultExpandSearch() {
200 var top = findOrgDepth(globalOrgTree);
201 if(getDepth() == top) return;
202 unHideMe($('low_hits_expand_range'));
203 var par = $('low_hits_expand_link').parentNode;
204 var template = par.removeChild($('low_hits_expand_link'));
206 var bottom = getDepth();
207 while( top < bottom ) {
209 a[PARAM_DEPTH] = top;
210 var temp = template.cloneNode(true);
211 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
212 temp.setAttribute('href',buildOPACLink(a));
213 par.appendChild(temp);
218 function resultSuggestSearchClass() {
219 var stype = getStype();
220 if(stype == STYPE_KEYWORD) return;
222 unHideMe($('low_hits_search_type'));
223 if(stype != STYPE_TITLE) {
224 ref = $('low_hits_title_search');
226 a[PARAM_STYPE] = STYPE_TITLE;
227 ref.setAttribute('href',buildOPACLink(a));
229 if(stype != STYPE_AUTHOR) {
230 ref = $('low_hits_author_search');
232 a[PARAM_STYPE] = STYPE_AUTHOR;
233 ref.setAttribute('href',buildOPACLink(a));
235 if(stype != STYPE_SUBJECT) {
236 ref = $('low_hits_subject_search');
238 a[PARAM_STYPE] = STYPE_SUBJECT;
239 ref.setAttribute('href',buildOPACLink(a));
241 if(stype != STYPE_KEYWORD) {
242 ref = $('low_hits_keyword_search');
244 a[PARAM_STYPE] = STYPE_KEYWORD;
245 ref.setAttribute('href',buildOPACLink(a));
247 if(stype != STYPE_SERIES) {
248 ref = $('low_hits_series_search');
250 a[PARAM_STYPE] = STYPE_SERIES;
251 ref.setAttribute('href',buildOPACLink(a));
255 function resultSuggestSpelling(r) {
256 var res = r.getResultObject();
258 unHideMe($('did_you_mean'));
260 arg[PARAM_TERM] = res;
261 $('spell_check_link').setAttribute(
262 'href', buildOPACLink(arg) );
263 $('spell_check_link').appendChild(text(res));
268 function resultPaginate() {
271 if( !(( (o+1) + getDisplayCount()) >= getHitCount()) ) {
274 args[PARAM_OFFSET] = o + getDisplayCount();
275 args[PARAM_SORT] = SORT;
276 args[PARAM_SORT_DIR] = SORT_DIR;
277 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
279 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
280 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
282 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
284 /* when hit count is divisible by display count, we have to adjust */
285 if( getHitCount() % getDisplayCount() == 0 )
286 args[PARAM_OFFSET] -= getDisplayCount();
288 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
289 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
295 args[PARAM_SORT] = SORT;
296 args[PARAM_SORT_DIR] = SORT_DIR;
297 args[PARAM_RLIST] = new CGI().param(PARAM_RLIST);
299 args[PARAM_OFFSET] = o - getDisplayCount();
300 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
301 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
303 args[PARAM_OFFSET] = 0;
304 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
305 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
308 if(getDisplayCount() < getHitCount())
309 unHideMe($('start_end_links_span'));
312 try{searchTimer.stop()}catch(e){}
315 function buildunAPISpan (span, type, id) {
319 addCSSClass(span,'unapi-id');
323 'tag:' + cgi.server_name + ',' +
325 ':' + type + '/' + id
329 /* display the record info in the record display table 'pos' is the
330 zero based position the record should have in the display table */
331 function resultDisplayRecord(rec, pos, is_mr) {
333 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
335 recordsCache.push(rec);
337 var r = table.rows[pos + 1];
341 var rank = parseFloat(ranks[pos + getOffset()]);
342 rank = parseInt( rank * 100 );
343 var relspan = $n(r, "relevancy_span");
344 relspan.appendChild(text(rank));
345 unHideMe(relspan.parentNode);
348 var pic = $n(r, config.names.result.item_jacket);
349 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
351 var title_link = $n(r, config.names.result.item_title);
352 var author_link = $n(r, config.names.result.item_author);
355 var onlyrec = onlyrecord[ getOffset() + pos ];
357 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
361 args[PARAM_OFFSET] = 0;
362 args[PARAM_RID] = onlyrec;
363 args[PARAM_MRID] = rec.doc_id();
364 pic.parentNode.setAttribute("href", buildOPACLink(args));
365 title_link.setAttribute("href", buildOPACLink(args));
366 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
369 buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
371 buildTitleLink(rec, title_link);
374 args[PARAM_OFFSET] = 0;
375 args[PARAM_MRID] = rec.doc_id();
376 pic.parentNode.setAttribute("href", buildOPACLink(args));
380 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
382 buildTitleDetailLink(rec, title_link);
385 args[PARAM_OFFSET] = 0;
386 args[PARAM_RID] = rec.doc_id();
387 pic.parentNode.setAttribute("href", buildOPACLink(args));
389 unHideMe($n(r,'place_hold_span'));
390 $n(r,'place_hold_link').setAttribute(
391 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
394 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
398 if(!isNull(rec.edition())) {
399 unHideMe( $n(r, "result_table_extra_span"));
400 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
402 if(!isNull(rec.pubdate())) {
403 unHideMe( $n(r, "result_table_extra_span"));
404 unHideMe($n(r, "result_table_pub_span"));
405 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
407 if(!isNull(rec.publisher()) ) {
408 unHideMe( $n(r, "result_table_extra_span"));
409 unHideMe($n(r, "result_table_pub_span"));
410 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
413 if(!isNull(rec.physical_description()) ) {
414 unHideMe( $n(r, "result_table_extra_span"));
415 var t = " " + rec.physical_description();
416 //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
417 $n(r, "result_table_phys_span").appendChild( text(t));
422 resultBuildFormatIcons( r, rec, is_mr );
426 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
429 if(resultPageIsDone()) {
430 runEvt('result', 'allRecordsReceived', recordsCache);
435 function _resultFindRec(id) {
436 for( var i = 0; i != recordsCache.length; i++ ) {
437 var rec = recordsCache[i];
438 if( rec && rec.doc_id() == id )
445 function resultBuildFormatIcons( row, rec, is_mr ) {
447 var ress = rec.types_of_resource();
449 for( var i in ress ) {
454 var link = $n(row, res + "_link");
456 var img = link.getElementsByTagName("img")[0];
457 removeCSSClass( img, config.css.dim );
461 if( f == modsFormatToMARC(res) )
462 addCSSClass( img, "dim2_border");
466 args[PARAM_OFFSET] = 0;
470 args[PARAM_TFORM] = modsFormatToMARC(res);
471 args[PARAM_MRID] = rec.doc_id();
475 args[PARAM_RID] = rec.doc_id();
478 link.setAttribute("href", buildOPACLink(args));
484 function resultPageIsDone(pos) {
485 return (recordsHandled == getDisplayCount()
486 || recordsHandled + getOffset() == getHitCount());
489 var resultCCHeaderApplied = false;
491 /* -------------------------------------------------------------------- */
492 /* dynamically add the copy count rows based on the org type 'countsrow'
493 is the row into which we will add TD's to hold the copy counts
494 This code generates copy count cells with an id of
495 'copy_count_cell_<depth>_<pagePosition>' */
496 function resultAddCopyCounts(rec, pagePosition) {
498 var r = table.rows[pagePosition + 1];
499 var countsrow = $n(r, config.names.result.counts_row );
500 var ccell = $n(countsrow, config.names.result.count_cell);
502 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
504 var type = findOrgType(node.ou_type());
505 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
506 ccell.title = type.opac_label();
507 //addCSSClass(ccell, config.css.result.cc_cell_even);
509 var lastcell = ccell;
510 var lastheadcell = null;
513 var ccheadcell = null;
514 if(!resultCCHeaderApplied) {
515 ccrow = $('result_thead_row');
516 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
517 var t = ccheadcell.cloneNode(true);
519 t.appendChild(text(type.opac_label()));
520 ccrow.appendChild(t);
521 resultCCHeaderApplied = true;
527 var d = findOrgDepth(nodes[1]);
528 var d2 = findOrgDepth(nodes[nodes.length -1]);
530 for( var i = d; i <= d2 ; i++ ) {
532 ccell = ccell.cloneNode(true);
534 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
535 //else addCSSClass(ccell, "copy_count_cell_even");
537 var node = nodes[x++];
538 var type = findOrgType(node.ou_type());
540 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
541 ccell.title = type.opac_label();
542 countsrow.insertBefore(ccell, lastcell);
546 var t = ccheadcell.cloneNode(true);
547 t.appendChild(text(type.opac_label()));
548 ccrow.insertBefore(t, lastheadcell);
554 unHideMe($("search_info_table"));
557 /* collect copy counts for a record using method 'methodName' */
558 function resultCollectCopyCounts(rec, pagePosition, methodName) {
559 if(rec == null || rec.doc_id() == null) return;
560 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
561 req.request.userdata = [ rec, pagePosition ];
562 req.callback(resultHandleCopyCounts);
566 function resultHandleCopyCounts(r) {
567 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
571 /* display the collected copy counts */
572 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
573 if(copy_counts == null || rec == null) return;
575 while(copy_counts[i] != null) {
576 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
577 var cts = copy_counts[i];
578 cell.appendChild(text(cts.available + " / " + cts.count));
581 /* here we style opac-invisible records for xul */
583 if( cts.depth == 0 ) {
585 _debug("found an opac-shadowed record: " + rec.doc_id());
586 var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode;
588 addCSSClass( row, 'no_copies' );
590 addCSSClass( row, 'shadowed' );