[% END %]
@@ -986,71 +992,75 @@ Note that permanent location is a code, and location may be an authval.
// http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
function verify_images() {
// Loop over each container in the template which contains covers
- $(".cover-image").each( function( index ){
- var div = $(this);
- // Find the image in the container
- var img = div.find("img")[0];
- if( $(img).length > 0 ){
- if( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ){
- // No image loaded in the container. Remove the slide
- div.remove();
- } else {
- // All slides start hidden. If this is the first one, show it.
- if( index == 0 ){
- div.show();
- }
- // Check if Amazon image is present
- if ( div.attr("id") == "amazon-bookcoverimg" ) {
- w = img.width;
- h = img.height;
- if ((w == 1) || (h == 1)) {
- // Amazon returned single-pixel placeholder
- // Remove the container
- div.remove();
+ $(".cover-slider").each(function(){
+ $(this).find(".cover-image").each( function( index ){
+ var div = $(this);
+ // Find the image in the container
+ var img = div.find("img")[0];
+ if( $(img).length > 0 ){
+ if( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ){
+ // No image loaded in the container. Remove the slide
+ div.remove();
+ } else {
+ // All slides start hidden. If this is the first one, show it.
+ if( index == 0 ){
+ div.show();
}
- }
- if( div.attr("id") == "custom-img" ){
- if ( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ) {
- // No image was loaded via the CustomCoverImages system preference
- // Remove the container
- div.remove();
+ // Check if Amazon image is present
+ if ( div.attr("id") == "amazon-bookcoverimg" ) {
+ w = img.width;
+ h = img.height;
+ if ((w == 1) || (h == 1)) {
+ // Amazon returned single-pixel placeholder
+ // Remove the container
+ div.remove();
+ }
}
- }
- if( div.attr("id") == "coce-coverimg" ){
- // Identify which service's image is being loaded by Coce
- if( $(img).attr("src").indexOf('amazon.com') >= 0 ){
- div.find(".hint").html(_("Coce image from Amazon.com"));
- } else if( $(img).attr("src").indexOf('google.com') >= 0 ){
- div.find(".hint").html(_("Coce image from Google Books"));
- } else if( $(img).attr("src").indexOf('openlibrary.org') >= 0 ){
- div.find(".hint").html(_("Coce image from Open Library"));
+ if( div.attr("id") == "custom-img" ){
+ if ( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ) {
+ // No image was loaded via the CustomCoverImages system preference
+ // Remove the container
+ div.remove();
+ }
+ }
+ if( div.attr("id") == "coce-coverimg" ){
+ // Identify which service's image is being loaded by Coce
+ if( $(img).attr("src").indexOf('amazon.com') >= 0 ){
+ div.find(".hint").html(_("Coce image from Amazon.com"));
+ } else if( $(img).attr("src").indexOf('google.com') >= 0 ){
+ div.find(".hint").html(_("Coce image from Google Books"));
+ } else if( $(img).attr("src").indexOf('openlibrary.org') >= 0 ){
+ div.find(".hint").html(_("Coce image from Open Library"));
+ }
}
}
}
- }
+ });
});
- var coverSlides = $(".cover-image");
- if( coverSlides.length > 1 ){
- coverSlides.each(function( index ){
- // If more that one slide is present, add a navigation link
- // for activating the slide
- var covernav = $("");
- if( index == 0 ){
- // Set the first navigation link as active
- $(covernav).addClass("nav-active");
- }
- $(covernav).html("");
- $("#cover-slides").append( covernav );
+ $(".cover-slider").each(function(){
+ var coverSlide = this;
+ var coverImages = $(this).find(".cover-image");
+ if( coverImages.length > 1 ){
+ coverImages.each(function( index ){
+ // If more that one image is present, add a navigation link
+ // for activating the slide
+ var covernav = $("");
+ if( index == 0 ){
+ // Set the first navigation link as active
+ $(covernav).addClass("nav-active");
+ }
+ $(covernav).html("");
+ $(coverSlide).append( covernav );
+ });
+ }
- });
- }
-
- if( $(".cover-image:visible").length < 1 ){
- $("#cover-slides").remove();
- } else {
- $("#cover-slides").addClass("cover-slides");
- }
+ if( $(coverSlide).find(".cover-image:visible").length < 1 ){
+ $(coverSlide).remove();
+ } else {
+ $(coverSlide).addClass("cover-slides");
+ }
+ });
$("#editions img").each(function(i){
if ( this.src.indexOf('amazon.com') >= 0 ) {
@@ -1223,14 +1233,15 @@ Note that permanent location is a code, and location may be an authval.
link = $(this).attr("href");
openWindow(link,"Print spine label",400,400);
});
- $("#cover-slides").on("click",".cover-nav", function(e){
+ $(".cover-slider").on("click",".cover-nav", function(e){
e.preventDefault();
+ var cover_slider = $(this).parent();
// Adding click handler for cover image navigation links
var num = $(this).data("num");
- $(".cover-nav").removeClass("nav-active");
+ $(cover_slider).find(".cover-nav").removeClass("nav-active");
$(this).addClass("nav-active");
- $(".cover-image").hide();
- $(".cover-image").eq( num ).show();
+ $(cover_slider).find(".cover-image").hide();
+ $(cover_slider).find(".cover-image").eq( num ).show();
});
});
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt
index 9abce8f7ec..9ebb48e462 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt
@@ -100,7 +100,7 @@
- [% IF AllowMultipleCovers == 0 OR itemnumber%]
+ [% IF AllowMultipleCovers == 0 %]
[% ELSE %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
index c650fcc845..261b1b36dd 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
@@ -1267,7 +1267,9 @@
[% IF ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %]
-
+ [% FOR image IN ITEM_RESULT.cover_images %]
+
+ [% END %]
[% END %]
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index 67c074cd70..8b935af155 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -763,22 +763,21 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
}
if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) {
- my $cover_image = $item->cover_image;
- $itm->{imagenumber} = $cover_image ? $cover_image->imagenumber : undef;
+ $itm->{cover_images} = $item->cover_images;
}
my $itembranch = $itm->{$separatebranch};
if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
if ($itembranch and $itembranch eq $currentbranch) {
push @itemloop, $itm;
- $itemloop_has_images++ if $itm->{imagenumber};
+ $itemloop_has_images++ if $item->cover_images->count;
} else {
push @otheritemloop, $itm;
- $otheritemloop_has_images++ if $itm->{imagenumber};
+ $otheritemloop_has_images++ if $item->cover_images->count;
}
} else {
push @itemloop, $itm;
- $itemloop_has_images++ if $itm->{imagenumber};
+ $itemloop_has_images++ if $item->cover_images->count;
}
}
}
diff --git a/t/db_dependent/Koha/CoverImages.t b/t/db_dependent/Koha/CoverImages.t
index 66067df9b7..ff4c12ed54 100644
--- a/t/db_dependent/Koha/CoverImages.t
+++ b/t/db_dependent/Koha/CoverImages.t
@@ -19,7 +19,7 @@
use Modern::Perl;
-use Test::More tests => 13;
+use Test::More tests => 14;
use Test::Exception;
use FindBin '$Bin';
@@ -70,16 +70,16 @@ $image = Koha::CoverImage->new(
)->store;
is( $biblio->cover_images->count, 2, 'There are now two cover images' );
-is( $item->cover_image, undef, 'No cover images yet' );
+is( $item->cover_images->count, 0, 'No cover images yet' );
$image = Koha::CoverImage->new(
{
itemnumber => $item->itemnumber,
src_image => GD::Image->new($logo_filepath)
}
)->store;
-is( ref( $item->cover_image ),
+is( ref( $item->cover_images->next ),
'Koha::CoverImage',
- 'Koha::Item->cover_image returns a Koha::CoverImage object' );
+ 'Koha::Item->cover_images returns a rs of Koha::CoverImage object' );
Koha::CoverImage->new(
{
@@ -89,5 +89,6 @@ Koha::CoverImage->new(
}
)->store;
is( $biblio->cover_images->count, 3, );
+is( $item->cover_images->count, 2, );
$schema->storage->txn_rollback;
diff --git a/tools/upload-cover-image.pl b/tools/upload-cover-image.pl
index 85cbedc465..6c19de1e99 100755
--- a/tools/upload-cover-image.pl
+++ b/tools/upload-cover-image.pl
@@ -94,11 +94,12 @@ if ($fileID) {
$fh->close if $fh;
if ( defined $srcimage ) {
eval {
- if ( $replace && $biblionumber ) {
- Koha::Biblios->find($biblionumber)->cover_images->delete;
- } elsif ( $itemnumber ) {
- my $cover_image = Koha::Items->find($itemnumber)->cover_image;
- $cover_image->delete if $cover_image;
+ if ( $replace ) {
+ if ( $biblionumber ) {
+ Koha::Biblios->find($biblionumber)->cover_images->delete;
+ } elsif ( $itemnumber ) {
+ Koha::Items->find($itemnumber)->cover_images->delete;
+ }
}
Koha::CoverImage->new(
@@ -181,10 +182,12 @@ if ($fileID) {
if ( defined $srcimage ) {
$total++;
eval {
- if ( $replace && $biblionumber ) {
- Koha::Biblios->find($biblionumber)->cover_images->delete;
- } elsif ( $itemnumber ) {
- Koha::Items->find($itemnumber)->cover_image->delete;
+ if ( $replace ) {
+ if ( $biblionumber ) {
+ Koha::Biblios->find($biblionumber)->cover_images->delete;
+ } elsif ( $itemnumber ) {
+ Koha::Items->find($itemnumber)->cover_images->delete;
+ }
}
Koha::CoverImage->new(