]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/result_common.js
removing relevance span population from metabib search
[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     var words = [];
180     for(var key in resultCompiledSearch.searches) 
181         words.push(resultCompiledSearch.searches[key].term);
182
183         var sreq = new Request(CHECK_SPELL, words.join(' '));
184         sreq.callback(resultSuggestSpelling);
185         sreq.send();
186
187     for(var key in resultCompiledSearch.searches) {
188                 var areq = new Request(FETCH_CROSSREF, key, resultCompiledSearch.searches[key].term);
189                 areq.callback(resultLowHitXRef);
190                 areq.send();
191         }
192
193         if( !(getForm() == null || getForm() == 'all' || getForm() == "") ) {
194                 var a = {};
195                 a[PARAM_FORM] = "all";
196                 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
197                 unHideMe($('low_hits_remove_format'));
198         }
199
200         resultSuggestSearchClass();
201
202         if(getTerm()) resultExpandSearch(); /* advanced search */
203 }
204
205 var lowHitsXRefLink;
206 var lowHitsXRefLinkParent;
207 function resultLowHitXRef(r) {
208         if(!lowHitsXRefLink){
209                 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
210                 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
211         }
212         var res = r.getResultObject();
213         var arr = res.from;
214         arr.concat(res.also);
215         if(arr && arr.length > 0) {
216                 unHideMe($('low_hits_cross_ref'));
217                 var word;
218                 var c = 0;
219                 while( word = arr.shift() ) {
220                         if(c++ > 20) break;
221                         var a = {};
222                         a[PARAM_TERM] = word;
223                         var template = lowHitsXRefLink.cloneNode(true);
224                         template.setAttribute('href',buildOPACLink(a));
225                         template.appendChild(text(word));
226                         lowHitsXRefLinkParent.appendChild(template);
227                         lowHitsXRefLinkParent.appendChild(text(' '));
228                 }
229         }
230 }
231
232 function resultZeroHits() {
233         showCanvas();
234         unHideMe($('result_low_hits'));
235         unHideMe($('result_zero_hits_msg'));
236         //if(getTerm()) resultExpandSearch(); /* advanced search */
237 }
238
239 function resultExpandSearch() {
240         var top = findOrgDepth(globalOrgTree);
241         if(getDepth() == top) return;
242         unHideMe($('low_hits_expand_range'));
243         var par = $('low_hits_expand_link').parentNode;
244         var template = par.removeChild($('low_hits_expand_link'));
245
246         var bottom = getDepth();
247         while( top < bottom ) {
248                 var a = {};
249                 a[PARAM_DEPTH] = top;
250                 var temp = template.cloneNode(true);
251                 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
252                 temp.setAttribute('href',buildOPACLink(a));
253                 par.appendChild(temp);
254                 top++;
255         }
256 }
257
258 function resultSuggestSearchClass() {
259         var stype = getStype();
260         if(stype == STYPE_KEYWORD) return;
261         var a = {}; var ref;
262         unHideMe($('low_hits_search_type'));
263         if(stype != STYPE_TITLE) {
264                 ref = $('low_hits_title_search');
265                 unHideMe(ref);
266                 a[PARAM_STYPE] = STYPE_TITLE;
267                 ref.setAttribute('href',buildOPACLink(a));
268         }
269         if(stype != STYPE_AUTHOR) {
270                 ref = $('low_hits_author_search');
271                 unHideMe(ref);
272                 a[PARAM_STYPE] = STYPE_AUTHOR;
273                 ref.setAttribute('href',buildOPACLink(a));
274         }
275         if(stype != STYPE_SUBJECT) {
276                 ref = $('low_hits_subject_search');
277                 unHideMe(ref);
278                 a[PARAM_STYPE] = STYPE_SUBJECT;
279                 ref.setAttribute('href',buildOPACLink(a));
280         }
281         if(stype != STYPE_KEYWORD) {
282                 ref = $('low_hits_keyword_search');
283                 unHideMe(ref);
284                 a[PARAM_STYPE] = STYPE_KEYWORD;
285                 ref.setAttribute('href',buildOPACLink(a));
286         }
287         if(stype != STYPE_SERIES) {
288                 ref = $('low_hits_series_search');
289                 unHideMe(ref);
290                 a[PARAM_STYPE] = STYPE_SERIES;
291                 ref.setAttribute('href',buildOPACLink(a));
292         }
293 }
294
295 function resultSuggestSpelling(r) {
296         var res = r.getResultObject();
297         var phrase = getTerm();
298         var words = phrase.split(/ /);
299
300         var newterm = "";
301
302         for( var w = 0; w < words.length; w++ ) {
303                 var word = words[w];
304                 var blob = grep(res, function(i){return (i.word == word);});
305                 if( blob ) blob = blob[0];
306                 else continue;
307                 if( blob.word == word ) {
308                         if( blob.suggestions && blob.suggestions[0] ) {
309                                 newterm += " " + blob.suggestions[0];
310                                 unHideMe($('did_you_mean'));
311                         } else {
312                                 newterm += " " + word;
313                         }
314                 }
315         }
316
317         var arg = {};
318         arg[PARAM_TERM] = newterm;
319         $('spell_check_link').setAttribute('href', buildOPACLink(arg));
320         $('spell_check_link').appendChild(text(newterm));
321 }
322
323
324 function resultPaginate() {
325         var o = getOffset();
326
327         if( !(  ((o) + getDisplayCount()) >= getHitCount()) ) {
328
329                 var args = {};
330                 args[PARAM_OFFSET]      = o + getDisplayCount();
331                 args[PARAM_SORT]                = SORT;
332                 args[PARAM_SORT_DIR] = SORT_DIR;
333                 args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
334
335                 G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
336                 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
337
338                 $('next_link2').setAttribute("href", buildOPACLink(args)); 
339                 addCSSClass($('next_link2'), config.css.result.nav_active);
340
341                 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
342
343                 /* when hit count is divisible by display count, we have to adjust */
344                 if( getHitCount() % getDisplayCount() == 0 ) 
345                         args[PARAM_OFFSET] -= getDisplayCount();
346
347         /*
348                 G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
349                 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
350
351                 $('end_link2').setAttribute("href", buildOPACLink(args)); 
352                 addCSSClass($('end_link2'), config.css.result.nav_active);
353         */
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 /*
441         try {
442                 var rank = parseFloat(ranks[pos + getOffset()]);
443                 rank            = parseInt( rank * 100 );
444                 var relspan = $n(r, "relevancy_span");
445                 relspan.appendChild(text(rank));
446                 unHideMe(relspan.parentNode);
447         } catch(e){ }
448 */
449
450         var pic = $n(r, config.names.result.item_jacket);
451         pic.setAttribute("src", buildISBNSrc(currentISBN));
452
453         var title_link = $n(r, config.names.result.item_title);
454         var author_link = $n(r, config.names.result.item_author);
455
456         if( is_mr )  {
457                 var onlyrec = onlyrecord[ getOffset() + pos ];
458                 if(onlyrec) {
459                         buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
460
461                         var args = {};
462                         args.page = RDETAIL;
463                         args[PARAM_OFFSET] = 0;
464                         args[PARAM_RID] = onlyrec;
465                         args[PARAM_MRID] = rec.doc_id();
466                         pic.parentNode.setAttribute("href", buildOPACLink(args));
467                         title_link.setAttribute("href", buildOPACLink(args));
468                         title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
469                         
470                 } else {
471                         buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
472
473                         buildTitleLink(rec, title_link); 
474                         var args = {};
475                         args.page = RRESULT;
476                         args[PARAM_OFFSET] = 0;
477                         args[PARAM_MRID] = rec.doc_id();
478                         pic.parentNode.setAttribute("href", buildOPACLink(args));
479                 }
480
481         } else {
482                 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
483
484                 buildTitleDetailLink(rec, title_link); 
485                 var args = {};
486                 args.page = RDETAIL;
487                 args[PARAM_OFFSET] = 0;
488                 args[PARAM_RID] = rec.doc_id();
489                 pic.parentNode.setAttribute("href", buildOPACLink(args));
490
491                 unHideMe($n(r,'place_hold_span'));
492                 $n(r,'place_hold_link').setAttribute(
493                         'href','javascript:holdsDrawEditor({record:"'+rec.doc_id()+'",type:"T"});');
494         }
495
496         buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
497
498         if(! is_mr ) {
499         
500                 if(!isNull(rec.edition()))      {
501                         unHideMe( $n(r, "result_table_extra_span"));
502                         $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
503                 }
504                 if(!isNull(rec.pubdate())) {
505                         unHideMe( $n(r, "result_table_extra_span"));
506                         unHideMe($n(r, "result_table_pub_span"));
507                         $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
508                 }
509                 if(!isNull(rec.publisher()) ) {
510                         unHideMe( $n(r, "result_table_extra_span"));
511                         unHideMe($n(r, "result_table_pub_span"));
512                         $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
513                 }
514
515                 if(!isNull(rec.physical_description()) ) {
516                         unHideMe( $n(r, "result_table_extra_span"));
517                         var t = " " + rec.physical_description();
518                         //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
519                         $n(r, "result_table_phys_span").appendChild( text(t));
520                 }
521
522         }
523
524         resultBuildFormatIcons( r, rec, is_mr );
525
526         unHideMe(r);
527         
528         runEvt("result", "recordDrawn", rec.doc_id(), title_link);
529
530         /*
531         if(resultPageIsDone())  {
532                 runEvt('result', 'allRecordsReceived', recordsCache);
533         }
534         */
535 }
536
537 function _resultFindRec(id) {
538         for( var i = 0; i != recordsCache.length; i++ ) {
539                 var rec = recordsCache[i];
540                 if( rec && rec.doc_id() == id )
541                         return rec;
542         }
543         return null;
544 }
545
546
547 function resultBuildFormatIcons( row, rec, is_mr ) {
548
549         var ress = rec.types_of_resource();
550
551         for( var i in ress ) {
552
553                 var res = ress[i];
554                 if(!res) continue;
555
556                 var link = $n(row, res + "_link");
557                 link.title = res;
558                 var img = link.getElementsByTagName("img")[0];
559                 removeCSSClass( img, config.css.dim );
560
561                 var f = getForm();
562                 if( f != "all" ) {
563                         if( f == modsFormatToMARC(res) ) 
564                                 addCSSClass( img, "dim2_border");
565                 }
566
567                 var args = {};
568                 args[PARAM_OFFSET] = 0;
569
570                 if(is_mr) {
571                         args.page = RRESULT;
572                         args[PARAM_TFORM] = modsFormatToMARC(res);
573                         args[PARAM_MRID] = rec.doc_id();
574
575                 } else {
576                         args.page = RDETAIL
577                         args[PARAM_RID] = rec.doc_id();
578                 }
579
580                 link.setAttribute("href", buildOPACLink(args));
581
582         }
583 }
584
585 function fetchGoogleBooks () {
586     if (isbnList && googleBooks) {
587         var scriptElement = document.createElement("script");
588         scriptElement.setAttribute("id", "jsonScript");
589         scriptElement.setAttribute("src",
590             "http://books.google.com/books?bibkeys=" + 
591             escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooks");
592         scriptElement.setAttribute("type", "text/javascript");
593         // make the request to Google Book Search
594         document.documentElement.firstChild.appendChild(scriptElement);
595     }
596 }
597
598 function resultPageIsDone(pos) {
599
600         return (recordsHandled == getDisplayCount() 
601                 || recordsHandled + getOffset() == getHitCount());
602 }
603
604 var resultCCHeaderApplied = false;
605
606 /* -------------------------------------------------------------------- */
607 /* dynamically add the copy count rows based on the org type 'countsrow' 
608         is the row into which we will add TD's to hold the copy counts 
609         This code generates copy count cells with an id of
610         'copy_count_cell_<depth>_<pagePosition>'  */
611 function resultAddCopyCounts(rec, pagePosition) {
612
613         var r = table.rows[pagePosition + 1];
614         var countsrow = $n(r, config.names.result.counts_row );
615         var ccell = $n(countsrow, config.names.result.count_cell);
616
617         var nodes = orgNodeTrail(findOrgUnit(getLocation()));
618         var node = nodes[0];
619         var type = findOrgType(node.ou_type());
620         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
621         ccell.title = type.opac_label();
622         //addCSSClass(ccell, config.css.result.cc_cell_even);
623
624         var lastcell = ccell;
625         var lastheadcell = null;
626
627         var cchead = null;
628         var ccheadcell = null;
629         if(!resultCCHeaderApplied) {
630                 ccrow = $('result_thead_row');
631                 ccheadcell =  ccrow.removeChild($n(ccrow, "result_thead_ccell"));
632                 var t = ccheadcell.cloneNode(true);
633                 lastheadcell = t;
634                 t.appendChild(text(type.opac_label()));
635                 ccrow.appendChild(t);
636                 resultCCHeaderApplied = true;
637         }
638
639         if(nodes[1]) {
640
641                 var x = 1;
642                 var d = findOrgDepth(nodes[1]);
643                 var d2 = findOrgDepth(nodes[nodes.length -1]);
644
645                 for( var i = d; i <= d2 ; i++ ) {
646         
647                         ccell = ccell.cloneNode(true);
648
649                         //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
650                         //else addCSSClass(ccell, "copy_count_cell_even");
651
652                         var node = nodes[x++];
653                         var type = findOrgType(node.ou_type());
654         
655                         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
656                         ccell.title = type.opac_label();
657                         countsrow.insertBefore(ccell, lastcell);
658                         lastcell = ccell;
659
660                         if(ccheadcell) {
661                                 var t = ccheadcell.cloneNode(true);
662                                 t.appendChild(text(type.opac_label()));
663                                 ccrow.insertBefore(t, lastheadcell);
664                                 lastheadcell = t;
665                         }
666                 }
667         }
668
669         unHideMe($("search_info_table"));
670 }
671
672 /* collect copy counts for a record using method 'methodName' */
673 function resultCollectCopyCounts(rec, pagePosition, methodName) {
674         if(rec == null || rec.doc_id() == null) return;
675         var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
676         req.request.userdata = [ rec, pagePosition ];
677         req.callback(resultHandleCopyCounts);
678         req.send();
679 }
680
681 function resultHandleCopyCounts(r) {
682         runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject()); 
683 }
684
685
686 /* display the collected copy counts */
687 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
688         if(copy_counts == null || rec == null) return;
689         var i = 0;
690         while(copy_counts[i] != null) {
691                 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
692                 var cts = copy_counts[i];
693                 cell.appendChild(text(cts.available + " / " + cts.count));
694
695                 if(isXUL()) {
696                         /* here we style opac-invisible records for xul */
697
698                         if( cts.depth == 0 ) {
699                                 if(!cts.transcendant && !cts.unshadow) {
700                                         _debug("found an opac-shadowed record: " + rec.doc_id());
701                                         var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode; 
702                                         if( cts.count == 0 ) 
703                                                 addCSSClass( row, 'no_copies' );
704                                         else 
705                                                 addCSSClass( row, 'shadowed' );
706                                 }
707                         }
708                 }
709                 i++;
710         }
711 }
712
713