From 2d078a18e5e090bcafa64262bb5f8dceed796169 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 3 Oct 2018 14:13:49 +0000 Subject: [PATCH] Bug 21479: Fix remove from cart links at the OPAC (should remove only 1) This patch changes the way biblionumbers are passed to the cart script for adding and removing single items. The title's biblionumber is now stored in a data-attribute on the links for adding and removing. This should be a more robust, unified way to handle these single-item operations. To test, apply the patch and enable the opacbookbag system preference. Test adding and removing items from the cart from various pages using various methods: - By clicking an "Add to your cart" / "Remove" link in search results - By clicking an "Add to your cart" / "Remove" link on a detail page - By checking boxes in search results and adding via the dropdown Each operation should work correctly. Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 2cd49034c43a16c7497f05e94c18396532fceddc) Signed-off-by: Martin Renvoize --- .../bootstrap/en/includes/opac-bottom.inc | 17 ++++++++++------- .../en/includes/opac-detail-sidebar.inc | 4 ++-- .../bootstrap/en/modules/opac-results.tt | 4 ++-- koha-tmpl/opac-tmpl/bootstrap/js/basket.js | 5 ++++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index 735cc894bc..16ca89629f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -164,15 +164,18 @@ $.widget.bridge('uitooltip', $.ui.tooltip); Dopop('opac-addbybiblionumber.pl?biblionumber=[% biblionumber | html %]'); return false; }); - $(".addrecord").on("click",function(){ - addRecord('[% biblionumber | html %]'); - return false; + $("body").on("click", ".addtocart", function(e){ + e.preventDefault(); + var biblionumber = $(this).data("biblionumber"); + addRecord( biblionumber ); }); - $(".cartRemove").on("click",function(){ - delSingleRecord('[% biblionumber | html %]'); - return false; + $("body").on("click", ".cartRemove", function(e){ + e.preventDefault(); + var biblionumber = $(this).data("biblionumber"); + delSingleRecord( biblionumber ); }); - $(".clearsh").on("click", function(){ + $(".clearsh").on("click", function(e){ + e.preventDefault(); return confirmDelete(MSG_DELETE_SEARCH_HISTORY); }); //]]> diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index e408d0af9e..8b6973bfb7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -26,9 +26,9 @@ [% IF Koha.Preference( 'opacbookbag' ) == 1 %] [% IF ( incart ) %] -
  • In your cart (remove)
  • +
  • In your cart (remove)
  • [% ELSE %] -
  • Add to your cart
  • +
  • Add to your cart
  • [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index 375f56afeb..8f23598260 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -534,9 +534,9 @@ [% IF Koha.Preference( 'opacbookbag' ) == 1 %] [% IF ( SEARCH_RESULT.incart ) %] - In your cart (remove) + In your cart (remove) [% ELSE %] - Add to cart + Add to your cart [% END %] [% END # / IF opacbookbag %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js index 9eb66309ab..250a0afa30 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js @@ -1,3 +1,5 @@ +/* global MSG_BASKET_EMPTY MSG_RECORD_IN_BASKET MSG_RECORD_ADDED MSG_NRECORDS_IN_BASKET MSG_NRECORDS_ADDED MSG_NO_RECORD_SELECTED MSG_NO_RECORD_ADDED MSG_IN_YOUR_CART MSG_RECORD_REMOVED MSG_CONFIRM_DEL_BASKET MSG_CONFIRM_DEL_RECORDS MSG_ITEM_IN_CART MSG_ITEM_NOT_IN_CART */ + ////////////////////////////////////////////////////////////////////////////// // BASIC FUNCTIONS FOR COOKIE MANAGEMENT // ////////////////////////////////////////////////////////////////////////////// @@ -230,11 +232,12 @@ function selRecord(num, status) { } function delSingleRecord(biblionumber){ + biblionumber = String( biblionumber ); var nameCookie = "bib_list"; var valCookie = readCookie(nameCookie); var arrayRecords = valCookie.split("/"); var pos = jQuery.inArray(biblionumber,arrayRecords); - arrayRecords.splice(pos,1); + arrayRecords.splice( pos, 1 ); valCookie = arrayRecords.join("/"); writeCookie( nameCookie, valCookie ); updateBasket( arrayRecords.length-1 ); -- 2.39.5