1 /* Import/export from/to a spreadsheet */
5 $(document).ready(function() {
6 $("#authtypes").dataTable($.extend(true, {}, dataTablesDefaults, {
8 { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
9 { "aTargets": [ 0, 1 ], "sType": "natural" },
12 "sPaginationType": "full"
15 $("body").css("cursor", "auto");
16 $('.import_export_options').hide();
17 $('a.import_export_fw').click(function() {
19 $('.import_export_options').hide();
20 $(this).next().show('slide');
25 $('.import_export_close').click(function() {
27 $('.import_export_options').fadeOut('fast');
28 $("body").css("cursor", "auto");
33 $('.input_import').val("");
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])));
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."));
46 $(this).css("background-color","white");
50 $('form.form_export').submit(function() {
51 $('.modal').modal("hide");
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);
66 $('#importing_' + authtypecode).css('display', 'block');
67 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress");
69 $(".modal-footer,.closebtn").hide();
75 obj.css("background-color","yellow");
76 alert(__("Please select a CSV (.csv) or ODS (.ods) spreadsheet file."));
78 bj.css("background-color","white");
81 $("#authtypecode").on("blur",function(){