From c17f6ee2555f349a170eb3679ed0eea8dbd082a8 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 20 Jan 2012 15:28:09 -0500 Subject: [PATCH] Bug 3215 [REBASED] It would be nice if "Add to Cart" changed to "Remove from Cart" Content-Type: text/plain; charset="utf-8" "Add to Cart" links in the OPAC should reflect whether a title is already in the Cart. On the results, list, and detail pages the "Add to Cart" link will say "In your cart (remove)" if the title is in your cart. The "(remove)" link will remove the title. This patch adds a check of the biblionumbers in the cart to the relevant scripts and sets a variable for the template governing whether to show "Add to cart" or "In your cart." Pages to test: - the search results page - any detail page (normal, MARC, ISBD) - any list contents page (/cgi-bin/koha/opac-shelves.pl?viewshelf=XX) Situations to test: - Add a single item to the Cart from the above pages The link should change from "Add to cart" to "In your cart (remove)" The count of items in your cart should reflect the addition, and the notification box should appear. - Remove a single item from the Cart from the above pages The link should change from "In your cart (remove)" to "Add to cart." The count of items in your cart should reflect the removal, and the notification box should appear. - View an item which is already in the cart from the above pages The cart links should reflect whether the title is already in the cart. - Remove one or more items from the Cart via the cart pop-up window View the above pages as you do so to verify that the operation is reflected immediately by the state of the "in your cart" links. - Empty the Cart from the cart pop-up window View the above pages as you do so to verify that the operation is reflected immediately by the state of the "in your cart" links. Tested in Firefox 9, Chrome 16, IE 7, and Opera 11.6 on Win 7 --- C4/VirtualShelves/Page.pm | 11 ++++ koha-tmpl/opac-tmpl/prog/en/css/opac.css | 16 ++++++ .../opac-tmpl/prog/en/includes/doc-head-close.inc | 3 + .../prog/en/includes/opac-detail-sidebar.inc | 6 ++- koha-tmpl/opac-tmpl/prog/en/js/basket.js | 50 +++++++++++++++++++- .../opac-tmpl/prog/en/modules/opac-results.tt | 8 +++- .../opac-tmpl/prog/en/modules/opac-shelves.tt | 9 +++- opac/opac-ISBDdetail.pl | 11 ++++ opac/opac-MARCdetail.pl | 11 ++++ opac/opac-detail.pl | 11 ++++ opac/opac-search.pl | 12 +++++ 11 files changed, 142 insertions(+), 6 deletions(-) diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index cfa4f60..7cab246 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -68,6 +68,14 @@ sub shelfpage ($$$$$) { my ( $shelflimit, $shelfoffset, $shelveslimit, $shelvesoffset ); my $marcflavour = C4::Context->preference("marcflavour"); + # get biblionumbers stored in the cart + my @cart_list; + my $cart_cookie = ( $type eq 'opac' ? "bib_list" : "intranet_bib_list" ); + if($query->cookie($cart_cookie)){ + my $cart_list = $query->cookie($cart_cookie); + @cart_list = split(/\//, $cart_list); + } + $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') ); $shelflimit = $shelflimit || 20; $shelfoffset = ( $itemoff - 1 ) * $shelflimit; # Sets the offset to begin retrieving items at @@ -227,6 +235,9 @@ sub shelfpage ($$$$$) { my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'}); $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} ); $this_item->{'ITEM_RESULTS'} = \@items_infos; + if ( grep {$_ eq $biblionumber} @cart_list) { + $this_item->{'incart'} = 1; + } if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnList')) { $this_item->{'TagLoop'} = get_tags({ diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css b/koha-tmpl/opac-tmpl/prog/en/css/opac.css index f904af2..f2b1467 100644 --- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css +++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css @@ -453,6 +453,18 @@ a .term { background-image:url(../../images/cart2.gif); } +#action a.cartRemove, .actions a.cartRemove { + color: #cc3333; + font-size : 90%; + margin : 0; + padding: 0; +} + +#action a.incart { + background-image:url(../../images/cart2.gif); + color : #666; +} + /* toolbar buttons */ #toolbar { @@ -1296,6 +1308,9 @@ padding-left : .4em; color: #707070; padding : 0 0 .5em 0; } +.results_summary .results_summary { + font-size : 100%; +} .m880 { display:block; @@ -1498,6 +1513,7 @@ div.lang{ box-shadow: 1px 1px 3px #666; -moz-box-shadow: 1px 1px 3px #666; -webkit-box-shadow: 1px 1px 3px #666; + z-index: 2; } diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc index 18e5917..3907f34 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc @@ -48,12 +48,15 @@ [% IF ( opacbookbag ) %]var MSG_BASKET_EMPTY = _("Your cart is currently empty"); var MSG_RECORD_IN_BASKET = _("This item is already in your cart"); var MSG_RECORD_ADDED = _("This item has been added to your cart"); + var MSG_RECORD_REMOVED = _("This item has been removed from your cart"); var MSG_NRECORDS_ADDED = _(" item(s) added to your cart"); var MSG_NRECORDS_IN_BASKET = _("already in your cart"); var MSG_NO_RECORD_SELECTED = _("No item was selected"); var MSG_NO_RECORD_ADDED = _("No item was added to your cart"); var MSG_CONFIRM_DEL_BASKET = _("Are you sure you want to empty your cart?"); var MSG_CONFIRM_DEL_RECORDS = _("Are you sure you want to remove the selected items?"); + var MSG_ITEM_IN_CART = _("In your cart"); + var MSG_ITEM_NOT_IN_CART = _("Add to your cart"); $("#cartDetails").ready(function(){ $("#cmspan").html("<\/i><\/i><\/span> "+_("Cart")+"<\/span><\/span><\/a>"); }); [% ELSE %][% IF ( virtualshelves ) %] var MSG_NO_RECORD_SELECTED = _("No item was selected");[% END %][% END %] [% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]var MSG_TAGS_DISABLED = _("Sorry, tags are not enabled on this system."); diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc index 71cb1a0..d615be6 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc @@ -21,7 +21,11 @@ [% END %][% END %] [% END %] [% IF ( opacbookbag ) %] -
  • Add to Your Cart
  • + [% IF ( incart ) %] +
  • In your cart (remove)
  • + [% ELSE %] +
  • Add to your cart
  • + [% END %] [% END %]
  • More searches
  • diff --git a/koha-tmpl/opac-tmpl/prog/en/js/basket.js b/koha-tmpl/opac-tmpl/prog/en/js/basket.js index 76d668b..1872ff3 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/basket.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/basket.js @@ -128,10 +128,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"); } } } @@ -229,12 +231,24 @@ function selRecord(num, status) { document.myform.records.value = str; } +function delSingleRecord(biblionumber){ + var nameCookie = "bib_list"; + 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; var nameCookie = "bib_list"; var valCookie = readCookie(nameCookie, 1); - if (valCookie) { var str = document.myform.records.value; if (str.length > 0){ @@ -243,9 +257,10 @@ function delSelRecords() { while (!end){ s = str.indexOf("/"); if (s>0){ - num = str.substring(0, s) + num = str.substring(0, s); str = delRecord(num,str); str2 = delRecord(num,str2); + updateLink(num,"del",top.opener); } else { end = 1; } @@ -312,6 +327,7 @@ function delBasket() { rep = confirm(MSG_CONFIRM_DEL_BASKET); if (rep) { delCookie(nameCookie); + updateAllLinks(top.opener); document.location = "about:blank"; updateBasket(0,top.opener); window.close(); @@ -462,6 +478,36 @@ function hideLists(){ $("#listsDetails").fadeOut("fast"); } +function updateLink(val,op,target){ + if(target){ + if(op == "add"){ + target.$("a.cart"+val).html(MSG_ITEM_IN_CART).addClass("incart"); + target.$("a.cartR"+val).show(); + } else { + target.$("a.cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart cart"+val); + target.$("a.cartR"+val).hide(); + } + } else { + if(op == "add"){ + $("a.cart"+val).html(MSG_ITEM_IN_CART).addClass("incart"); + $("a.cartR"+val).show(); + } else { + $("a.cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart cart"+val); + $("a.cartR"+val).hide(); + } + } +} + +function updateAllLinks(target){ + if(target){ + target.$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + target.$("a.cartRemove").hide(); + } else { + $("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); + $("a.cartRemove").hide(); + } +} + $("#cartDetails").ready(function(){ $("#cartDetails,#cartmenulink").click(function(){ hideCart(); }); $("#cartmenulink").click(function(){ openBasket(); return false; }); diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt index 2f3c7d5..22c9272 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -521,7 +521,13 @@ $(document).ready(function(){ [% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( virtualshelves ) %]Save to Lists [% END %][% END %][% END %] - [% IF ( opacbookbag ) %]Add to Cart[% END %] + [% IF ( opacbookbag ) %] + [% IF ( SEARCH_RESULT.incart ) %] + In your Cart (remove) + [% ELSE %] + Add to Cart + [% END %] + [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt index 908eb94..25c2e58 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt @@ -320,8 +320,13 @@ $(function() { [% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( virtualshelves ) %]Save to another list [% END %][% END %][% END %] - - [% IF ( opacbookbag ) %]Add to Cart[% ELSE %]nocart[% END %] + [% IF ( opacbookbag ) %] + [% IF ( itemsloo.incart ) %] + In your cart (remove) + [% ELSE %] + Add to Cart + [% END %] + [% END %] diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 3373787..e9a4c0e 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -69,6 +69,17 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $biblionumber = $query->param('biblionumber'); +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("bib_list")){ + my $cart_list = $query->cookie("bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 519791c..def6c8d 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -81,6 +81,17 @@ $template->param( bibliotitle => $biblio->{title}, ); +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("bib_list")){ + my $cart_list = $query->cookie("bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index b5a25a8..8eefbfd 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -75,6 +75,17 @@ if ( ! $record ) { } $template->param( biblionumber => $biblionumber ); +# get biblionumbers stored in the cart +my @cart_list; + +if($query->cookie("bib_list")){ + my $cart_list = $query->cookie("bib_list"); + @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + SetUTF8Flag($record); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 87d2890..3e3995d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -88,6 +88,14 @@ if ($template_name eq 'opac-results.tmpl') { $template->param('COinSinOPACResults' => C4::Context->preference('COinSinOPACResults')); } +# get biblionumbers stored in the cart +my @cart_list; + +if($cgi->cookie("bib_list")){ + my $cart_list = $cgi->cookie("bib_list"); + @cart_list = split(/\//, $cart_list); +} + if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') { $template->param($format => 1); $template->param(timestamp => strftime("%Y-%m-%dT%H:%M:%S-00:00", gmtime)) if ($format eq 'atom'); @@ -497,6 +505,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; + } } my $tag_quantity; -- 1.7.3