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);
12 attachEvt('result','lowHits',resultLowHits);
13 attachEvt('result','zeroHits',resultZeroHits);
15 attachEvt( "common", "locationUpdated", resultSBSubmit );
16 function resultSBSubmit(){searchBarSubmit();}
18 /* do this after we have ID's so the rank for mr pages will be correct */
19 attachEvt("result", "preCollectRecords", resultPaginate);
21 /* returns the last 'index' postion ocurring in this page */
22 function resultFinalPageIndex() {
23 if(getHitCount() < (getOffset() + getDisplayCount()))
24 return getHitCount() - 1;
25 return getOffset() + getDisplayCount() - 1;
28 /* set the search result info, number of hits, which results we're
29 displaying, links to the next/prev pages, etc. */
30 function resultSetHitInfo() {
31 if( findCurrentPage() == MRESULT ) {
32 if(getHitCount() <= lowHitCount)
33 runEvt('result', 'lowHits');
34 if(getHitCount() == 0) {
35 runEvt('result', 'zeroHits');
41 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
42 else c = getDisplayCount() + getOffset();
44 var pages = getHitCount() / getDisplayCount();
45 if(pages % 1) pages = parseInt(pages) + 1;
47 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
48 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
50 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
51 G.ui.result.offset_end.appendChild(text(c));
52 G.ui.result.result_count.appendChild(text(getHitCount()));
53 unHideMe(G.ui.result.info);
56 function resultLowHits() {
57 try{searchTimer.stop()}catch(e){}
59 unHideMe($('result_low_hits'));
61 unHideMe($('result_low_hits_msg'));
63 var sreq = new Request(CHECK_SPELL, getTerm());
64 sreq.callback(resultSuggestSpelling);
67 var words = getTerm().split(' ');
69 while( word = words.shift() ) {
70 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
71 areq.callback(resultLowHitXRef);
75 if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
77 a[PARAM_FORM] = "all";
78 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
79 unHideMe($('low_hits_remove_format'));
82 resultSuggestSearchClass();
86 var lowHitsXRefLinkParent;
87 function resultLowHitXRef(r) {
89 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
90 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
92 var res = r.getResultObject();
95 if(arr && arr.length > 0) {
96 unHideMe($('low_hits_cross_ref'));
99 while( word = arr.shift() ) {
102 a[PARAM_TERM] = word;
103 var template = lowHitsXRefLink.cloneNode(true);
104 template.setAttribute('href',buildOPACLink(a));
105 template.appendChild(text(word));
106 lowHitsXRefLinkParent.appendChild(template);
107 lowHitsXRefLinkParent.appendChild(text(' '));
112 function resultZeroHits() {
113 unHideMe($('result_zero_hits_msg'));
114 resultExpandSearch();
117 function resultExpandSearch() {
118 var top = findOrgDepth(globalOrgTree);
119 if(getDepth() == top) return;
120 unHideMe($('low_hits_expand_range'));
121 var par = $('low_hits_expand_link').parentNode;
122 var template = par.removeChild($('low_hits_expand_link'));
124 var bottom = getDepth();
125 while( top < bottom ) {
127 a[PARAM_DEPTH] = top;
128 var temp = template.cloneNode(true);
129 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
130 temp.setAttribute('href',buildOPACLink(a));
131 par.appendChild(temp);
136 function resultSuggestSearchClass() {
137 var stype = getStype();
138 if(stype == STYPE_KEYWORD) return;
140 unHideMe($('low_hits_search_type'));
141 if(stype != STYPE_TITLE) {
142 ref = $('low_hits_title_search');
144 a[PARAM_STYPE] = STYPE_TITLE;
145 ref.setAttribute('href',buildOPACLink(a));
147 if(stype != STYPE_AUTHOR) {
148 ref = $('low_hits_author_search');
150 a[PARAM_STYPE] = STYPE_AUTHOR;
151 ref.setAttribute('href',buildOPACLink(a));
153 if(stype != STYPE_SUBJECT) {
154 ref = $('low_hits_subject_search');
156 a[PARAM_STYPE] = STYPE_SUBJECT;
157 ref.setAttribute('href',buildOPACLink(a));
159 if(stype != STYPE_KEYWORD) {
160 ref = $('low_hits_keyword_search');
162 a[PARAM_STYPE] = STYPE_KEYWORD;
163 ref.setAttribute('href',buildOPACLink(a));
165 if(stype != STYPE_SERIES) {
166 ref = $('low_hits_series_search');
168 a[PARAM_STYPE] = STYPE_SERIES;
169 ref.setAttribute('href',buildOPACLink(a));
173 function resultSuggestSpelling(r) {
174 var res = r.getResultObject();
176 unHideMe($('did_you_mean'));
178 arg[PARAM_TERM] = res;
179 $('spell_check_link').setAttribute(
180 'href', buildOPACLink(arg) );
181 $('spell_check_link').appendChild(text(res));
186 function resultPaginate() {
189 if( !((o + getDisplayCount()) >= getHitCount()) ) {
192 args[PARAM_OFFSET] = o + getDisplayCount();
193 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
194 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
196 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
197 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
198 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
204 args[PARAM_OFFSET] = o - getDisplayCount();
205 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
206 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
208 args[PARAM_OFFSET] = 0;
209 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
210 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
212 if(getDisplayCount() < getHitCount())
213 unHideMe($('start_end_links_span'));
216 try{searchTimer.stop()}catch(e){}
220 /* display the record info in the record display table 'pos' is the
221 zero based position the record should have in the display table */
222 function resultDisplayRecord(rec, pos, is_mr) {
224 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
226 recordsCache.push(rec);
228 var r = table.rows[pos + 1];
231 var rank = parseFloat(ranks[pos + getOffset()]);
232 rank = ( rank / getTopRank() ) * 100;
233 rank = parseInt(rank) + "%";
234 var relspan = $n(r, "relevancy_span");
235 relspan.appendChild(text(rank));
236 unHideMe(relspan.parentNode);
239 var pic = $n(r, config.names.result.item_jacket);
240 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
242 var title_link = $n(r, config.names.result.item_title);
243 var author_link = $n(r, config.names.result.item_author);
246 var onlyrec = onlyrecord[ getOffset() + pos ];
250 args[PARAM_OFFSET] = 0;
251 args[PARAM_RID] = onlyrec;
252 args[PARAM_MRID] = rec.doc_id();
253 pic.parentNode.setAttribute("href", buildOPACLink(args));
254 title_link.setAttribute("href", buildOPACLink(args));
255 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
258 buildTitleLink(rec, title_link);
261 args[PARAM_OFFSET] = 0;
262 args[PARAM_MRID] = rec.doc_id();
263 pic.parentNode.setAttribute("href", buildOPACLink(args));
267 buildTitleDetailLink(rec, title_link);
270 args[PARAM_OFFSET] = 0;
271 args[PARAM_RID] = rec.doc_id();
272 pic.parentNode.setAttribute("href", buildOPACLink(args));
274 unHideMe($n(r,'place_hold_span'));
275 $n(r,'place_hold_link').setAttribute(
276 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
279 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
283 if(!isNull(rec.edition())) {
284 unHideMe( $n(r, "result_table_extra_span"));
285 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
287 if(!isNull(rec.pubdate())) {
288 unHideMe( $n(r, "result_table_extra_span"));
289 unHideMe($n(r, "result_table_pub_span"));
290 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
292 if(!isNull(rec.publisher()) ) {
293 unHideMe( $n(r, "result_table_extra_span"));
294 unHideMe($n(r, "result_table_pub_span"));
295 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
299 resultBuildFormatIcons( r, rec );
303 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
305 if(resultPageIsDone()) {
307 /* hide the 'now loading...' message */
309 hideMe(G.ui.common.loading);
311 runEvt('result', 'allRecordsReceived', recordsCache);
315 function _resultFindRec(id) {
316 for( var i = 0; i != recordsCache.length; i++ ) {
317 var rec = recordsCache[i];
318 if( rec && rec.doc_id() == id )
325 function resultBuildFormatIcons( row, rec ) {
327 var ress = rec.types_of_resource();
329 for( var i in ress ) {
332 var link = $n(row, res + "_link");
334 var img = link.getElementsByTagName("img")[0];
335 removeCSSClass( img, config.css.dim );
339 if( f == modsFormatToMARC(res) )
340 addCSSClass( img, "dim2_border");
345 args[PARAM_OFFSET] = 0;
346 args[PARAM_MRID] = rec.doc_id();
347 args[PARAM_FORM] = modsFormatToMARC(res);
349 link.setAttribute("href", buildOPACLink(args));
355 function resultPageIsDone(pos) {
356 return (recordsHandled == getDisplayCount()
357 || recordsHandled + getOffset() == getHitCount());
360 var resultCCHeaderApplied = false;
362 /* -------------------------------------------------------------------- */
363 /* dynamically add the copy count rows based on the org type 'countsrow'
364 is the row into which we will add TD's to hold the copy counts
365 This code generates copy count cells with an id of
366 'copy_count_cell_<depth>_<pagePosition>' */
367 function resultAddCopyCounts(rec, pagePosition) {
369 var r = table.rows[pagePosition + 1];
370 var countsrow = $n(r, config.names.result.counts_row );
371 var ccell = $n(countsrow, config.names.result.count_cell);
373 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
375 var type = findOrgType(node.ou_type());
376 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
377 ccell.title = type.opac_label();
378 //addCSSClass(ccell, config.css.result.cc_cell_even);
380 var lastcell = ccell;
381 var lastheadcell = null;
384 var ccheadcell = null;
385 if(!resultCCHeaderApplied) {
386 ccrow = $('result_thead_row');
387 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
388 var t = ccheadcell.cloneNode(true);
390 t.appendChild(text(type.opac_label()));
391 ccrow.appendChild(t);
392 resultCCHeaderApplied = true;
398 var d = findOrgDepth(nodes[1]);
399 var d2 = findOrgDepth(nodes[nodes.length -1]);
401 for( var i = d; i <= d2 ; i++ ) {
403 ccell = ccell.cloneNode(true);
405 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
406 //else addCSSClass(ccell, "copy_count_cell_even");
408 var node = nodes[x++];
409 var type = findOrgType(node.ou_type());
411 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
412 ccell.title = type.opac_label();
413 countsrow.insertBefore(ccell, lastcell);
417 var t = ccheadcell.cloneNode(true);
418 t.appendChild(text(type.opac_label()));
419 ccrow.insertBefore(t, lastheadcell);
425 unHideMe($("search_info_table"));
428 /* collect copy counts for a record using method 'methodName' */
429 function resultCollectCopyCounts(rec, pagePosition, methodName) {
430 if(rec == null || rec.doc_id() == null) return;
431 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
432 req.request.userdata = [ rec, pagePosition ];
433 req.callback(resultHandleCopyCounts);
437 function resultHandleCopyCounts(r) {
438 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
442 /* display the collected copy counts */
443 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
444 if(copy_counts == null || rec == null) return;
446 while(copy_counts[i] != null) {
447 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
449 var span = cell.getElementsByTagName("div")[0];
451 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));