Bug 21556: Deleting same record twice leads to fatal software error
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / catalog.js
1 /* IF ( CAN_user_editcatalogue_edit_catalogue ) */
2     /* this function open a popup to search on z3950 server.  */
3     function PopupZ3950() {
4         var strQuery = GetZ3950Terms();
5         if(strQuery){
6             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');
7         }
8     }
9     function PopupZ3950Confirmed() {
10         if (confirm( MSG_REPLACE_RECORD )){
11             PopupZ3950();
12         }
13     }
14 /* END IF( CAN_user_editcatalogue_edit_catalogue ) */
15
16 function addToCart() { addRecord( biblionumber ); }
17 function addToShelf() { window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=' + biblionumber,'Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes');
18 }
19 function printBiblio() {window.print(); }
20
21 /* IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
22
23 function confirm_deletion(link) {
24     var order_manage_permission = $(link).data("order-manage");
25     var is_confirmed;
26     if (count > 0){
27         is_confirmed = alert( MSG_DELETE_ALL_ITEMS.format(count) );
28     } else if (countorders > 0){
29         if( order_manage_permission ){
30             is_confirmed = confirm( CONFIRM_RECORD_USED_IN_ORDERS.format(countorders) );
31         } else {
32             is_confirmed = alert( MSG_RECORD_USED_IN_ORDERS.format(countorders) );
33         }
34     } else if (countdeletedorders > 0){
35         if( order_manage_permission ){
36             is_confirmed = confirm( CONFIRM_IN_DELETED_ORDERS.format(countdeletedorders) );
37         } else {
38             is_confirmed = alert( MSG_IN_DELETED_ORDERS.format(countdeletedorders) );
39         }
40     } else if ( holdcount > 0 ) {
41         is_confirmed = confirm( CONFIRM_DELETION_HOLDS.format(holdcount) );
42     } else {
43         is_confirmed = confirm( CONFIRM_RECORD_DELETION );
44     }
45     if (is_confirmed) {
46         $("#deletebiblio").unbind('click');
47         window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=" + biblionumber;
48     } else {
49         return false;
50     }
51 }
52
53 /* END IF CAN_user_editcatalogue_edit_catalogue or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
54
55 /* IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
56
57 function confirm_items_deletion() {
58     if ( holdcount > 0 ) {
59         alert( MSG_DELETE_ALL_HOLDS.format(holdcount) );
60     } else if ( count > 0 ) {
61         if( confirm( CONFIRM_DELETE_ITEMS.format(count) ) ) {
62             window.location="/cgi-bin/koha/cataloguing/additem.pl?op=delallitems&biblionumber=" + biblionumber;
63         } else {
64             return false;
65         }
66     } else {
67         alertNoItems();
68         return false;
69     }
70 }
71
72 function alertNoItems(){
73     alert( MSG_NO_ITEMS );
74 }
75
76 /* END IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) */
77
78 $(document).ready(function() {
79     $("#z3950copy").click(function(){
80         PopupZ3950();
81         return false;
82     });
83     $("#deletebiblio").click(function(){
84         confirm_deletion(this);
85         return false;
86     });
87     $("#deleteallitems").click(function(){
88         confirm_items_deletion();
89         return false;
90     });
91     $("#printbiblio").click(function(){
92         printBiblio();
93         return false;
94     });
95     $("#addtocart").click(function(){
96         addToCart();
97         $(".btn-group").removeClass("open");
98         return false;
99     });
100     $("#addtoshelf").click(function(){
101         addToShelf();
102         $(".btn-group").removeClass("open");
103         return false;
104     });
105     $("#export").remove(); // Hide embedded export form if JS menus available
106     $("#deletebiblio").tooltip();
107     $("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled")
108         .on("click",function(e){
109             e.preventDefault();
110             alertNoItems();
111         })
112         .tooltip();
113  });