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