Bug 25251: (follow-up) Remove alertNoItems
[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 if (subscriptionscount > 0){
48         is_confirmed = alert(__("%s subscription(s) are attached to this record. You must delete all subscription before deleting this record.").format(subscriptionscount));
49     } else {
50         is_confirmed = confirm( __("Are you sure you want to delete this record?") );
51     }
52     if (is_confirmed) {
53         $("#deletebiblio").unbind('click');
54         window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=" + biblionumber + (searchid ? "&searchid="+searchid : "");
55     } else {
56         return false;
57     }
58 }
59
60 /* END IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
61
62 /* IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
63
64 function confirm_items_deletion() {
65     if ( holdcount > 0 ) {
66         alert(__("%s hold(s) on this record. You must delete all holds before deleting all items.").format(holdcount));
67     } else if ( count > 0 ) {
68         if (confirm(__("Are you sure you want to delete the %s attached items?").format(count))) {
69             window.location="/cgi-bin/koha/cataloguing/additem.pl?op=delallitems&biblionumber=" + biblionumber + (searchid ? "&searchid="+searchid : "");
70         } else {
71             return false;
72         }
73     } else {
74         return false;
75     }
76 }
77
78 /* END IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
79
80 $(document).ready(function() {
81     $("#z3950copy").click(function(){
82         PopupZ3950();
83         return false;
84     });
85     $("#deletebiblio").click(function(){
86         confirm_deletion(this);
87         return false;
88     });
89     $("#deleteallitems").click(function(){
90         confirm_items_deletion();
91         return false;
92     });
93     $("#printbiblio").click(function(){
94         printBiblio();
95         return false;
96     });
97
98     $(".addtocart").on("click", function (e) {
99         e.preventDefault();
100         var selection_id = this.id;
101         var biblionumber = selection_id.replace("cart", "");
102         addRecord(biblionumber);
103     });
104
105     $(".cartRemove").on("click", function (e) {
106         e.preventDefault();
107         var selection_id = this.id;
108         var biblionumber = selection_id.replace("cartR", "");
109         delSingleRecord(biblionumber);
110         $(".addtocart").html("<i class=\"fa fa-shopping-cart\"></i> " + __("Add to cart"));
111     });
112
113     $("#addtoshelf").click(function(){
114         addToShelf();
115         $(".btn-group").removeClass("open");
116         return false;
117     });
118     $("#export").remove(); // Hide embedded export form if JS menus available
119     $("#deletebiblio").tooltip();
120     $("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled")
121         .on("click",function(e){
122             e.stopPropagation();
123         })
124         .tooltip();
125
126     $(".addtolist").on("click", function (e) {
127         e.preventDefault();
128         var shelfnumber = $(this).data("shelfnumber");
129         if ($(this).hasClass("morelists")) {
130             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber);
131         } else if ($(this).hasClass("newlist")) {
132             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&biblionumber=' + biblionumber);
133         } else {
134             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber=' + shelfnumber + '&confirm=1&biblionumber=' + biblionumber);
135         }
136     });
137
138 });