From 1b856c681e7c5d86c78f4443fb7aacc4a368ef65 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 5 Dec 2018 21:33:48 +0000 Subject: [PATCH] Bug 13952: (follow-up) template filters, moving js to separate file This patch adds filters to the template file and moves the JS into a separate file. Signed-off-by: Owen Leonard Signed-off-by: Michal Denar Signed-off-by: Michal Denar Signed-off-by: Mazen Khallaf Signed-off-by: Michal Denar Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- .../prog/en/modules/admin/authtypes.tt | 181 +++++------------- koha-tmpl/intranet-tmpl/prog/js/authtype.js | 85 ++++++++ 2 files changed, 136 insertions(+), 130 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/authtype.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tt index f1251a8b53..eff2c33150 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tt @@ -192,61 +192,61 @@ Authority types › Administration › Koha
  • Edit
  • [% IF authority_type.authtypecode %]
  • Delete
  • [% END %] -
  • Export
  • +
  • Export
  • -
  • Import
  • +
  • Import
  • - - + + - - + + [% END %] @@ -267,85 +267,6 @@ Authority types › Administration › Koha [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% Asset.js("js/admin-menu.js") | $raw %] - + [% Asset.js("js/authtype.js") | $raw %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/authtype.js b/koha-tmpl/intranet-tmpl/prog/js/authtype.js new file mode 100644 index 0000000000..b4c95017cc --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/authtype.js @@ -0,0 +1,85 @@ +/* Import/export from/to a spreadsheet */ + +var importing = false; + +$(document).ready(function() { + $("#authtypes").dataTable($.extend(true, {}, dataTablesDefaults, { + "aoColumnDefs": [ + { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }, + { "aTargets": [ 0, 1 ], "sType": "natural" }, + ], + "bSort": true, + "sPaginationType": "full" + })); + + $("body").css("cursor", "auto"); + $('.import_export_options').hide(); + $('a.import_export_fw').click(function() { + if (!importing) { + $('.import_export_options').hide(); + $(this).next().show('slide'); + } + return false; + }); + + $('.import_export_close').click(function() { + if (!importing) { + $('.import_export_options').fadeOut('fast'); + $("body").css("cursor", "auto"); + return false; + } + }); + + $('.input_import').val(""); + + var matches = new RegExp("\\?error_import_export=(.+)$").exec(window.location.search); + if (matches && matches.length > 1) { + alert(_("Error importing the authority type %s").format(decodeURIComponent(matches[1]))); + } + + $('input.input_import').change( function() { + var filename = $(this).val(); + if ( ! /(?:\.csv|\.ods|\.xml)$/.test(filename)) { + $(this).css("background-color","yellow"); + alert(_("Please select a CSV (.csv), ODS (.ods) or XML (.xml) spreadsheet file.")); + $(this).val(""); + $(this).css("background-color","white"); + } + }); + + $('form.form_export').submit(function() { + $('.modal').modal("hide"); + return true; + }); + + $('form.form_import').submit(function() { + var id = $(this).attr('id'); + var obj = $('#' + id + ' input:file'); + if (/(?:\.csv|\.ods|\.xml)$/.test(obj.val())) { + 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"))) { + var authtypecode = $('#' + id + ' input:hidden[name=authtypecode]').val(); + $('#importing_' + authtypecode).find("span").html(_("Importing to authority type: %s. Importing from file: %s").format("" + authtypecode + "", "" + obj.val().replace(new RegExp("^.+[/\\\\]"),"") + "")); + if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) { + var timestamp = new Date().getTime(); + $('#importing_' + authtypecode).find("img").attr('src', '[% interface | html %]/[% theme | html %]/img/loading-small.gif' + '?' +timestamp); + } + $('#importing_' + authtypecode).css('display', 'block'); + if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress"); + importing = true; + $(".modal-footer,.closebtn").hide(); + return true; + } else { + return false; + } + } + obj.css("background-color","yellow"); + alert(_("Please select a CSV (.csv), ODS (.ods) or XML (.xml) spreadsheet file.")); + obj.val(""); + bj.css("background-color","white"); + return false; + }); + $("#authtypecode").on("blur",function(){ + toUC(this); + }); + +}); -- 2.39.5