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