Koha/koha-tmpl/intranet-tmpl/prog/js/catalog.js
Owen Leonard ff2c52e093 Bug 26707: Split cart and lists button on bibliographic detail pages
This patch modifies the toolbar shown on bibliographic detail pages so
that the "Add to cart" and "Add to lists" buttons are separate. The "Add
to cart" will now reflect whether the title is in the cart. The "Add to
lists" button will now be a menu of list choices like it is on the
search results page.

To test, apply the patch and rebuild the staff client CSS
(https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client).

Search for a title in the staff client and view the detail page for one
of the results.

Testing the cart button:

- In the toolbar you should see an "Add to cart" button and an "Add to
  lists" menu button.
- Clicking the "Add to cart" button should show the cart message
  associated with cart link in the header.
  - The label showing the number of items in the cart should be
    incremented.
  - The button  should change to a "Remove from cart" button.
- Clicking the "Remove from cart" button should correctly remove the
  item from the cart:
  - The label showing the number of items in the cart should be
    decremented.
  - The button should change to "Add to cart."
- Add a title to the cart and click the cart link in the header to open
  the cart pop-up window.
  - Click the "Empty and close" button in the cart window.
  - After you confirm the cart window should close. The "Remove from
    cart" button should now be an "Add to cart" button.
- Add a title to the cart and navigate between each of the other views
  of that title: Normal, MARC, Labeled MARC, and ISBD. On each page you
  should see a "Remove from cart" button.
- Test the add and remove functions from each of the other bibliographic
  detail views.

Testing the lists button:

- On the normal bibliographic detail page you should see an "Add to
  list" menu button. Clicking it should reveal the same kind of lists
  menu you see on the catalog search results page, with recent public
  and private lists and options for "More lists" and "New list."
  - Test that each of these options works correctly to trigger the
    expected pop-up window.
  - Confrim that the correct title is added to the correct list.
- Perform this test from each of the bibliographic detail pages: Normal,
  MARC, Labeled MARC, and ISBD.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-01-04 16:31:29 +01:00

142 lines
5.9 KiB
JavaScript

/* global __ biblionumber count holdcount countorders countdeletedorders searchid addRecord delSingleRecord */
/* exported GetZ3950Terms PopupZ3950Confirmed */
/* IF ( CAN_user_editcatalogue_edit_catalogue ) */
/* this function open a popup to search on z3950 server. */
function PopupZ3950() {
var strQuery = GetZ3950Terms();
if(strQuery){
window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=" + biblionumber + strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
}
}
function PopupZ3950Confirmed() {
if (confirm( __("Please note that this external search could replace the current record.") )) {
PopupZ3950();
}
}
/* END IF( CAN_user_editcatalogue_edit_catalogue ) */
function addToCart(){
addRecord( biblionumber );
}
function addToShelf() { window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber,'Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes');
}
function printBiblio() {window.print(); }
/* IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
function confirm_deletion(link) {
var order_manage_permission = $(link).data("order-manage");
var is_confirmed;
if (count > 0){
is_confirmed = alert(__("%s item(s) are attached to this record. You must delete all items before deleting this record.").format(count));
} else if (countorders > 0){
if( order_manage_permission ){
is_confirmed = confirm(__("Warning: This record is used in %s order(s). Deleting it could cause serious issues on acquisition module. Are you sure you want to delete this record?").format(countorders));
} else {
is_confirmed = alert(__("%s order(s) are using this record. You need order managing permissions to delete this record.").format(countorders));
}
} else if (countdeletedorders > 0){
if( order_manage_permission ){
is_confirmed = confirm(__("%s deleted order(s) are using this record. Are you sure you want to delete this record?").format(countdeletedorders));
} else {
is_confirmed = alert(__("%s deleted order(s) are using this record. You need order managing permissions to delete this record.").format(countdeletedorders));
}
} else if ( holdcount > 0 ) {
is_confirmed = confirm( __("%s holds(s) for this record. Are you sure you want to delete this record?").format(holdcount));
} else {
is_confirmed = confirm( __("Are you sure you want to delete this record?") );
}
if (is_confirmed) {
$("#deletebiblio").unbind('click');
window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&amp;biblionumber=" + biblionumber + (searchid ? "&amp;searchid="+searchid : "");
} else {
return false;
}
}
/* END IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
/* IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
function confirm_items_deletion() {
if ( holdcount > 0 ) {
alert(__("%s hold(s) on this record. You must delete all holds before deleting all items.").format(holdcount));
} else if ( count > 0 ) {
if (confirm(__("Are you sure you want to delete the %s attached items?").format(count))) {
window.location="/cgi-bin/koha/cataloguing/additem.pl?op=delallitems&amp;biblionumber=" + biblionumber + (searchid ? "&amp;searchid="+searchid : "");
} else {
return false;
}
} else {
alertNoItems();
return false;
}
}
function alertNoItems(){
alert( __("This record has no items.") );
}
/* END IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
$(document).ready(function() {
$("#z3950copy").click(function(){
PopupZ3950();
return false;
});
$("#deletebiblio").click(function(){
confirm_deletion(this);
return false;
});
$("#deleteallitems").click(function(){
confirm_items_deletion();
return false;
});
$("#printbiblio").click(function(){
printBiblio();
return false;
});
$(".addtocart").on("click", function (e) {
e.preventDefault();
var selection_id = this.id;
var biblionumber = selection_id.replace("cart", "");
addRecord(biblionumber);
});
$(".cartRemove").on("click", function (e) {
e.preventDefault();
var selection_id = this.id;
var biblionumber = selection_id.replace("cartR", "");
delSingleRecord(biblionumber);
$(".addtocart").html("<i class=\"fa fa-shopping-cart\"></i> " + __("Add to cart"));
});
$("#addtoshelf").click(function(){
addToShelf();
$(".btn-group").removeClass("open");
return false;
});
$("#export").remove(); // Hide embedded export form if JS menus available
$("#deletebiblio").tooltip();
$("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled")
.on("click",function(e){
e.preventDefault();
alertNoItems();
})
.tooltip();
$(".addtolist").on("click", function (e) {
e.preventDefault();
var shelfnumber = $(this).data("shelfnumber");
if ($(this).hasClass("morelists")) {
openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber);
} else if ($(this).hasClass("newlist")) {
openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&biblionumber=' + biblionumber);
} else {
openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber=' + shelfnumber + '&confirm=1&biblionumber=' + biblionumber);
}
});
});