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