f4154f93ef82d4c542a7244ee47e620a94081e2c
[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 querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) | html %]";
68 var results_per_page = [% OPACnumSearchResults | html %];
69
70 function fetch_availability( prod, $tr ) {
71     var $availability_summary = $( '<span class="results_summary availability"></span>' );
72     $tr.find( '.mediatype' ).after( $availability_summary );
73     $availability_summary.html( '<span class="label">' + _("Availability:") + ' </span> ' + _("Loading...") );
74
75     KOHA.OverDrive.Get(
76         prod.links.availability.href,
77         {},
78         function ( data ) {
79             if ( data.error ) return;
80
81             $availability_summary.html( '<span class="label">' + _("Availability:") + ' </span> ' + '<span class="available"><b>' + _("Items available:") + ' </b>' +  data.copiesAvailable + " " + _("out of") + ' ' + data.copiesOwned + '</span>' );
82
83             if ( data.numberOfHolds ) {
84                 $availability_summary.find( '.available' ).append( ', ' + _("waiting holds:") + ' <strong>' + data.numberOfHolds + '</strong>' );
85             }
86
87             $tr.find( '.info' ).each(function() {
88                 KOHA.OverDriveCirculation.add_actions(this, data.id, data.copiesAvailable);
89             });
90         }
91     );
92 }
93
94 function search( offset ) {
95     $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
96
97     KOHA.OverDrive.Search( "[% OverDriveLibraryID | html %]", querystring, results_per_page, offset, function( data ) {
98         if ( data.error ) {
99             $( '#overdrive-status' ).html( '<strong class="unavailable">' + _("Error searching OverDrive collection.") + '</strong>' );
100             return;
101         }
102
103         if ( !data.totalItems ) {
104             $( '#overdrive-status' ).html( '<strong>' + _("No results found in the library's OverDrive collection.") + '</strong>' );
105             return;
106         }
107
108         $( '#overdrive-results-list tbody' ).empty();
109
110         $( '#overdrive-status' ).html( '<strong>' + _("Found") + ' ' + data.totalItems + ' ' + _("results in the library's OverDrive collection.") + '</strong>' );
111
112         for ( var i = 0; data.products[i]; i++ ) {
113             var prod = data.products[i];
114             var results = [];
115
116             results.push( '<tr>' );
117
118             results.push( '<td class="info"><a class="title" href="', prod.contentDetails[0].href, '">' );
119             results.push( prod.title );
120             if ( prod.subtitle ) results.push( ', ', prod.subtitle );
121             results.push( '</a>' );
122             results.push( '<p>' + _("by") + ' ', prod.primaryCreator.name, '</p>' );
123             results.push( '<span class="results_summary mediatype"><span class="label">' + _("Type:") + ' </span>', prod.mediaType, '</span>' );
124
125             if ( prod.starRating ) {
126                 results.push( '<div class="results_summary ratings">' );
127                 for ( var rating = 1; rating <= 5; rating++ ) {
128                     results.push( '<input class="star" type="radio" name="rating-' + i + '" value="' + rating + '"' + ( rating == Math.round( prod.starRating ) ? ' checked="checked"' : '' ) + ' disabled="disabled" />' );
129                 }
130                 results.push( '</div>' );
131             }
132
133             results.push( '</td>' );
134
135             results.push( '<td>' );
136             if ( prod.images.thumbnail ) {
137                 results.push( '<a href="', prod.contentDetails[0].href, '">' );
138                 results.push( '<img class="thumbnail" src="', prod.images.thumbnail.href, '" />' );
139                 results.push( '</a>' );
140             }
141             results.push( '</td>' );
142
143             results.push( '</tr>' );
144             var $tr = $( results.join( '' ));
145             $( '#overdrive-results-list tbody' ).append( $tr );
146
147             fetch_availability( prod, $tr );
148         }
149
150         $( '#overdrive-results-list tr:odd' ).addClass( 'highlight' );
151
152         var pages = [];
153         var cur_page = offset / results_per_page;
154         var max_page = Math.floor( data.totalItems / results_per_page );
155
156         if ( cur_page != 0 ) {
157             pages.push( '<li><a class="od-nav" href="#" data-offset="' + (offset - results_per_page) + '">&laquo; ' + _("Previous") + '</a></li>' );
158         }
159
160         for ( var page = Math.max( 0, cur_page - 9 ); page <= Math.min( max_page, cur_page + 9 ); page++ ) {
161             if ( page == cur_page ) {
162                 pages.push( ' <li class="active"><a href="#">' + ( page + 1 ) + '</a></li>' );
163             } else {
164                 pages.push( ' <li><a class="od-nav" href="#" data-offset="' + ( page * results_per_page ) + '">' + ( page + 1 ) + '</a></li>' );
165             }
166         }
167
168         if ( cur_page < max_page ) {
169             pages.push( ' <li><a class="od-nav" href="#" data-offset="' + (offset + results_per_page) + '">' + _("Next") + ' &raquo;</a></li>' );
170         }
171
172         if ( pages.length > 1 ) $( '#top-pages, #bottom-pages' ).find( '.pagination' ).html( '<ul>' + pages.join( '' ) + '</ul>');
173
174         $( '#overdrive-results-list input.star' ).rating();
175     } );
176 }
177
178 $( document ).ready( function() {
179     $( '#breadcrumbs p' )
180         .append( ' ' )
181         .append( '<span id="overdrive-status"></span>' );
182
183     $( document ).on( 'click', 'a.od-nav', function() {
184         search( $( this ).data( 'offset' ) );
185         return false;
186     });
187
188     [% IF ( overdrive_error ) %]
189     KOHA.OverDriveCirculation.display_error("#breadcrumbs", "[% overdrive_error.dquote | html %]");
190     [% END %]
191     [% IF ( loggedinusername and OverDriveCirculation ) %]
192     KOHA.OverDriveCirculation.with_account_details("#breadcrumbs", function() {
193         search( 0 );
194     });
195     [% ELSE %]
196         search( 0 );
197     [% END %]
198 } );
199 </script>
200 [% END %]