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