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