Bug 20053: Drop type attribute "text/javascript" in OPAC templates
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / modules / opac-overdrive-search.tt
1 [% USE Asset %]
2 [% USE Koha %]
3 [% INCLUDE 'doc-head-open.inc' %]
4 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; OverDrive search for '[% q | html %]'</title>
5 [% INCLUDE 'doc-head-close.inc' %]
6 [% BLOCK cssinclude %]
7 [% Asset.css("css/jquery.rating.css") %]
8 <style>
9 .actions a.addtocart {
10     display: inline;
11 }
12 </style>
13 [% END %]
14 </head>
15 [% INCLUDE 'bodytag.inc' bodyid='overdrive-results-page' bodyclass='scrollto' %]
16 [% INCLUDE 'masthead.inc' %]
17
18     <div class="main">
19         <ul class="breadcrumb">
20             <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
21             <li><a href="#">OverDrive search for '[% q | html %]'</a></li>
22         </ul>
23
24         <div class="container-fluid">
25             <div class="row-fluid">
26                 <div class="span2">
27                     [% IF ( OpacNav || OpacNavBottom ) %]
28                         [% INCLUDE 'navigation.inc' %]
29                     [% END %]
30                 </div>
31                 <div class="span10">
32                     <div id="overdrive-results-content" class="maincontent searchresults">
33                         <h1>OverDrive search for '[% q | html %]'</h1>
34                             <div id="breadcrumbs">
35                                 <p></p>
36                             </div>
37
38                             <div id="top-pages">
39                                 <div class="pagination pagination-small">
40                                 </div>
41                             </div>
42
43                             <table id="overdrive-results-list" class="table table-striped">
44                                 <tbody>
45                                 </tbody>
46                             </table>
47
48                             <div id="bottom-pages">
49                                 <div class="pagination pagination-small">
50                                 </div>
51                             </div>
52
53                     </div> <!-- / #overdrive-results-content -->
54                 </div> <!-- / .span10 -->
55             </div> <!-- / .row-fluid -->
56         </div> <!-- / .container-fluid -->
57     </div> <!-- / .main -->
58
59 [% INCLUDE 'overdrive-checkout.inc' %]
60
61 [% INCLUDE 'opac-bottom.inc' %]
62 [% BLOCK jsinclude %]
63 [% Asset.js("js/overdrive.js") %]
64 [% Asset.js("lib/jquery/plugins/jquery.rating.js") %]
65 <script>
66 var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]";
67 var results_per_page = [% OPACnumSearchResults %];
68
69 function fetch_availability( prod, $tr ) {
70     var $availability_summary = $( '<span class="results_summary availability"></span>' );
71     $tr.find( '.mediatype' ).after( $availability_summary );
72     $availability_summary.html( '<span class="label">' + _("Availability:") + ' </span> ' + _("Loading...") );
73
74     KOHA.OverDrive.Get(
75         prod.links.availability.href,
76         {},
77         function ( data ) {
78             if ( data.error ) return;
79
80             $availability_summary.html( '<span class="label">' + _("Availability:") + ' </span> ' + '<span class="available"><b>' + _("Items available:") + ' </b>' +  data.copiesAvailable + " " + _("out of") + ' ' + data.copiesOwned + '</span>' );
81
82             if ( data.numberOfHolds ) {
83                 $availability_summary.find( '.available' ).append( ', ' + _("waiting holds:") + ' <strong>' + data.numberOfHolds + '</strong>' );
84             }
85
86             $tr.find( '.info' ).each(function() {
87                 KOHA.OverDriveCirculation.add_actions(this, data.id, data.copiesAvailable);
88             });
89         }
90     );
91 }
92
93 function search( offset ) {
94     $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
95
96     KOHA.OverDrive.Search( "[% OverDriveLibraryID %]", querystring, results_per_page, offset, function( data ) {
97         if ( data.error ) {
98             $( '#overdrive-status' ).html( '<strong class="unavailable">' + _("Error searching OverDrive collection.") + '</strong>' );
99             return;
100         }
101
102         if ( !data.totalItems ) {
103             $( '#overdrive-status' ).html( '<strong>' + _("No results found in the library's OverDrive collection.") + '</strong>' );
104             return;
105         }
106
107         $( '#overdrive-results-list tbody' ).empty();
108
109         $( '#overdrive-status' ).html( '<strong>' + _("Found") + ' ' + data.totalItems + ' ' + _("results in the library's OverDrive collection.") + '</strong>' );
110
111         for ( var i = 0; data.products[i]; i++ ) {
112             var prod = data.products[i];
113             var results = [];
114
115             results.push( '<tr>' );
116
117             results.push( '<td class="info"><a class="title" href="', prod.contentDetails[0].href, '">' );
118             results.push( prod.title );
119             if ( prod.subtitle ) results.push( ', ', prod.subtitle );
120             results.push( '</a>' );
121             results.push( '<p>' + _("by") + ' ', prod.primaryCreator.name, '</p>' );
122             results.push( '<span class="results_summary mediatype"><span class="label">' + _("Type:") + ' </span>', prod.mediaType, '</span>' );
123
124             if ( prod.starRating ) {
125                 results.push( '<div class="results_summary ratings">' );
126                 for ( var rating = 1; rating <= 5; rating++ ) {
127                     results.push( '<input class="star" type="radio" name="rating-' + i + '" value="' + rating + '"' + ( rating == Math.round( prod.starRating ) ? ' checked="checked"' : '' ) + ' disabled="disabled" />' );
128                 }
129                 results.push( '</div>' );
130             }
131
132             results.push( '</td>' );
133
134             results.push( '<td>' );
135             if ( prod.images.thumbnail ) {
136                 results.push( '<a href="', prod.contentDetails[0].href, '">' );
137                 results.push( '<img class="thumbnail" src="', prod.images.thumbnail.href, '" />' );
138                 results.push( '</a>' );
139             }
140             results.push( '</td>' );
141
142             results.push( '</tr>' );
143             var $tr = $( results.join( '' ));
144             $( '#overdrive-results-list tbody' ).append( $tr );
145
146             fetch_availability( prod, $tr );
147         }
148
149         $( '#overdrive-results-list tr:odd' ).addClass( 'highlight' );
150
151         var pages = [];
152         var cur_page = offset / results_per_page;
153         var max_page = Math.floor( data.totalItems / results_per_page );
154
155         if ( cur_page != 0 ) {
156             pages.push( '<li><a class="od-nav" href="#" data-offset="' + (offset - results_per_page) + '">&laquo; ' + _("Previous") + '</a></li>' );
157         }
158
159         for ( var page = Math.max( 0, cur_page - 9 ); page <= Math.min( max_page, cur_page + 9 ); page++ ) {
160             if ( page == cur_page ) {
161                 pages.push( ' <li class="active"><a href="#">' + ( page + 1 ) + '</a></li>' );
162             } else {
163                 pages.push( ' <li><a class="od-nav" href="#" data-offset="' + ( page * results_per_page ) + '">' + ( page + 1 ) + '</a></li>' );
164             }
165         }
166
167         if ( cur_page < max_page ) {
168             pages.push( ' <li><a class="od-nav" href="#" data-offset="' + (offset + results_per_page) + '">' + _("Next") + ' &raquo;</a></li>' );
169         }
170
171         if ( pages.length > 1 ) $( '#top-pages, #bottom-pages' ).find( '.pagination' ).html( '<ul>' + pages.join( '' ) + '</ul>');
172
173         $( '#overdrive-results-list input.star' ).rating();
174     } );
175 }
176
177 $( document ).ready( function() {
178     $( '#breadcrumbs p' )
179         .append( ' ' )
180         .append( '<span id="overdrive-status"></span>' );
181
182     $( document ).on( 'click', 'a.od-nav', function() {
183         search( $( this ).data( 'offset' ) );
184         return false;
185     });
186
187     [% IF ( overdrive_error ) %]
188     KOHA.OverDriveCirculation.display_error("#breadcrumbs", "[% overdrive_error.dquote %]");
189     [% END %]
190     [% IF ( loggedinusername and OverDriveCirculation ) %]
191     KOHA.OverDriveCirculation.with_account_details("#breadcrumbs", function() {
192         search( 0 );
193     });
194     [% ELSE %]
195         search( 0 );
196     [% END %]
197 } );
198 </script>
199 [% END %]