Bug 21082: Update OverDrive authentication method
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / modules / opac-overdrive-search.tt
index c214297..1c2548b 100644 (file)
@@ -1,9 +1,11 @@
+[% USE raw %]
+[% USE Asset %]
 [% USE Koha %]
 [% INCLUDE 'doc-head-open.inc' %]
-[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › OverDrive search for '[% q | html %]'
+<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog &rsaquo; OverDrive search for '[% q | html %]'</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% BLOCK cssinclude %]
-<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/jquery.rating.css" />
+[% Asset.css("css/jquery.rating.css") | $raw %]
 <style>
 .actions a.addtocart {
     display: inline;
         </div> <!-- / .container-fluid -->
     </div> <!-- / .main -->
 
+[% INCLUDE 'overdrive-checkout.inc' %]
+
 [% INCLUDE 'opac-bottom.inc' %]
 [% BLOCK jsinclude %]
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/overdrive.js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.rating.js"></script>
-<script type="text/javascript">
-var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]";
-var results_per_page = [% OPACnumSearchResults %];
+[% Asset.js("js/overdrive.js") | $raw %]
+[% Asset.js("lib/jquery/plugins/jquery.rating.js") | $raw %]
+<script>
+var OD_password_required = [% IF Koha.Preference('OverDrivePasswordRequired') %]1[% ELSE %]0[% END %];
+var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) | html %]";
+var results_per_page = [% OPACnumSearchResults | html %];
 
 function fetch_availability( prod, $tr ) {
     var $availability_summary = $( '<span class="results_summary availability"></span>' );
@@ -80,15 +85,17 @@ function fetch_availability( prod, $tr ) {
                 $availability_summary.find( '.available' ).append( ', ' + _("waiting holds:") + ' <strong>' + data.numberOfHolds + '</strong>' );
             }
 
-            $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>' );
+            $tr.find( '.info' ).each(function() {
+                KOHA.OverDriveCirculation.add_actions(this, data.id, data.copiesAvailable);
+            });
         }
     );
 }
 
 function search( offset ) {
-    $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
+    $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
 
-    KOHA.OverDrive.Search( "[% OverDriveLibraryID %]", querystring, results_per_page, offset, function( data ) {
+    KOHA.OverDrive.Search( "[% OverDriveLibraryID | html %]", querystring, results_per_page, offset, function( data ) {
         if ( data.error ) {
             $( '#overdrive-status' ).html( '<strong class="unavailable">' + _("Error searching OverDrive collection.") + '</strong>' );
             return;
@@ -179,7 +186,16 @@ $( document ).ready( function() {
         return false;
     });
 
-    search( 0 );
+    [% IF ( overdrive_error ) %]
+    KOHA.OverDriveCirculation.display_error("#breadcrumbs", "[% overdrive_error.dquote | html %]");
+    [% END %]
+    [% IF ( loggedinusername and Koha.Preference('OverDriveCirculation') ) %]
+    KOHA.OverDriveCirculation.with_account_details("#breadcrumbs", function() {
+        search( 0 );
+    });
+    [% ELSE %]
+        search( 0 );
+    [% END %]
 } );
 </script>
 [% END %]