Bug 26707: Split cart and lists button on bibliographic detail pages
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / catalog.js
1 /* global __ biblionumber count holdcount countorders countdeletedorders searchid addRecord delSingleRecord */
2 /* exported GetZ3950Terms PopupZ3950Confirmed */
3 /* IF ( CAN_user_editcatalogue_edit_catalogue ) */
4     /* this function open a popup to search on z3950 server.  */
5     function PopupZ3950() {
6         var strQuery = GetZ3950Terms();
7         if(strQuery){
8             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');
9         }
10     }
11     function PopupZ3950Confirmed() {
12         if (confirm( __("Please note that this external search could replace the current record.") )) {
13             PopupZ3950();
14         }
15     }
16 /* END IF( CAN_user_editcatalogue_edit_catalogue ) */
17
18 function addToCart(){
19     addRecord( biblionumber );
20 }
21
22 function addToShelf() { window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber,'Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes');
23 }
24 function printBiblio() {window.print(); }
25
26 /* IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
27
28 function confirm_deletion(link) {
29     var order_manage_permission = $(link).data("order-manage");
30     var is_confirmed;
31     if (count > 0){
32         is_confirmed = alert(__("%s item(s) are attached to this record. You must delete all items before deleting this record.").format(count));
33     } else if (countorders > 0){
34         if( order_manage_permission ){
35             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));
36         } else {
37             is_confirmed = alert(__("%s order(s) are using this record. You need order managing permissions to delete this record.").format(countorders));
38         }
39     } else if (countdeletedorders > 0){
40         if( order_manage_permission ){
41             is_confirmed = confirm(__("%s deleted order(s) are using this record. Are you sure you want to delete this record?").format(countdeletedorders));
42         } else {
43             is_confirmed = alert(__("%s deleted order(s) are using this record. You need order managing permissions to delete this record.").format(countdeletedorders));
44         }
45     } else if ( holdcount > 0 ) {
46         is_confirmed = confirm( __("%s holds(s) for this record. Are you sure you want to delete this record?").format(holdcount));
47     } else {
48         is_confirmed = confirm( __("Are you sure you want to delete this record?") );
49     }
50     if (is_confirmed) {
51         $("#deletebiblio").unbind('click');
52         window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=" + biblionumber + (searchid ? "&searchid="+searchid : "");
53     } else {
54         return false;
55     }
56 }
57
58 /* END IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
59
60 /* IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
61
62 function confirm_items_deletion() {
63     if ( holdcount > 0 ) {
64         alert(__("%s hold(s) on this record. You must delete all holds before deleting all items.").format(holdcount));
65     } else if ( count > 0 ) {
66         if (confirm(__("Are you sure you want to delete the %s attached items?").format(count))) {
67             window.location="/cgi-bin/koha/cataloguing/additem.pl?op=delallitems&biblionumber=" + biblionumber + (searchid ? "&searchid="+searchid : "");
68         } else {
69             return false;
70         }
71     } else {
72         alertNoItems();
73         return false;
74     }
75 }
76
77 function alertNoItems(){
78     alert( __("This record has no items.") );
79 }
80
81 /* END IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
82
83 $(document).ready(function() {
84     $("#z3950copy").click(function(){
85         PopupZ3950();
86         return false;
87     });
88     $("#deletebiblio").click(function(){
89         confirm_deletion(this);
90         return false;
91     });
92     $("#deleteallitems").click(function(){
93         confirm_items_deletion();
94         return false;
95     });
96     $("#printbiblio").click(function(){
97         printBiblio();
98         return false;
99     });
100
101     $(".addtocart").on("click", function (e) {
102         e.preventDefault();
103         var selection_id = this.id;
104         var biblionumber = selection_id.replace("cart", "");
105         addRecord(biblionumber);
106     });
107
108     $(".cartRemove").on("click", function (e) {
109         e.preventDefault();
110         var selection_id = this.id;
111         var biblionumber = selection_id.replace("cartR", "");
112         delSingleRecord(biblionumber);
113         $(".addtocart").html("<i class=\"fa fa-shopping-cart\"></i> " + __("Add to cart"));
114     });
115
116     $("#addtoshelf").click(function(){
117         addToShelf();
118         $(".btn-group").removeClass("open");
119         return false;
120     });
121     $("#export").remove(); // Hide embedded export form if JS menus available
122     $("#deletebiblio").tooltip();
123     $("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled")
124         .on("click",function(e){
125             e.preventDefault();
126             alertNoItems();
127         })
128         .tooltip();
129
130     $(".addtolist").on("click", function (e) {
131         e.preventDefault();
132         var shelfnumber = $(this).data("shelfnumber");
133         if ($(this).hasClass("morelists")) {
134             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber);
135         } else if ($(this).hasClass("newlist")) {
136             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&biblionumber=' + biblionumber);
137         } else {
138             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber=' + shelfnumber + '&confirm=1&biblionumber=' + biblionumber);
139         }
140     });
141
142 });