2 var recordsHandled = 0;
5 /* set up the event handlers */
6 G.evt.result.hitCountReceived.push(resultSetHitInfo);
7 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
8 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
9 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
11 attachEvt( "common", "locationUpdated", resultSBSubmit );
12 function resultSBSubmit(){searchBarSubmit();}
14 /* do this after we have ID's so the rank for mr pages will be correct */
15 attachEvt("result", "preCollectRecords", resultPaginate);
17 /* returns the last 'index' postion ocurring in this page */
18 function resultFinalPageIndex() {
19 if(getHitCount() < (getOffset() + getDisplayCount()))
20 return getHitCount() - 1;
21 return getOffset() + getDisplayCount() - 1;
24 /* set the search result info, number of hits, which results we're
25 displaying, links to the next/prev pages, etc. */
26 function resultSetHitInfo() {
28 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
29 else c = getDisplayCount() + getOffset();
31 var pages = getHitCount() / getDisplayCount();
32 if(pages % 1) pages = parseInt(pages) + 1;
34 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
35 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
37 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
38 G.ui.result.offset_end.appendChild(text(c));
39 G.ui.result.result_count.appendChild(text(getHitCount()));
40 unHideMe(G.ui.result.info);
44 function resultPaginate() {
47 if( !((o + getDisplayCount()) >= getHitCount()) ) {
50 args[PARAM_OFFSET] = o + getDisplayCount();
51 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
52 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
54 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
55 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
56 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
62 args[PARAM_OFFSET] = o - getDisplayCount();
63 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
64 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
66 args[PARAM_OFFSET] = 0;
67 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
68 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
70 if(getDisplayCount() < getHitCount())
71 unHideMe($('start_end_links_span'));
75 /* display the record info in the record display table 'pos' is the
76 zero based position the record should have in the display table */
77 function resultDisplayRecord(rec, pos, is_mr) {
79 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
81 recordsCache.push(rec);
83 var r = table.rows[pos + 1];
86 var rank = parseFloat(ranks[pos + getOffset()]);
87 rank = ( rank / getTopRank() ) * 100;
88 rank = parseInt(rank) + "%";
89 var relspan = $n(r, "relevancy_span");
90 relspan.appendChild(text(rank));
91 unHideMe(relspan.parentNode);
94 var pic = $n(r, config.names.result.item_jacket);
95 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
97 var title_link = $n(r, config.names.result.item_title);
98 var author_link = $n(r, config.names.result.item_author);
101 var onlyrec = onlyrecord[ getOffset() + pos ];
105 args[PARAM_OFFSET] = 0;
106 args[PARAM_RID] = onlyrec;
107 args[PARAM_MRID] = rec.doc_id();
108 pic.parentNode.setAttribute("href", buildOPACLink(args));
109 title_link.setAttribute("href", buildOPACLink(args));
110 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
113 buildTitleLink(rec, title_link);
116 args[PARAM_OFFSET] = 0;
117 args[PARAM_MRID] = rec.doc_id();
118 pic.parentNode.setAttribute("href", buildOPACLink(args));
122 buildTitleDetailLink(rec, title_link);
125 args[PARAM_OFFSET] = 0;
126 args[PARAM_RID] = rec.doc_id();
127 pic.parentNode.setAttribute("href", buildOPACLink(args));
129 unHideMe($n(r,'place_hold_span'));
130 $n(r,'place_hold_link').setAttribute(
131 'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
134 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
138 if(!isNull(rec.edition())) {
139 unHideMe( $n(r, "result_table_extra_span"));
140 $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
142 if(!isNull(rec.pubdate())) {
143 unHideMe( $n(r, "result_table_extra_span"));
144 unHideMe($n(r, "result_table_pub_span"));
145 $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
147 if(!isNull(rec.publisher()) ) {
148 unHideMe( $n(r, "result_table_extra_span"));
149 unHideMe($n(r, "result_table_pub_span"));
150 $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
154 resultBuildFormatIcons( r, rec );
158 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
160 if(resultPageIsDone()) {
161 /* hide the 'now loading...' message */
163 hideMe(G.ui.common.loading);
165 runEvt('result', 'allRecordsReceived', recordsCache);
169 function _resultFindRec(id) {
170 for( var i = 0; i != recordsCache.length; i++ ) {
171 var rec = recordsCache[i];
172 if( rec && rec.doc_id() == id )
179 var currentHoldRecord;
180 var holdsOrgSelectorBuilt = false;
181 function resultDrawHoldsWindow(recid) {
184 recid = currentHoldRecord;
185 if(recid == null) return;
187 currentHoldRecord = recid;
189 detachEvt('common','locationUpdated', resultSBSubmit );
190 attachEvt( "common", "locationUpdated", resultSBSubmit );
192 if(!(G.user && G.user.session)) {
194 detachEvt('common','locationUpdated', resultSBSubmit );
195 attachEvt('common','loggedIn', resultDrawHoldsWindow)
196 //alert(G.evt['common']['locationUpdated']);
198 //attachEvt( "common", "locationUpdated", resultSBSubmit );
201 swapCanvas($('holds_box'));
203 var rec = _resultFindRec(recid);
205 if(!holdsOrgSelectorBuilt) {
206 resultBuildHoldsSelector(null, 0);
207 holdsOrgSelectorBuilt = true;
210 removeChildren($('holds_title'));
211 removeChildren($('holds_author'));
212 removeChildren($('holds_format'));
213 removeChildren($('holds_email'));
214 removeChildren($('holds_email'));
216 $('holds_title').appendChild(text(rec.title()));
217 $('holds_author').appendChild(text(rec.author()));
219 for( var i in rec.types_of_resource() ) {
220 var res = rec.types_of_resource()[i];
221 var img = elem("img");
222 setResourcePic(img, res);
223 $('holds_format').appendChild(text(' '+res+' '));
224 $('holds_format').appendChild(img);
225 $('holds_format').appendChild(text(' '));
228 $('holds_phone').appendChild(text(G.user.day_phone()));
229 $('holds_email').appendChild(text(G.user.email()));
230 $('holds_cancel').onclick = showCanvas;
231 $('holds_submit').onclick = resultPlaceHold;
235 function resultBuildHoldsSelector(node, depth) {
238 node = globalOrgTree;
242 var selector = $('holds_org_selector');
243 var index = selector.options.length;
246 var pre = elem("pre");
247 for(var x=2; x <= findOrgType(node.ou_type()).depth(); x++) {
248 pre.appendChild(text(" "));
250 pre.appendChild(text(node.name()));
251 var select = new Option("", node.id());
252 selector.options[index] = select;
253 select.appendChild(pre);
256 var pad = (findOrgType(node.ou_type()).depth() - 1) * 12;
258 var select = new Option(node.name(), node.id());
259 select.setAttribute("style", "padding-left: "+pad+'px;');
260 selector.options[index] = select;
263 if( node.id() == getLocation() ) {
264 selector.selectedIndex = index;
265 selector.options[index].selected = true;
268 for( var i in node.children() ) {
269 var child = node.children()[i];
271 resultBuildHoldsSelector(child, depth+1);
276 function resultPlaceHold() {
277 var hold = new ahr();
278 hold.pickup_lib( 1 );
279 hold.requestor(G.user.id());
280 hold.usr(G.user.id());
282 hold.email_notify(G.user.email());
283 hold.phone_notify(G.user.day_phone());
284 hold.target(currentHoldRecord);
286 var req = new Request( CREATE_HOLD, G.user.session, hold );
288 var res = req.result();
293 alert('hold failed');
300 function resultBuildFormatIcons( row, rec ) {
302 var ress = rec.types_of_resource();
304 for( var i in ress ) {
307 var link = $n(row, res + "_link");
309 var img = link.getElementsByTagName("img")[0];
310 removeCSSClass( img, config.css.dim );
314 if( f == modsFormatToMARC(res) )
315 addCSSClass( img, "dim2_border");
320 args[PARAM_OFFSET] = 0;
321 args[PARAM_MRID] = rec.doc_id();
322 args[PARAM_FORM] = modsFormatToMARC(res);
324 link.setAttribute("href", buildOPACLink(args));
330 function resultPageIsDone(pos) {
331 return (recordsHandled == getDisplayCount()
332 || recordsHandled + getOffset() == getHitCount());
335 var resultCCHeaderApplied = false;
337 /* -------------------------------------------------------------------- */
338 /* dynamically add the copy count rows based on the org type 'countsrow'
339 is the row into which we will add TD's to hold the copy counts
340 This code generates copy count cells with an id of
341 'copy_count_cell_<depth>_<pagePosition>' */
342 function resultAddCopyCounts(rec, pagePosition) {
344 var r = table.rows[pagePosition + 1];
345 var countsrow = $n(r, config.names.result.counts_row );
346 var ccell = $n(countsrow, config.names.result.count_cell);
348 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
350 var type = findOrgType(node.ou_type());
351 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
352 ccell.title = type.opac_label();
353 //addCSSClass(ccell, config.css.result.cc_cell_even);
355 var lastcell = ccell;
356 var lastheadcell = null;
359 var ccheadcell = null;
360 if(!resultCCHeaderApplied) {
361 ccrow = $('result_thead_row');
362 ccheadcell = ccrow.removeChild($n(ccrow, "result_thead_ccell"));
363 var t = ccheadcell.cloneNode(true);
365 t.appendChild(text(type.opac_label()));
366 ccrow.appendChild(t);
367 resultCCHeaderApplied = true;
373 var d = findOrgDepth(nodes[1]);
374 var d2 = findOrgDepth(nodes[nodes.length -1]);
376 for( var i = d; i <= d2 ; i++ ) {
378 ccell = ccell.cloneNode(true);
380 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
381 //else addCSSClass(ccell, "copy_count_cell_even");
383 var node = nodes[x++];
384 var type = findOrgType(node.ou_type());
386 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
387 ccell.title = type.opac_label();
388 countsrow.insertBefore(ccell, lastcell);
392 var t = ccheadcell.cloneNode(true);
393 t.appendChild(text(type.opac_label()));
394 ccrow.insertBefore(t, lastheadcell);
400 unHideMe($("search_info_table"));
403 /* collect copy counts for a record using method 'methodName' */
404 function resultCollectCopyCounts(rec, pagePosition, methodName) {
405 if(rec == null || rec.doc_id() == null) return;
406 var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
407 req.request.userdata = [ rec, pagePosition ];
408 req.callback(resultHandleCopyCounts);
412 function resultHandleCopyCounts(r) {
413 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
417 /* display the collected copy counts */
418 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
419 if(copy_counts == null || rec == null) return;
421 while(copy_counts[i] != null) {
422 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
424 var span = cell.getElementsByTagName("div")[0];
426 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
433 /* captures extraneous info from each record */
435 var subjectCache = {};
436 var authorCache = {};
437 var seriesCache = {};
439 function resultBuildCaches(records) {
440 for( var r in records ) {
441 var rec = records[r];
442 for( var s in rec.subject() )
443 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
444 authorCache[rec.author()] = 1;
445 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
449 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
450 function resultDrawSubjects() {
453 for( var s in subjectCache )
454 subjs.push( { sub : s, count : subjectCache[s] } );
455 subjs.sort(resultSortSubjects);
458 for( var s in subjs ) ss.push(subjs[s].sub);
460 resultDrawSidebarTrees(
462 "subjectSidebarTree", ss,
463 $("subject_tree_sidebar"),
464 $("subject_sidebar_tree_div") );
467 function resultDrawAuthors() {
468 var auths = new Array();
469 for( var s in authorCache ) auths.push(s);
471 resultDrawSidebarTrees(
473 "authorSidebarTree", auths.sort(),
474 $("author_tree_sidebar"),
475 $("author_sidebar_tree_div") );
478 function resultDrawSeries() {
479 var sers = new Array();
480 for( var s in seriesCache ) sers.push(s);
481 resultDrawSidebarTrees(
483 "seriesSidebarTree", sers.sort(),
484 $("series_tree_sidebar"),
485 $("series_sidebar_tree_div") );
488 function resultDrawSidebarTrees( stype, treeName, items, wrapperNode, destNode ) {
490 eval("tree = " + treeName);
494 for( var i in items ) {
496 if(isNull(items[i])) continue;
500 var item = normalize(truncate(items[i], 65));
503 var href = resultQuickLink( items[i], stype );
504 tree.addNode( stype + "_" + items[i], treeName + 'Root', item, href );
508 setTimeout('resultFireXRefReq("'+treeName+'","'+stype+'","'+item+'");',200);
510 if(!IE) resultFireXRefReq(treeName, stype, items[i]);
514 unHideMe(wrapperNode);
515 //tree.close(tree.rootid);
519 function resultFireXRefReq( treeName, stype, item ) {
521 eval('tree=' + treeName);
522 var req = new Request(FETCH_CROSSREF, stype, item);
523 req.request._tree = tree;
524 req.request._item = item;
525 req.request._stype = stype;
526 req.callback(resultAppendCrossRef);
531 function resultQuickLink( term, type ) {
534 args[PARAM_OFFSET] = 0;
535 args[PARAM_TERM] = term;
536 args[PARAM_STYPE] = type;
537 return buildOPACLink(args);
541 function resultAppendCrossRef(r) {
544 var stype = r._stype;
545 var result = r.getResultObject();
547 var froms = result['from'];
548 var alsos = result['also'];
552 for( var i = 0; (total++ < 5 && i < froms.length); i++ ) {
553 var string = normalize(truncate(froms[i], 45));
554 if($(stype + '_' + froms[i])) continue;
555 tree.addNode(stype + '_' + froms[i],
556 stype + '_' + item, string, resultQuickLink(froms[i],stype));
558 for( var i = 0; (total++ < 10 && i < alsos.length); i++ ) {
559 var string = normalize(truncate(alsos[i], 45));
560 if($(stype + '_' + alsos[i])) continue;
561 tree.addNode(stype + '_' + alsos[i],
562 stype + '_' + item, string, resultQuickLink(alsos[i],stype));