Line 0
Link Here
|
|
|
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 |
<script type="text/javascript" src="[% themelang %]/js/overdrive.js"></script> |
5 |
<script type="text/javascript"> |
6 |
var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]"; |
7 |
var results_per_page = [% OPACnumSearchResults %]; |
8 |
|
9 |
function fetch_availability( prod, $tr ) { |
10 |
var $availability_summary = $( '<span class="results_summary"></span>' ); |
11 |
$tr.find( '.info' ).append( $availability_summary ); |
12 |
$availability_summary.html( '<span class="label">Availability: </span> Loading...' ); |
13 |
|
14 |
KOHA.OverDrive.Get( |
15 |
prod.links.availability.href, |
16 |
{}, |
17 |
function ( data ) { |
18 |
if ( data.error ) return; |
19 |
|
20 |
$availability_summary.html( '<span class="label">Copies available: </span><span class="available"><strong>' + data.copiesAvailable + '</strong> out of ' + data.copiesOwned + '</span>' ); |
21 |
|
22 |
if ( data.numberOfHolds ) { |
23 |
$availability_summary.find( '.available' ).append( ', waiting holds: <strong>' + data.numberOfHolds + '</strong>' ); |
24 |
} |
25 |
|
26 |
$tr.find( '.info' ).append( '<span class="results_summary actions"><span class="label">Actions: </span><a href="http://' + prod.contentDetails[0].href + '" ' + ( data.copiesAvailable ? ' class="addtocart">Check out' : ' class="hold">Place hold' ) + '</a></span>' ); |
27 |
} |
28 |
); |
29 |
} |
30 |
|
31 |
function search( offset ) { |
32 |
$( '#overdrive-status' ).html( 'Searching OverDrive... <img class="throbber" src="/opac-tmpl/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' ); |
33 |
|
34 |
KOHA.OverDrive.Search( "[% OverDriveLibraryID %]", querystring, results_per_page, offset, function( data ) { |
35 |
if ( data.error ) { |
36 |
$( '#overdrive-status' ).html( '<strong class="unavailable">Error searching OverDrive collection.</strong>' ); |
37 |
return; |
38 |
} |
39 |
|
40 |
if ( !data.totalItems ) { |
41 |
$( '#overdrive-status' ).html( '<strong>No results found in the library\'s OverDrive collection.</strong>' ); |
42 |
return; |
43 |
} |
44 |
|
45 |
$( '#results tbody' ).empty(); |
46 |
|
47 |
$( '#overdrive-status' ).html( '<strong>Found ' + data.totalItems + ' results in the library\'s OverDrive collection.</strong>' ); |
48 |
|
49 |
for ( var i = 0; data.products[i]; i++ ) { |
50 |
var prod = data.products[i]; |
51 |
var results = []; |
52 |
|
53 |
results.push( '<tr>' ); |
54 |
|
55 |
results.push( '<td class="info"><a class="title" href="http://', prod.contentDetails[0].href, '">' ); |
56 |
results.push( prod.title ); |
57 |
if ( prod.subtitle ) results.push( ', ', prod.subtitle ); |
58 |
results.push( '</a>' ); |
59 |
results.push( '<p>by ', prod.primaryCreator.name, '</p>' ); |
60 |
results.push( '<span class="results_summary"><span class="label">Type: </span>', prod.mediaType, '</span>' ); |
61 |
if ( prod.starRating ) results.push( '<span class="results_summary"><span class="label">Average rating: <img src="[% themelang %]/../images/Star', Math.round( parseInt( prod.starRating )), '.gif" title="" style="max-height: 15px; vertical-align: bottom"/></span>' ); |
62 |
results.push( '</td>' ); |
63 |
|
64 |
results.push( '<td>' ); |
65 |
if ( prod.images.thumbnail ) { |
66 |
results.push( '<a href="http://', prod.contentDetails[0].href, '">' ); |
67 |
results.push( '<img class="thumbnail" src="', prod.images.thumbnail.href, '" />' ); |
68 |
results.push( '</a>' ); |
69 |
} |
70 |
results.push( '</td>' ); |
71 |
|
72 |
results.push( '</tr>' ); |
73 |
var $tr = $( results.join( '' )); |
74 |
$( '#results tbody' ).append( $tr ); |
75 |
|
76 |
fetch_availability( prod, $tr ); |
77 |
} |
78 |
|
79 |
$( '#results tr:odd' ).addClass( 'highlight' ); |
80 |
|
81 |
var pages = []; |
82 |
var cur_page = offset / results_per_page; |
83 |
var max_page = Math.floor( data.totalItems / results_per_page ); |
84 |
|
85 |
if ( cur_page != 0 ) { |
86 |
pages.push( '<a class="nav" href="#" data-offset="' + (offset - results_per_page) + '"><< Previous</a>' ); |
87 |
} |
88 |
|
89 |
for ( var page = Math.max( 0, cur_page - 9 ); page <= Math.min( max_page, cur_page + 9 ); page++ ) { |
90 |
if ( page == cur_page ) { |
91 |
pages.push( ' <span class="current">' + ( page + 1 ) + '</span>' ); |
92 |
} else { |
93 |
pages.push( ' <a class="nav" href="#" data-offset="' + ( page * results_per_page ) + '">' + ( page + 1 ) + '</a>' ); |
94 |
} |
95 |
} |
96 |
|
97 |
if ( cur_page < max_page ) { |
98 |
pages.push( ' <a class="nav" href="#" data-offset="' + (offset + results_per_page) + '">Next >></a>' ); |
99 |
} |
100 |
|
101 |
if ( pages.length > 1 ) $( '#top-pages, #bottom-pages' ).find( '.pages' ).html( pages.join( '' ) ); |
102 |
} ); |
103 |
} |
104 |
|
105 |
$( document ).ready( function() { |
106 |
$( '#breadcrumbs p' ) |
107 |
.append( ' ' ) |
108 |
.append( '<span id="overdrive-status"></span>' ); |
109 |
|
110 |
$( document ).on( 'click', 'a.nav', function() { |
111 |
search( $( this ).data( 'offset' ) ); |
112 |
return false; |
113 |
}); |
114 |
|
115 |
search( 0 ); |
116 |
} ); |
117 |
</script> |
118 |
<style> |
119 |
.actions a.addtocart { |
120 |
display: inline; |
121 |
} |
122 |
</style> |
123 |
</head> |
124 |
<body> |
125 |
[% IF ( OpacNav ) %] |
126 |
<div id="doc3" class="yui-t1"> |
127 |
[% ELSE %] |
128 |
<div id="doc3" class="yui-t7"> |
129 |
[% END %] |
130 |
<div id="bd"> |
131 |
[% INCLUDE 'masthead.inc' %] |
132 |
|
133 |
<h1>OverDrive search for '[% q | html %]'</h1> |
134 |
<div id="breadcrumbs"> |
135 |
<p></p> |
136 |
</div> |
137 |
|
138 |
<div id="yui-main"><div class="yui-b searchresults"> |
139 |
<div id="top-pages"> |
140 |
<div class="pages"> |
141 |
</div> |
142 |
</div> |
143 |
<table id="results"> |
144 |
<tbody> |
145 |
</tbody> |
146 |
</table> |
147 |
<div id="bottom-pages"> |
148 |
<div class="pages"> |
149 |
</div> |
150 |
</div> |
151 |
</div></div> |
152 |
|
153 |
[% IF ( OpacNav ) %] |
154 |
<div class="yui-b"><div id="opacnav" class="container"> |
155 |
[% INCLUDE 'navigation.inc' %] |
156 |
</div></div> |
157 |
[% END %] |
158 |
|
159 |
|
160 |
</div> |
161 |
[% INCLUDE 'opac-bottom.inc' %] |