Bug 9565: (follow-up) Deleting a biblio should alert/fail if there are existent subsc...
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / biblio_framework.js
1 /* global __ */
2 /* Import/Export from/to spreadsheet */
3
4     var importing = false;
5
6     $(document).ready(function() {
7         $("#table_biblio_frameworks").dataTable($.extend(true, {}, dataTablesDefaults, {
8             "aoColumnDefs": [
9                 { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
10                 { "aTargets": [ 0, 1 ], "sType": "natural" },
11             ],
12             "bSort": true,
13             "sPaginationType": "full"
14         }));
15
16         $("body").css("cursor", "auto");
17         $('.import_export_options').hide();
18         $('a.import_export_fw').click(function() {
19             if (!importing) {
20                 $('.import_export_options').hide();
21                 $(this).next().show('slide');
22             }
23             return false;
24         });
25         $('.import_export_close').click(function() {
26             if (!importing) {
27                 $('.import_export_options').fadeOut('fast');
28                 $("body").css("cursor", "auto");
29                 return false;
30             }
31         });
32         $('.input_import').val("");
33
34         var matches = new RegExp("\\?error_import_export=(.+)$").exec(window.location.search);
35         if (matches && matches.length > 1) {
36             alert( __("Error importing the framework") + " %s".format(decodeURIComponent(matches[1])));
37         }
38
39         $('input.input_import').change( function() {
40             var filename = $(this).val();
41             if ( ! /(?:\.csv|\.ods|\.xml)$/.test(filename)) {
42                 $(this).css("background-color","yellow");
43                 alert( __("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.") );
44                 $(this).val("");
45                 $(this).css("background-color","white");
46             }
47         });
48         $('form.form_export').submit(function() {
49             $('.modal').modal("hide");
50             return true;
51         });
52         $('form.form_import').submit(function() {
53             var id = $(this).attr('id');
54             var obj = $('#' + id + ' input:file');
55             if (/(?:\.csv|\.ods|\.xml)$/.test(obj.val())) {
56                 var frameworkcode = $('#' + id + ' input:hidden[name=frameworkcode]').val();
57                 var MSG_OVERWRITE_WARNING = __("Are you sure you want to replace the fields and subfields for the %s framework structure? The existing structure will be overwritten! For safety reasons, it is recommended to use the export option to make a backup first.").format( frameworkcode );
58                 if (confirm( MSG_OVERWRITE_WARNING )) {
59                     $('#importing_' + frameworkcode).find("span").html( __("Importing to framework: %s. Importing from file: %s.").format("<strong>" + frameworkcode + "</strong>", "<i>" + obj.val().replace(new RegExp("^.+[/\\\\]"), "") + "</i>"));
60                     if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
61                         var timestamp = new Date().getTime();
62                         $('#importing_' + frameworkcode).find("img").attr('src', template_path + '/img/spinner-small.gif' + '?' +timestamp);
63                     }
64                     $('#importing_' + frameworkcode).css('display', 'block');
65                     if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress");
66                     importing = true;
67                     $(".modal-footer,.closebtn").hide();
68                     return true;
69                 } else
70                     return false;
71             }
72             obj.css("background-color","yellow");
73             alert( __("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.") );
74             obj.val("");
75             obj.css("background-color","white");
76             return false;
77         });
78         $("#frameworkcode").on("blur",function(){
79             toUC(this);
80         });
81     });