From 2baba4b62e64aff7efc96c1d394db64fe14146e6 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 16 Oct 2020 15:32:03 +0000 Subject: [PATCH] Bug 26707: Split cart and lists button on bibliographic detail pages This patch modifies the toolbar shown on bibliographic detail pages so that the "Add to cart" and "Add to lists" buttons are separate. The "Add to cart" will now reflect whether the title is in the cart. The "Add to lists" button will now be a menu of list choices like it is on the search results page. To test, apply the patch and rebuild the staff client CSS (https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client). Search for a title in the staff client and view the detail page for one of the results. Testing the cart button: - In the toolbar you should see an "Add to cart" button and an "Add to lists" menu button. - Clicking the "Add to cart" button should show the cart message associated with cart link in the header. - The label showing the number of items in the cart should be incremented. - The button should change to a "Remove from cart" button. - Clicking the "Remove from cart" button should correctly remove the item from the cart: - The label showing the number of items in the cart should be decremented. - The button should change to "Add to cart." - Add a title to the cart and click the cart link in the header to open the cart pop-up window. - Click the "Empty and close" button in the cart window. - After you confirm the cart window should close. The "Remove from cart" button should now be an "Add to cart" button. - Add a title to the cart and navigate between each of the other views of that title: Normal, MARC, Labeled MARC, and ISBD. On each page you should see a "Remove from cart" button. - Test the add and remove functions from each of the other bibliographic detail views. Testing the lists button: - On the normal bibliographic detail page you should see an "Add to list" menu button. Clicking it should reveal the same kind of lists menu you see on the catalog search results page, with recent public and private lists and options for "More lists" and "New list." - Test that each of these options works correctly to trigger the expected pop-up window. - Confrim that the correct title is added to the correct list. - Perform this test from each of the bibliographic detail pages: Normal, MARC, Labeled MARC, and ISBD. --- catalogue/ISBDdetail.pl | 33 ++++++++++ catalogue/MARCdetail.pl | 34 ++++++++++ catalogue/detail.pl | 32 +++++++++ catalogue/labeledMARCdetail.pl | 33 ++++++++++ .../intranet-tmpl/prog/css/src/staff-global.scss | 18 ++++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 75 ++++++++++++++++++---- .../prog/en/modules/catalogue/ISBDdetail.tt | 1 + .../prog/en/modules/catalogue/MARCdetail.tt | 1 + .../prog/en/modules/catalogue/labeledMARCdetail.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/basket.js | 29 +++++++-- koha-tmpl/intranet-tmpl/prog/js/catalog.js | 39 +++++++++-- 11 files changed, 270 insertions(+), 26 deletions(-) diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl index 898f57ab5d..d26780a8e2 100755 --- a/catalogue/ISBDdetail.pl +++ b/catalogue/ISBDdetail.pl @@ -49,6 +49,7 @@ use C4::Search; # enabled_staff_search_views use Koha::Biblios; use Koha::Patrons; use Koha::RecordProcessor; +use Koha::Virtualshelves; my $query = CGI->new; @@ -138,6 +139,38 @@ if ($subscriptionsnumber) { ); } +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("intranet_bib_list")){ + my $cart_list = $query->cookie("intranet_bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + +my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $loggedinuser, + add_allowed => 1, + category => 1, + } +); +my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $loggedinuser, + add_allowed => 1, + category => 2, + } +); + + +$template->param( + add_to_some_private_shelves => $some_private_shelves, + add_to_some_public_shelves => $some_public_shelves, +); + $template->param ( ISBD => $res, biblionumber => $biblionumber, diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index 4f30839f2c..97ce943a2f 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -62,6 +62,7 @@ use Koha::Biblios; use Koha::BiblioFrameworks; use Koha::Patrons; use Koha::DateUtils; +use Koha::Virtualshelves; use List::MoreUtils qw( uniq ); @@ -325,6 +326,38 @@ if ($subscriptionscount) { ); } +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("intranet_bib_list")){ + my $cart_list = $query->cookie("intranet_bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + +my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $loggedinuser, + add_allowed => 1, + category => 1, + } +); +my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $loggedinuser, + add_allowed => 1, + category => 2, + } +); + + +$template->param( + add_to_some_private_shelves => $some_private_shelves, + add_to_some_public_shelves => $some_public_shelves, +); + $template->param ( item_loop => \@item_loop, item_header_loop => \@item_header_loop, @@ -337,6 +370,7 @@ $template->param ( C4::Search::enabled_staff_search_views, searchid => scalar $query->param('searchid'), biblio => $biblio_object, + loggedinuser => $loggedinuser, ); $template->param( holdcount => $biblio_object->holds->count ); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 7b7f4d2944..9cb607b1e1 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -438,6 +438,27 @@ if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { } } +my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $borrowernumber, + add_allowed => 1, + category => 1, + } +); +my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $borrowernumber, + add_allowed => 1, + category => 2, + } +); + + +$template->param( + add_to_some_private_shelves => $some_private_shelves, + add_to_some_public_shelves => $some_public_shelves, +); + $template->param( MARCNOTES => $marcnotesarray, itemdata_ccode => $itemfields{ccode}, @@ -580,6 +601,17 @@ if ($StaffDetailItemSelection) { } } +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("intranet_bib_list")){ + my $cart_list = $query->cookie("intranet_bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + $template->param(biblio => $biblio); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/catalogue/labeledMARCdetail.pl b/catalogue/labeledMARCdetail.pl index 16eb6cacd1..47ce79024d 100755 --- a/catalogue/labeledMARCdetail.pl +++ b/catalogue/labeledMARCdetail.pl @@ -32,6 +32,7 @@ use C4::Serials; use Koha::Biblios; use Koha::BiblioFrameworks; use Koha::Patrons; +use Koha::Virtualshelves; my $query = CGI->new; my $dbh = C4::Context->dbh; @@ -120,6 +121,38 @@ for my $field ($record->fields) }; } +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("intranet_bib_list")){ + my $cart_list = $query->cookie("intranet_bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + +my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $loggedinuser, + add_allowed => 1, + category => 1, + } +); +my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + borrowernumber => $loggedinuser, + add_allowed => 1, + category => 2, + } +); + + +$template->param( + add_to_some_private_shelves => $some_private_shelves, + add_to_some_public_shelves => $some_public_shelves, +); + $template->param ( marc_data => \@marc_data, biblionumber => $biblionumber, diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index a698ec9bf9..0aa0231c55 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -1357,6 +1357,24 @@ dd { margin-top: 0; z-index: 300; } + + a.addtocart { + display: block; + } + + a.cartRemove { + padding: 6px 12px; + font-size: 12px; + display: none; + } + + a.addtocart.incart { + display: none; + } + + a.cartRemove.incart { + display: block; + } } #disabled { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 4d07b26ce6..b004628bcb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -100,19 +100,68 @@ CAN_user_serials_create_subscription ) %] -[% IF ( virtualshelves && intranetbookbag ) %] -
- - -
-[% ELSIF ( virtualshelves ) %] -
Add to list
-[% ELSIF ( intranetbookbag ) %] -
Add to cart
-[% END %] + [% IF ( intranetbookbag ) %] + [% IF ( incart ) %] +
+ Add to cart +
+
+ Remove from cart +
+ [% ELSE %] +
+ Add to cart +
+
+ Remove from cart +
+ [% END %] + [% END %] + + [% IF Koha.Preference('virtualshelves') %] +
+ + +
+ [% END # /IF virtualshelves %]
Print
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt index 6cb1cf391a..069207538e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE Koha %] [% USE Asset %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt index 1d2bec4267..f9f73f32bf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE Koha %] [% USE Asset %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/labeledMARCdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/labeledMARCdetail.tt index 096abb01a1..f951304dea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/labeledMARCdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/labeledMARCdetail.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE Koha %] [% USE Asset %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/basket.js b/koha-tmpl/intranet-tmpl/prog/js/basket.js index aa5320f844..725e3942b2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/basket.js +++ b/koha-tmpl/intranet-tmpl/prog/js/basket.js @@ -333,6 +333,7 @@ function delRecord (n, s) { function delBasket(context,rep) { + console.log("delBasket"); if (rep === undefined){ rep = confirm(MSG_CONFIRM_DEL_BASKET); } @@ -484,22 +485,36 @@ function updateLink(val, op, target){ var cartR = target ? target.$("#cartR" + val) : $("#cartR" + val); if(op == "add"){ - cart.html(MSG_ITEM_IN_CART).addClass("incart"); + if( cart.hasClass("btn") ){ + /* Cart link is a button with an icon */ + cart.html(" " + __("Add to cart")).addClass("incart"); + cart.hide(); + } else { + cart.html(MSG_ITEM_IN_CART).addClass("incart"); + } cartR.show(); } else { - cart.html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + if (cart.hasClass("btn")) { + cart.html(" " + __("Add to cart")).addClass("addtocart"); + cart.show(); + } else { + cart.html(MSG_ITEM_NOT_IN_CART).addClass("addtocart"); + } cartR.hide(); } } function updateAllLinks(target){ - if(target){ - target.$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); - target.$(".cartRemove").hide(); + var cart = target ? target.$("a.incart") : $("a.incart"); + var cartR = target ? target.$(".cartRemove") : $(".cartRemove"); + if( cart.hasClass("btn") ){ + /* Cart link is a button with an icon */ + cart.html(" " + __("Add to cart")).addClass("incart"); + cartR.hide(); } else { - $("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); - $(".cartRemove").hide(); + cart.html(MSG_ITEM_IN_CART).addClass("incart"); } + cart.show(); } $(document).ready(function(){ diff --git a/koha-tmpl/intranet-tmpl/prog/js/catalog.js b/koha-tmpl/intranet-tmpl/prog/js/catalog.js index af19ebe8c4..76428397f1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/catalog.js +++ b/koha-tmpl/intranet-tmpl/prog/js/catalog.js @@ -1,4 +1,4 @@ -/* global __ biblionumber count holdcount countorders countdeletedorders searchid addRecord */ +/* global __ biblionumber count holdcount countorders countdeletedorders searchid addRecord delSingleRecord */ /* exported GetZ3950Terms PopupZ3950Confirmed */ /* IF ( CAN_user_editcatalogue_edit_catalogue ) */ /* this function open a popup to search on z3950 server. */ @@ -15,7 +15,10 @@ } /* END IF( CAN_user_editcatalogue_edit_catalogue ) */ -function addToCart() { addRecord( biblionumber ); } +function addToCart(){ + addRecord( biblionumber ); +} + function addToShelf() { window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber,'Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes'); } function printBiblio() {window.print(); } @@ -94,11 +97,22 @@ $(document).ready(function() { printBiblio(); return false; }); - $("#addtocart").click(function(){ - addToCart(); - $(".btn-group").removeClass("open"); - return false; + + $(".addtocart").on("click", function (e) { + e.preventDefault(); + var selection_id = this.id; + var biblionumber = selection_id.replace("cart", ""); + addRecord(biblionumber); + }); + + $(".cartRemove").on("click", function (e) { + e.preventDefault(); + var selection_id = this.id; + var biblionumber = selection_id.replace("cartR", ""); + delSingleRecord(biblionumber); + $(".addtocart").html(" " + __("Add to cart")); }); + $("#addtoshelf").click(function(){ addToShelf(); $(".btn-group").removeClass("open"); @@ -112,4 +126,17 @@ $(document).ready(function() { alertNoItems(); }) .tooltip(); + + $(".addtolist").on("click", function (e) { + e.preventDefault(); + var shelfnumber = $(this).data("shelfnumber"); + if ($(this).hasClass("morelists")) { + openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber); + } else if ($(this).hasClass("newlist")) { + openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&biblionumber=' + biblionumber); + } else { + openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber=' + shelfnumber + '&confirm=1&biblionumber=' + biblionumber); + } + }); + }); -- 2.11.0