Bug 32030: Unique - Prevent same relationships for agreements
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / authtype.js
1 /* Import/export from/to a spreadsheet */
2
3 var importing = false;
4
5 $(document).ready(function() {
6     $("#authtypes").dataTable($.extend(true, {}, dataTablesDefaults, {
7         "aoColumnDefs": [
8             { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
9             { "aTargets": [ 0, 1 ], "sType": "natural" },
10         ],
11         "bSort": true,
12         "sPaginationType": "full"
13     }));
14
15     $("body").css("cursor", "auto");
16     $('.import_export_options').hide();
17     $('a.import_export_fw').click(function() {
18         if (!importing) {
19             $('.import_export_options').hide();
20             $(this).next().show('slide');
21         }
22         return false;
23     });
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
33     $('.input_import').val("");
34
35     var matches = new RegExp("\\?error_import_export=(.+)$").exec(window.location.search);
36     if (matches && matches.length > 1) {
37         alert(__("Error importing the authority type %s").format(decodeURIComponent(matches[1])));
38     }
39
40     $('input.input_import').change( function() {
41         var filename = $(this).val();
42         if ( ! /(?:\.csv|\.ods)$/.test(filename)) {
43             $(this).css("background-color","yellow");
44             alert(_("Please select a CSV (.csv) or ODS (.ods) spreadsheet file."));
45             $(this).val("");
46             $(this).css("background-color","white");
47         }
48     });
49
50     $('form.form_export').submit(function() {
51         $('.modal').modal("hide");
52         return true;
53     });
54
55     $('form.form_import').submit(function() {
56         var id = $(this).attr('id');
57         var obj = $('#' + id + ' input:file');
58         if (/(?:\.csv|\.ods)$/.test(obj.val())) {
59             if (confirm(_("Do you really want to import the authority type fields and subfields? This will overwrite the current configuration. For safety reasons please use the export option to make a backup"))) {
60                 var authtypecode = $('#' + id + ' input:hidden[name=authtypecode]').val();
61                 $('#importing_' + authtypecode).find("span").html(_("Importing to authority type: %s. Importing from file: %s").format("<strong>" + authtypecode + "</strong>", "<i>" + obj.val().replace(new RegExp("^.+[/\\\\]"),"") + "</i>"));
62                 if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
63                     var timestamp = new Date().getTime();
64                     $('#importing_' + authtypecode).find("img").attr('src', '[% interface | html %]/[% theme | html %]/img/loading-small.gif' + '?' +timestamp);
65                 }
66                 $('#importing_' + authtypecode).css('display', 'block');
67                 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress");
68                 importing = true;
69                 $(".modal-footer,.closebtn").hide();
70                 return true;
71             } else {
72                 return false;
73             }
74         }
75         obj.css("background-color","yellow");
76         alert(_("Please select a CSV (.csv) or ODS (.ods) spreadsheet file."));
77         obj.val("");
78         bj.css("background-color","white");
79         return false;
80     });
81     $("#authtypecode").on("blur",function(){
82         toUC(this);
83     });
84
85 });