Bug 26441: Move translatable strings out of catalog-strings.inc into catalog.js
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / catalog.js
1 /* global __ biblionumber count holdcount countorders countdeletedorders searchid addRecord */
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() { addRecord( biblionumber ); }
19 function addToShelf() { window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber,'Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes');
20 }
21 function printBiblio() {window.print(); }
22
23 /* IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
24
25 function confirm_deletion(link) {
26     var order_manage_permission = $(link).data("order-manage");
27     var is_confirmed;
28     if (count > 0){
29         is_confirmed = alert(__("%s item(s) are attached to this record. You must delete all items before deleting this record.").format(count));
30     } else if (countorders > 0){
31         if( order_manage_permission ){
32             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));
33         } else {
34             is_confirmed = alert(__("%s order(s) are using this record. You need order managing permissions to delete this record.").format(countorders));
35         }
36     } else if (countdeletedorders > 0){
37         if( order_manage_permission ){
38             is_confirmed = confirm(__("%s deleted order(s) are using this record. Are you sure you want to delete this record?").format(countdeletedorders));
39         } else {
40             is_confirmed = alert(__("%s deleted order(s) are using this record. You need order managing permissions to delete this record.").format(countdeletedorders));
41         }
42     } else if ( holdcount > 0 ) {
43         is_confirmed = confirm( __("%s holds(s) for this record. Are you sure you want to delete this record?").format(holdcount));
44     } else {
45         is_confirmed = confirm( __("Are you sure you want to delete this record?") );
46     }
47     if (is_confirmed) {
48         $("#deletebiblio").unbind('click');
49         window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=" + biblionumber + (searchid ? "&searchid="+searchid : "");
50     } else {
51         return false;
52     }
53 }
54
55 /* END IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
56
57 /* IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
58
59 function confirm_items_deletion() {
60     if ( holdcount > 0 ) {
61         alert(__("%s hold(s) on this record. You must delete all holds before deleting all items.").format(holdcount));
62     } else if ( count > 0 ) {
63         if (confirm(__("Are you sure you want to delete the %s attached items?").format(count))) {
64             window.location="/cgi-bin/koha/cataloguing/additem.pl?op=delallitems&biblionumber=" + biblionumber + (searchid ? "&searchid="+searchid : "");
65         } else {
66             return false;
67         }
68     } else {
69         alertNoItems();
70         return false;
71     }
72 }
73
74 function alertNoItems(){
75     alert( __("This record has no items.") );
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     $("#addtocart").click(function(){
98         addToCart();
99         $(".btn-group").removeClass("open");
100         return false;
101     });
102     $("#addtoshelf").click(function(){
103         addToShelf();
104         $(".btn-group").removeClass("open");
105         return false;
106     });
107     $("#export").remove(); // Hide embedded export form if JS menus available
108     $("#deletebiblio").tooltip();
109     $("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled")
110         .on("click",function(e){
111             e.preventDefault();
112             alertNoItems();
113         })
114         .tooltip();
115 });