@@ -, +, @@ in the staff client - 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. --- catalogue/search.pl | 12 ++++++ koha-tmpl/intranet-tmpl/prog/css/staff-global.css | 11 ++++++ .../prog/en/includes/doc-head-close.inc | 3 ++ .../prog/en/modules/catalogue/results.tt | 37 ++++++++++++++--- koha-tmpl/intranet-tmpl/prog/js/basket.js | 46 ++++++++++++++++++++++ 5 files changed, 103 insertions(+), 6 deletions(-) --- a/catalogue/search.pl +++ a/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 --- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css +++ a/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+ */ --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ a/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"); //]]> --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -184,6 +184,20 @@ $('#sort_by').change(function() { [% IF LocalCoverImages %]KOHA.LocalCover.LoadResultsCovers();[% END %] + $("#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); + }); + }); @@ -553,12 +567,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 %] --- a/koha-tmpl/intranet-tmpl/prog/js/basket.js +++ a/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(); @@ -439,6 +455,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); } --