2 /* Import/Export from/to spreadsheet */
6 $(document).ready(function() {
7 $("#table_biblio_frameworks").dataTable($.extend(true, {}, dataTablesDefaults, {
9 { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
10 { "aTargets": [ 0, 1 ], "sType": "natural" },
13 "sPaginationType": "full"
16 $("body").css("cursor", "auto");
17 $('.import_export_options').hide();
18 $('a.import_export_fw').click(function() {
20 $('.import_export_options').hide();
21 $(this).next().show('slide');
25 $('.import_export_close').click(function() {
27 $('.import_export_options').fadeOut('fast');
28 $("body").css("cursor", "auto");
32 $('.input_import').val("");
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])));
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.") );
45 $(this).css("background-color","white");
48 $('form.form_export').submit(function() {
49 $('.modal').modal("hide");
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);
64 $('#importing_' + frameworkcode).css('display', 'block');
65 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress");
67 $(".modal-footer,.closebtn").hide();
72 obj.css("background-color","yellow");
73 alert( __("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.") );
75 obj.css("background-color","white");
78 $("#frameworkcode").on("blur",function(){