]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/result_common.js
3f757b07bcf1a7e1af35d58d97d918930d9eb2b1
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / result_common.js
1
2 var recordsHandled = 0;
3 var recordsCache = [];
4 var lowHitCount = 4;
5 var isbnList = '';
6 var googleBooks = true;
7
8 var resultFetchAllRecords = false;
9 var resultCompiledSearch = null;
10
11 /* set up the event handlers */
12 if( findCurrentPage() == MRESULT || findCurrentPage() == RRESULT ) {
13         G.evt.result.hitCountReceived.push(resultSetHitInfo);
14         G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
15         G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
16         G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, 
17       resultDrawAuthors, resultDrawSeries, function(){unHideMe($('result_info_2'))},
18           fetchGoogleBooks);
19
20         attachEvt('result','lowHits',resultLowHits);
21         attachEvt('result','zeroHits',resultZeroHits);
22         attachEvt( "common", "locationUpdated", resultSBSubmit );
23         /* do this after we have ID's so the rank for mr pages will be correct */
24         attachEvt("result", "preCollectRecords", resultPaginate);
25 }
26
27 function resultSBSubmit(){searchBarSubmit();}
28
29 /* returns the last 'index' postion ocurring in this page */
30 function resultFinalPageIndex() {
31         if(getHitCount() < (getOffset() + getDisplayCount())) 
32                 return getHitCount() - 1;
33         return getOffset() + getDisplayCount() - 1;
34 }
35
36
37
38
39 /* generic search method */
40 function resultCollectSearchIds( type, method, handler ) {
41
42         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
43         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
44
45         var item_type;
46         var item_form;
47         var args = {};
48
49         if( type ) {
50                 var form = parseForm(getForm());
51                 item_type = form.item_type;
52                 item_form = form.item_form;
53
54         } else {
55                 item_type = (getItemType()) ? getItemType().split(/,/) : null;
56                 item_form = (getItemForm()) ? getItemForm().split(/,/) : null;
57         }
58
59         var limit = (resultFetchAllRecords) ? 1000 : getDisplayCount();
60
61         if( getOffset() > 0 ) {
62                 if( getHitCount() > 0 && (getOffset() + getDisplayCount()) > getHitCount() ) 
63                         limit = getHitCount() - getOffset();
64         }
65
66         args.org_unit = getLocation();
67         args.depth    = getDepth();
68         args.limit    = limit;
69         args.offset   = getOffset();
70         args.visibility_limit = 3000;
71     args.default_class = getStype();
72
73         if(sort) args.sort = sort;
74         if(sortdir) args.sort_dir = sortdir;
75         if(item_type) args.item_type    = item_type;
76         if(item_form) args.item_form    = item_form;
77     if(getAvail()) args.available = 1;
78
79
80         if(getAudience()) args.audience  = getAudience().split(/,/);
81         if(getLitForm()) args.lit_form  = getLitForm().split(/,/);
82         if(getLanguage()) args.language = getLanguage().split(/,/);
83         if(getBibLevel()) args.bib_level        = getBibLevel().split(/,/);
84
85         _debug('Search args: ' + js2JSON(args));
86         _debug('Raw query: ' + getTerm());
87
88         var req = new Request(method, args, getTerm(), 1);
89         req.callback(handler);
90         req.send();
91 }
92
93
94
95
96
97 /* set the search result info, number of hits, which results we're 
98         displaying, links to the next/prev pages, etc. */
99 function resultSetHitInfo() { 
100
101
102         /* tell the user where the results are coming from */
103         var baseorg = findOrgUnit(getLocation());
104         var depth = getDepth();
105         var mydepth = findOrgDepth(baseorg);
106         if( findOrgDepth(baseorg) != depth ) {
107                 var tmporg = baseorg;
108                 while( mydepth > depth ) {
109                         mydepth--;
110                         tmporg = findOrgUnit(tmporg.parent_ou());
111                 }
112                 unHideMe($('including_results_for'));
113                 $('including_results_location').appendChild(text(tmporg.name()));
114         }
115
116
117         try{searchTimer.stop()}catch(e){}
118
119         //if( findCurrentPage() == MRESULT ) {
120         if( findCurrentPage() == MRESULT || 
121
122                 (findCurrentPage() == RRESULT &&
123                         (
124                                 getRtype() == RTYPE_TITLE ||
125                                 getRtype() == RTYPE_AUTHOR ||
126                                 getRtype() == RTYPE_SUBJECT ||
127                                 getRtype() == RTYPE_SERIES ||
128                                 getRtype() == RTYPE_KEYWORD 
129                         )
130
131                 ) ) {
132
133                 if(getHitCount() <= lowHitCount && getTerm())
134                         runEvt('result', 'lowHits');
135         }
136
137         if(getHitCount() == 0) {
138                 runEvt('result', 'zeroHits');
139                 return;
140         }
141
142
143         var pages = getHitCount() / getDisplayCount();
144         if(pages % 1) pages = parseInt(pages) + 1;
145
146         
147
148         var cpage = (getOffset()/getDisplayCount()) + 1;
149
150         G.ui.result.current_page.appendChild(text(cpage));
151         G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
152
153         $('current_page2').appendChild(text(cpage));
154         $('num_pages2').appendChild(text(pages + ")")); /* the ) is dumb */
155
156         /* set the offsets */
157         var offsetEnd = getDisplayCount() + getOffset();  
158         if( getDisplayCount() > (getHitCount() - getOffset()))  
159                 offsetEnd = getHitCount();
160
161         G.ui.result.offset_end.appendChild(text(offsetEnd));
162         G.ui.result.offset_start.appendChild(text(getOffset() + 1));
163
164         $('offset_end2').appendChild(text(offsetEnd));
165         $('offset_start2').appendChild(text(getOffset() + 1));
166
167         G.ui.result.result_count.appendChild(text(getHitCount()));
168         unHideMe(G.ui.result.info);
169
170         $('result_count2').appendChild(text(getHitCount()));
171         unHideMe($('result_info_div2'));
172 }
173
174 function resultLowHits() {
175         showCanvas();
176         unHideMe($('result_low_hits'));
177         if(getHitCount() > 0)
178                 unHideMe($('result_low_hits_msg'));
179
180     var words = [];
181     for(var key in resultCompiledSearch.searches) 
182         words.push(resultCompiledSearch.searches[key].term);
183
184         var sreq = new Request(CHECK_SPELL, words.join(' '));
185         sreq.callback(resultSuggestSpelling);
186         sreq.send();
187
188     for(var key in resultCompiledSearch.searches) {
189                 var areq = new Request(FETCH_CROSSREF, key, resultCompiledSearch.searches[key].term);
190                 areq.callback(resultLowHitXRef);
191                 areq.send();
192         }
193
194         if( !(getForm() == null || getForm() == 'all' || getForm() == "") ) {
195                 var a = {};
196                 a[PARAM_FORM] = "all";
197                 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
198                 unHideMe($('low_hits_remove_format'));
199         }
200
201         resultSuggestSearchClass();
202
203         if(getTerm()) resultExpandSearch(); /* advanced search */
204 }
205
206 var lowHitsXRefLink;
207 var lowHitsXRefLinkParent;
208 function resultLowHitXRef(r) {
209         if(!lowHitsXRefLink){
210                 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
211                 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
212         }
213         var res = r.getResultObject();
214         var arr = res.from;
215         arr.concat(res.also);
216         if(arr && arr.length > 0) {
217                 unHideMe($('low_hits_cross_ref'));
218                 var word;
219                 var c = 0;
220                 while( word = arr.shift() ) {
221                         if(c++ > 20) break;
222                         var a = {};
223                         a[PARAM_TERM] = word;
224                         var template = lowHitsXRefLink.cloneNode(true);
225                         template.setAttribute('href',buildOPACLink(a));
226                         template.appendChild(text(word));
227                         lowHitsXRefLinkParent.appendChild(template);
228                         lowHitsXRefLinkParent.appendChild(text(' '));
229                 }
230         }
231 }
232
233 function resultZeroHits() {
234         showCanvas();
235         unHideMe($('result_low_hits'));
236         unHideMe($('result_zero_hits_msg'));
237         //if(getTerm()) resultExpandSearch(); /* advanced search */
238 }
239
240 function resultExpandSearch() {
241         var top = findOrgDepth(globalOrgTree);
242         if(getDepth() == top) return;
243         unHideMe($('low_hits_expand_range'));
244         var par = $('low_hits_expand_link').parentNode;
245         var template = par.removeChild($('low_hits_expand_link'));
246
247         var bottom = getDepth();
248         while( top < bottom ) {
249                 var a = {};
250                 a[PARAM_DEPTH] = top;
251                 var temp = template.cloneNode(true);
252                 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
253                 temp.setAttribute('href',buildOPACLink(a));
254                 par.appendChild(temp);
255                 top++;
256         }
257 }
258
259 function resultSuggestSearchClass() {
260         var stype = getStype();
261         if(stype == STYPE_KEYWORD) return;
262         var a = {}; var ref;
263         unHideMe($('low_hits_search_type'));
264         if(stype != STYPE_TITLE) {
265                 ref = $('low_hits_title_search');
266                 unHideMe(ref);
267                 a[PARAM_STYPE] = STYPE_TITLE;
268                 ref.setAttribute('href',buildOPACLink(a));
269         }
270         if(stype != STYPE_AUTHOR) {
271                 ref = $('low_hits_author_search');
272                 unHideMe(ref);
273                 a[PARAM_STYPE] = STYPE_AUTHOR;
274                 ref.setAttribute('href',buildOPACLink(a));
275         }
276         if(stype != STYPE_SUBJECT) {
277                 ref = $('low_hits_subject_search');
278                 unHideMe(ref);
279                 a[PARAM_STYPE] = STYPE_SUBJECT;
280                 ref.setAttribute('href',buildOPACLink(a));
281         }
282         if(stype != STYPE_KEYWORD) {
283                 ref = $('low_hits_keyword_search');
284                 unHideMe(ref);
285                 a[PARAM_STYPE] = STYPE_KEYWORD;
286                 ref.setAttribute('href',buildOPACLink(a));
287         }
288         if(stype != STYPE_SERIES) {
289                 ref = $('low_hits_series_search');
290                 unHideMe(ref);
291                 a[PARAM_STYPE] = STYPE_SERIES;
292                 ref.setAttribute('href',buildOPACLink(a));
293         }
294 }
295
296 function resultSuggestSpelling(r) {
297         var res = r.getResultObject();
298         var phrase = getTerm();
299         var words = phrase.split(/ /);
300
301         var newterm = "";
302
303         for( var w = 0; w < words.length; w++ ) {
304                 var word = words[w];
305                 var blob = grep(res, function(i){return (i.word == word);});
306                 if( blob ) blob = blob[0];
307                 else continue;
308                 if( blob.word == word ) {
309                         if( blob.suggestions && blob.suggestions[0] ) {
310                                 newterm += " " + blob.suggestions[0];
311                                 unHideMe($('did_you_mean'));
312                         } else {
313                                 newterm += " " + word;
314                         }
315                 }
316         }
317
318         var arg = {};
319         arg[PARAM_TERM] = newterm;
320         $('spell_check_link').setAttribute('href', buildOPACLink(arg));
321         $('spell_check_link').appendChild(text(newterm));
322 }
323
324
325 function resultPaginate() {
326         var o = getOffset();
327
328         if( !(  ((o) + getDisplayCount()) >= getHitCount()) ) {
329
330                 var args = {};
331                 args[PARAM_OFFSET]      = o + getDisplayCount();
332                 args[PARAM_SORT]                = SORT;
333                 args[PARAM_SORT_DIR] = SORT_DIR;
334                 args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
335
336                 G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
337                 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
338
339                 $('next_link2').setAttribute("href", buildOPACLink(args)); 
340                 addCSSClass($('next_link2'), config.css.result.nav_active);
341
342                 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
343
344                 /* when hit count is divisible by display count, we have to adjust */
345                 if( getHitCount() % getDisplayCount() == 0 ) 
346                         args[PARAM_OFFSET] -= getDisplayCount();
347
348         /*
349                 G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
350                 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
351
352                 $('end_link2').setAttribute("href", buildOPACLink(args)); 
353                 addCSSClass($('end_link2'), config.css.result.nav_active);
354         */
355         }
356
357         if( o > 0 ) {
358
359                 var args = {};
360                 args[PARAM_SORT]                = SORT;
361                 args[PARAM_SORT_DIR] = SORT_DIR;
362                 args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
363
364                 args[PARAM_OFFSET] = o - getDisplayCount();
365                 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args)); 
366                 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
367
368                 $('prev_link2').setAttribute( "href", buildOPACLink(args)); 
369                 addCSSClass($('prev_link2'), config.css.result.nav_active);
370
371                 args[PARAM_OFFSET] = 0;
372                 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args)); 
373                 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
374
375                 $('search_home_link2').setAttribute( "href", buildOPACLink(args)); 
376                 addCSSClass($('search_home_link2'), config.css.result.nav_active);
377         }
378
379         if(getDisplayCount() < getHitCount()) {
380                 unHideMe($('start_end_links_span'));
381                 unHideMe($('start_end_links_span2'));
382    }
383
384         showCanvas();
385         try{searchTimer.stop()}catch(e){}
386 }
387
388 function buildunAPISpan (span, type, id) {
389         var cgi = new CGI();
390         var d = new Date();
391
392         addCSSClass(span,'unapi-id');
393
394         span.setAttribute(
395                 'title',
396                 'tag:' + cgi.server_name + ',' +
397                         d.getFullYear() +
398                         ':' + type + '/' + id
399         );
400 }
401
402 function unhideGoogleBooks (data) {
403     for ( var i in data ) {
404         //if (data[i].preview == 'noview') continue;
405
406         var gbspan = $n(document.documentElement, 'googleBooks-' + i);
407         var gba = $n(gbspan, "googleBooks-link");
408
409         gba.setAttribute(
410             'href',
411             data[i].info_url
412         );
413         removeCSSClass( gbspan, 'hide_me' );
414     }
415 }
416
417 /* display the record info in the record display table 'pos' is the 
418                 zero based position the record should have in the display table */
419 function resultDisplayRecord(rec, pos, is_mr) {
420
421         if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
422         recordsHandled++;
423         recordsCache.push(rec);
424
425         var r = table.rows[pos + 1];
426     var currentISBN = cleanISBN(rec.isbn());
427
428     if (googleBooks) {
429             var gbspan = $n(r, "googleBooks");
430         if (currentISBN) {
431             gbspan.setAttribute(
432                 'name',
433                 gbspan.getAttribute('name') + '-' + currentISBN
434             );
435
436             if (isbnList) isbnList += ', ';
437             isbnList += currentISBN;
438         }
439     }
440
441 /*
442         try {
443                 var rank = parseFloat(ranks[pos + getOffset()]);
444                 rank            = parseInt( rank * 100 );
445                 var relspan = $n(r, "relevancy_span");
446                 relspan.appendChild(text(rank));
447                 unHideMe(relspan.parentNode);
448         } catch(e){ }
449 */
450
451         var pic = $n(r, config.names.result.item_jacket);
452         pic.setAttribute("src", buildISBNSrc(currentISBN));
453
454         var title_link = $n(r, config.names.result.item_title);
455         var author_link = $n(r, config.names.result.item_author);
456
457         if( is_mr )  {
458                 var onlyrec = onlyrecord[ getOffset() + pos ];
459                 if(onlyrec) {
460                         buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
461
462                         var args = {};
463                         args.page = RDETAIL;
464                         args[PARAM_OFFSET] = 0;
465                         args[PARAM_RID] = onlyrec;
466                         args[PARAM_MRID] = rec.doc_id();
467                         pic.parentNode.setAttribute("href", buildOPACLink(args));
468                         title_link.setAttribute("href", buildOPACLink(args));
469                         title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
470                         
471                 } else {
472                         buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
473
474                         buildTitleLink(rec, title_link); 
475                         var args = {};
476                         args.page = RRESULT;
477                         args[PARAM_OFFSET] = 0;
478                         args[PARAM_MRID] = rec.doc_id();
479                         pic.parentNode.setAttribute("href", buildOPACLink(args));
480                 }
481
482         } else {
483                 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
484
485                 buildTitleDetailLink(rec, title_link); 
486                 var args = {};
487                 args.page = RDETAIL;
488                 args[PARAM_OFFSET] = 0;
489                 args[PARAM_RID] = rec.doc_id();
490                 pic.parentNode.setAttribute("href", buildOPACLink(args));
491
492                 unHideMe($n(r,'place_hold_span'));
493                 $n(r,'place_hold_link').setAttribute(
494                         'href','javascript:holdsDrawEditor({record:"'+rec.doc_id()+'",type:"T"});');
495         }
496
497         buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
498
499         if(! is_mr ) {
500         
501                 if(!isNull(rec.edition()))      {
502                         unHideMe( $n(r, "result_table_extra_span"));
503                         $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
504                 }
505                 if(!isNull(rec.pubdate())) {
506                         unHideMe( $n(r, "result_table_extra_span"));
507                         unHideMe($n(r, "result_table_pub_span"));
508                         $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
509                 }
510                 if(!isNull(rec.publisher()) ) {
511                         unHideMe( $n(r, "result_table_extra_span"));
512                         unHideMe($n(r, "result_table_pub_span"));
513                         $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
514                 }
515
516                 if(!isNull(rec.physical_description()) ) {
517                         unHideMe( $n(r, "result_table_extra_span"));
518                         var t = " " + rec.physical_description();
519                         //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
520                         $n(r, "result_table_phys_span").appendChild( text(t));
521                 }
522
523         }
524
525         resultBuildFormatIcons( r, rec, is_mr );
526
527         unHideMe(r);
528         
529         runEvt("result", "recordDrawn", rec.doc_id(), title_link);
530
531         /*
532         if(resultPageIsDone())  {
533                 runEvt('result', 'allRecordsReceived', recordsCache);
534         }
535         */
536 }
537
538 function _resultFindRec(id) {
539         for( var i = 0; i != recordsCache.length; i++ ) {
540                 var rec = recordsCache[i];
541                 if( rec && rec.doc_id() == id )
542                         return rec;
543         }
544         return null;
545 }
546
547
548 function resultBuildFormatIcons( row, rec, is_mr ) {
549
550         var ress = rec.types_of_resource();
551
552         for( var i in ress ) {
553
554                 var res = ress[i];
555                 if(!res) continue;
556
557                 var link = $n(row, res + "_link");
558                 link.title = res;
559                 var img = link.getElementsByTagName("img")[0];
560                 removeCSSClass( img, config.css.dim );
561
562                 var f = getForm();
563                 if( f != "all" ) {
564                         if( f == modsFormatToMARC(res) ) 
565                                 addCSSClass( img, "dim2_border");
566                 }
567
568                 var args = {};
569                 args[PARAM_OFFSET] = 0;
570
571                 if(is_mr) {
572                         args.page = RRESULT;
573                         args[PARAM_TFORM] = modsFormatToMARC(res);
574                         args[PARAM_MRID] = rec.doc_id();
575
576                 } else {
577                         args.page = RDETAIL
578                         args[PARAM_RID] = rec.doc_id();
579                 }
580
581                 link.setAttribute("href", buildOPACLink(args));
582
583         }
584 }
585
586 function fetchGoogleBooks () {
587     if (isbnList && googleBooks) {
588         var scriptElement = document.createElement("script");
589         scriptElement.setAttribute("id", "jsonScript");
590         scriptElement.setAttribute("src",
591             "http://books.google.com/books?bibkeys=" + 
592             escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooks");
593         scriptElement.setAttribute("type", "text/javascript");
594         // make the request to Google Book Search
595         document.documentElement.firstChild.appendChild(scriptElement);
596     }
597 }
598
599 function resultPageIsDone(pos) {
600
601         return (recordsHandled == getDisplayCount() 
602                 || recordsHandled + getOffset() == getHitCount());
603 }
604
605 var resultCCHeaderApplied = false;
606
607 /* -------------------------------------------------------------------- */
608 /* dynamically add the copy count rows based on the org type 'countsrow' 
609         is the row into which we will add TD's to hold the copy counts 
610         This code generates copy count cells with an id of
611         'copy_count_cell_<depth>_<pagePosition>'  */
612 function resultAddCopyCounts(rec, pagePosition) {
613
614         var r = table.rows[pagePosition + 1];
615         var countsrow = $n(r, config.names.result.counts_row );
616         var ccell = $n(countsrow, config.names.result.count_cell);
617
618         var nodes = orgNodeTrail(findOrgUnit(getLocation()));
619         var node = nodes[0];
620         var type = findOrgType(node.ou_type());
621         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
622         ccell.title = type.opac_label();
623         //addCSSClass(ccell, config.css.result.cc_cell_even);
624
625         var lastcell = ccell;
626         var lastheadcell = null;
627
628         var cchead = null;
629         var ccheadcell = null;
630         if(!resultCCHeaderApplied) {
631                 ccrow = $('result_thead_row');
632                 ccheadcell =  ccrow.removeChild($n(ccrow, "result_thead_ccell"));
633                 var t = ccheadcell.cloneNode(true);
634                 lastheadcell = t;
635                 t.appendChild(text(type.opac_label()));
636                 ccrow.appendChild(t);
637                 resultCCHeaderApplied = true;
638         }
639
640         if(nodes[1]) {
641
642                 var x = 1;
643                 var d = findOrgDepth(nodes[1]);
644                 var d2 = findOrgDepth(nodes[nodes.length -1]);
645
646                 for( var i = d; i <= d2 ; i++ ) {
647         
648                         ccell = ccell.cloneNode(true);
649
650                         //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
651                         //else addCSSClass(ccell, "copy_count_cell_even");
652
653                         var node = nodes[x++];
654                         var type = findOrgType(node.ou_type());
655         
656                         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
657                         ccell.title = type.opac_label();
658                         countsrow.insertBefore(ccell, lastcell);
659                         lastcell = ccell;
660
661                         if(ccheadcell) {
662                                 var t = ccheadcell.cloneNode(true);
663                                 t.appendChild(text(type.opac_label()));
664                                 ccrow.insertBefore(t, lastheadcell);
665                                 lastheadcell = t;
666                         }
667                 }
668         }
669
670         unHideMe($("search_info_table"));
671 }
672
673 /* collect copy counts for a record using method 'methodName' */
674 function resultCollectCopyCounts(rec, pagePosition, methodName) {
675         if(rec == null || rec.doc_id() == null) return;
676         var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
677         req.request.userdata = [ rec, pagePosition ];
678         req.callback(resultHandleCopyCounts);
679         req.send();
680 }
681
682 function resultHandleCopyCounts(r) {
683         runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject()); 
684 }
685
686
687 /* display the collected copy counts */
688 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
689         if(copy_counts == null || rec == null) return;
690         var i = 0;
691         while(copy_counts[i] != null) {
692                 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
693                 var cts = copy_counts[i];
694                 cell.appendChild(text(cts.available + " / " + cts.count));
695
696                 if(isXUL()) {
697                         /* here we style opac-invisible records for xul */
698
699                         if( cts.depth == 0 ) {
700                                 if(!cts.transcendant && !cts.unshadow) {
701                                         _debug("found an opac-shadowed record: " + rec.doc_id());
702                                         var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode; 
703                                         if( cts.count == 0 ) 
704                                                 addCSSClass( row, 'no_copies' );
705                                         else 
706                                                 addCSSClass( row, 'shadowed' );
707                                 }
708                         }
709                 }
710                 i++;
711         }
712 }
713
714