Bug 28377: (28937 follow-up) Flatpickr change
[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         alertNoItems();
75         return false;
76     }
77 }
78
79 function alertNoItems(){
80     alert( __("This record has no items.") );
81 }
82
83 /* END IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
84
85 $(document).ready(function() {
86     $("#z3950copy").click(function(){
87         PopupZ3950();
88         return false;
89     });
90     $("#deletebiblio").click(function(){
91         confirm_deletion(this);
92         return false;
93     });
94     $("#deleteallitems").click(function(){
95         confirm_items_deletion();
96         return false;
97     });
98     $("#printbiblio").click(function(){
99         printBiblio();
100         return false;
101     });
102
103     $(".addtocart").on("click", function (e) {
104         e.preventDefault();
105         var selection_id = this.id;
106         var biblionumber = selection_id.replace("cart", "");
107         addRecord(biblionumber);
108     });
109
110     $(".cartRemove").on("click", function (e) {
111         e.preventDefault();
112         var selection_id = this.id;
113         var biblionumber = selection_id.replace("cartR", "");
114         delSingleRecord(biblionumber);
115         $(".addtocart").html("<i class=\"fa fa-shopping-cart\"></i> " + __("Add to cart"));
116     });
117
118     $("#addtoshelf").click(function(){
119         addToShelf();
120         $(".btn-group").removeClass("open");
121         return false;
122     });
123     $("#export").remove(); // Hide embedded export form if JS menus available
124     $("#deletebiblio").tooltip();
125     $("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled")
126         .on("click",function(e){
127             e.preventDefault();
128             alertNoItems();
129         })
130         .tooltip();
131
132     $(".addtolist").on("click", function (e) {
133         e.preventDefault();
134         var shelfnumber = $(this).data("shelfnumber");
135         if ($(this).hasClass("morelists")) {
136             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber);
137         } else if ($(this).hasClass("newlist")) {
138             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&biblionumber=' + biblionumber);
139         } else {
140             openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber=' + shelfnumber + '&confirm=1&biblionumber=' + biblionumber);
141         }
142     });
143
144 });