From 480a445991b587f6bf8573861d113159c0fd4a3b Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 9 May 2016 21:14:17 -0400 Subject: [PATCH] Bug 16490 - Add an "add to cart" link for each search results in the staff client MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds an "add to cart" link to each line of search results in the staff client. To test, apply the patch and clear your browser cache if necessary. - Enable the intranetbookbag system preference. - Perform a search which will return multiple search results. - Each result should have an "Add to cart" link. - Clicking the "Add to cart" link should add the title to the cart, triggering the correct pop-up message and changing the link to read "In your cart (remove)." - Clicking the "remove" link should remove the title from your cart and trigger the correct messages. - Add multiple titles to your cart and perform the same search again. Each result should correctly indicate which titles are already in your cart. - Open the cart popup window. - Check the checkbox for one or more titles in your cart and choose "Remove." The titles should be removed, and the "In your cart" label in the search results page should reflect that the titles are no longer in the cart. - Choose "Empty and close." All titles in the parent page should now indicate that they are not in the cart. - Disable the intranetbookbag preference and confirm that the "Add to cart" links are no longer there. Followed test plan. Works as expected. Signed-off-by: Marc Véron Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- catalogue/search.pl | 12 +++++ .../intranet-tmpl/prog/css/staff-global.css | 11 +++++ .../prog/en/includes/doc-head-close.inc | 3 ++ .../prog/en/modules/catalogue/results.tt | 43 ++++++++++++++--- koha-tmpl/intranet-tmpl/prog/js/basket.js | 46 +++++++++++++++++++ 5 files changed, 108 insertions(+), 7 deletions(-) diff --git a/catalogue/search.pl b/catalogue/search.pl index c70efb0dd2..dcbd21c323 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -205,6 +205,14 @@ if($cgi->cookie("holdfor")){ ); } +# get biblionumbers stored in the cart +my @cart_list; + +if($cgi->cookie("intranet_bib_list")){ + my $cart_list = $cgi->cookie("intranet_bib_list"); + @cart_list = split(/\//, $cart_list); +} + # load the branches my $branches = GetBranches(); @@ -610,6 +618,10 @@ for (my $i=0;$i<@servers;$i++) { # in order to avoid problems generated by the default size value in TT foreach my $line (@newresults) { if ( not exists $line->{'size'} ) { $line->{'size'} = "" } + # while we're checking each line, see if item is in the cart + if ( grep {$_ eq $line->{'biblionumber'}} @cart_list) { + $line->{'incart'} = 1; + } } $template->param(SEARCH_RESULTS => \@newresults); ## FIXME: add a global function for this, it's better than the current global one diff --git a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css index bc2a03f3b6..278cd851af 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css @@ -1097,6 +1097,17 @@ a.xml { background-image: url("../img/famfamfam/silk/page_white_code.png"); } +a.cartRemove { + color: #cc3333; + font-size : 90%; + margin : 0; + padding: 0; +} + +a.incart { + color: #666; +} + div.message { background: #ffffff; /* Old browsers */ background: -moz-linear-gradient(top, #ffffff 0%, #f4f6fa 2%, #eaeef5 23%, #e8edf6 94%, #cddbf2 100%); /* FF3.6+ */ diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc index 43236f9a9b..f72425d470 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc @@ -65,6 +65,9 @@ var MSG_CONFIRM_DEL_RECORDS = _("Are you sure you want to remove the selected items?"); var MSG_IN_YOUR_CART = _("Items in your cart: %s"); var MSG_NON_RESERVES_SELECTED = _("One or more selected items cannot be reserved."); + var MSG_ITEM_NOT_IN_CART = _("Add to cart"); + var MSG_ITEM_IN_CART = _("In your cart"); + var MSG_RECORD_REMOVED = _("The item has been removed from your cart"); //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index b1ed175238..83b1b49180 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -182,7 +182,10 @@ $('#sort_by').change(function() { [% END %] [% END %] -[% IF LocalCoverImages %]KOHA.LocalCover.LoadResultsCovers();[% END %] + [% IF LocalCoverImages %] + KOHA.LocalCover.LoadResultsCovers(); + [% END %] + $("#select_all").on("click",function(e){ e.preventDefault(); selectAll(); @@ -191,6 +194,21 @@ $('#sort_by').change(function() { e.preventDefault(); clearAll(); }); + + $("#searchresults").on("click",".addtocart",function(e){ + e.preventDefault(); + var selection_id = this.id; + var biblionumber = selection_id.replace("cart",""); + addRecord(biblionumber); + }); + + $("#searchresults").on("click",".cartRemove",function(e){ + e.preventDefault(); + var selection_id = this.id; + var biblionumber = selection_id.replace("cartR",""); + delSingleRecord(biblionumber); + }); + }); @@ -560,12 +578,23 @@ var holdForPatron = function () { [% END %] [% END %] -

[% IF ( SEARCH_RESULT.norequests ) %] - No holds allowed - [% ELSE %] - Holds - [% IF ( holdfor ) %] | Place hold for [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])[% END %] - [% END %] +

+ + [% IF ( SEARCH_RESULT.norequests ) %] + No holds allowed + [% ELSE %] + Holds + [% IF ( holdfor ) %] | Place hold for [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])[% END %] + [% END %] + + [% IF Koha.Preference('intranetbookbag') == 1 %] + [% IF ( SEARCH_RESULT.incart ) %] + | In your cart (remove) + [% ELSE %] + | Add to cart + [% END %] + [% END # / IF intranetbookbag %] + [% IF ( CAN_user_editcatalogue_edit_catalogue ) %] | Edit record [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/basket.js b/koha-tmpl/intranet-tmpl/prog/js/basket.js index db74a4d94e..f2d1d6484f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/basket.js +++ b/koha-tmpl/intranet-tmpl/prog/js/basket.js @@ -126,10 +126,12 @@ function addRecord(val, selection,NoMsgAlert) { if (write) { writeCookie(nameCookie, valCookie); if (selection) { // when adding a selection of records + updateLink(val,"add"); return 1; } if (! NoMsgAlert ) { showCartUpdate(MSG_RECORD_ADDED); + updateLink(val,"add"); } } } @@ -227,6 +229,18 @@ function selRecord(num, status) { document.myform.records.value = str; } +function delSingleRecord(biblionumber){ + var valCookie = readCookie(nameCookie); + var arrayRecords = valCookie.split("/"); + var pos = jQuery.inArray(biblionumber,arrayRecords); + arrayRecords.splice(pos,1); + valCookie = arrayRecords.join("/"); + writeCookie( nameCookie, valCookie ); + updateBasket( arrayRecords.length-1 ); + updateLink(biblionumber,"del"); + showCartUpdate(MSG_RECORD_REMOVED); +} + function delSelRecords() { var recordsSel = 0; var end = 0; @@ -243,6 +257,7 @@ function delSelRecords() { num = str.substring(0, s); str = delRecord(num,str); str2 = delRecord(num,str2); + updateLink(num,"del",top.opener); } else { end = 1; } @@ -308,6 +323,7 @@ function delBasket(context,rep) { if (rep) { if(context == "popup"){ delCookie(nameCookie); + updateAllLinks(top.opener); document.location = "about:blank"; updateBasket(0,top.opener); window.close(); @@ -438,6 +454,36 @@ function hideCart(){ $("#cartDetails").fadeOut("fast"); } +function updateLink(val,op,target){ + if(target){ + if(op == "add"){ + target.$("#cart"+val).html(MSG_ITEM_IN_CART).addClass("incart"); + target.$("#cartR"+val).show(); + } else { + target.$("#cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + target.$("#cartR"+val).hide(); + } + } else { + if(op == "add"){ + $("#cart"+val).html(MSG_ITEM_IN_CART).addClass("incart"); + $("#cartR"+val).show(); + } else { + $("#cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + $("#cartR"+val).hide(); + } + } +} + +function updateAllLinks(target){ + if(target){ + target.$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + target.$(".cartRemove").hide(); + } else { + $("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + $(".cartRemove").hide(); + } +} + $(document).ready(function(){ $("#cartmenulink").click(function(){ openBasket(); return false; }); if(basketcount){ updateBasket(basketcount); } -- 2.39.5