]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/acjs.tt2
lp1481844 Change Available Copies Display
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / acjs.tt2
1
2 <script type="text/javascript">
3
4     /* Checks to see if a given type of added content has data to show.
5      * The first arg to callback() is boolean indicating the presence of data */
6     function acIsAvailable(bre_id, type, callback) {
7         var url = '/opac/extras/ac/' + type + '/html/r/' + bre_id;
8         dojo.xhr('HEAD', {
9             url : url,
10             failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
11             error : function(err) { callback(false, bre_id, type); },
12             load : function(result) { callback(true, bre_id, type); }
13         });
14     }
15
16     [%-
17         FOR type IN ctx.added_content.keys;
18             IF ctx.added_content.$type.status == '3' # status unknown %]
19
20                 dojo.addOnLoad(function() {
21                     var bre_id = '[% ctx.bre_id %]';
22                     var type = '[% type %]';
23
24                     acIsAvailable(bre_id, type, function(avail, bre_id, type) {
25                         if (avail) {
26
27                             [% IF CGI.param('expand') == 'addedcontent' %]
28
29                                 // if the content is available, un-hide the tab
30                                 dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
31
32                             [% ELSE %]
33                                 // if no default type is selected on the main tab link
34                                 // set one here, since we have available content
35
36                                 var link = dojo.query('[name=addedcontent]')[0];
37                                 var href = link.getAttribute('href');
38                                 if (!href.match('[\&;]ac=')) {
39                                     href = href.replace('#addedcontent', ';ac=' + type + '#addedcontent');
40                                     dojo.attr(link, 'href', href);
41                                     dojo.attr(dojo.query('[name=addedcontent_lbl]')[0], 'href', href);
42                                 }
43
44                             [% END %]
45                         }
46                     });
47                 });
48             [% END; # IF status unknown
49         END; # FOR type
50
51         ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc;
52         IF ident;
53     -%]
54
55 [%- IF ENV.OILS_NOVELIST_URL -%]
56             /* Load novelist content */
57             novSelect.loadContentForQuery(
58                 {
59                     ClientIdentifier : '[% ident %]',
60                     ISBN : '[% ident %]',
61                     version : '2.1'
62                 },
63                 '[% ENV.OILS_NOVELIST_PROFILE %]',
64                 '[% ENV.OILS_NOVELIST_PASSWORD %]',
65                 function(d){
66                     // note if d.length == 0, there is no content to display
67                     // hide the Loading... text
68                     dojo.byId('novelist-loading').innerHTML = '';
69                 }
70             );
71 [%- END; # Novelist -%]
72
73         [% END; # IF ident
74     %]
75 </script>