Bug 16490 - Add an "add to cart" link for each search results in the staff client

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 <veron@veron.ch>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Owen Leonard 2016-05-09 21:14:17 -04:00 committed by Kyle M Hall
parent 24729ff8f9
commit 480a445991
5 changed files with 108 additions and 7 deletions

View file

@ -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

View file

@ -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+ */

View file

@ -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");
//]]>
</script>

View file

@ -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 %]
<p class="hold">[% IF ( SEARCH_RESULT.norequests ) %]
<span class="noholdstext">No holds allowed</span>
[% ELSE %]
<a id="reserve_[% SEARCH_RESULT.biblionumber %]" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Holds</a>
[% IF ( holdfor ) %] <span class="holdforlink">| <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]&amp;findborrower=[% holdfor_cardnumber %]">Place hold for [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])</a></span>[% END %]
[% END %]
<p class="hold">
[% IF ( SEARCH_RESULT.norequests ) %]
<span class="noholdstext">No holds allowed</span>
[% ELSE %]
<a id="reserve_[% SEARCH_RESULT.biblionumber %]" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Holds</a>
[% IF ( holdfor ) %] <span class="holdforlink">| <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]&amp;findborrower=[% holdfor_cardnumber %]">Place hold for [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])</a></span>[% END %]
[% END %]
[% IF Koha.Preference('intranetbookbag') == 1 %]
[% IF ( SEARCH_RESULT.incart ) %]
| <a class="addtocart" id="cart[% SEARCH_RESULT.biblionumber %]" href="#">In your cart</a> <a class="cartRemove" id="cartR[% SEARCH_RESULT.biblionumber %]" href="#">(remove)</a>
[% ELSE %]
| <a class="addtocart" id="cart[% SEARCH_RESULT.biblionumber %]" href="#">Add to cart</a> <a style="display:none;" class="cartRemove" id="cartR[% SEARCH_RESULT.biblionumber %]" href="#">(remove)</a>
[% END %]
[% END # / IF intranetbookbag %]
[% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
| <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Edit record</a>
[% END %]

View file

@ -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); }