From 7c64a088665869172bdd313ab6db0acdf35495d3 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 9 Nov 2017 15:08:38 +0000 Subject: [PATCH] Bug 19560: Unable to delete library when branchcode contains special characters This patch modifies the library administration page so that the library delete button submits a form using POST rather than linking to the delete operation with GET variables. This patch also adds validation to the library entry form so that it will only accept letters, numbers, hyphen, and underscore. The validation method for this already existed in categories.js, so it has been moved to staff-global.js and the validator warning message has been moved to validator-strings.inc so it is included globally. To test: - Add a library with a branchcode containing characters like & or #. - Apply the patch and clear your browser cache if necessary. - Try to delete the new library. It should delete successfully. - Add a library again and try to include spaces and/or special characters in the branchcode. The form validation script should prevent you from submitting the form. - Go do Administration -> Patron categories and add a new patron category. The category code field should prevent you from entering a code with spaces or special characters. --- .../prog/en/includes/validator-strings.inc | 3 +- koha-tmpl/intranet-tmpl/prog/en/js/categories.js | 10 ------- .../prog/en/modules/admin/branches.tt | 34 +++++++++++++--------- .../prog/en/modules/admin/categories.tt | 1 - koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 8 +++++ 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc index 2ca4430..b09440a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc @@ -16,7 +16,8 @@ $(document).ready(function(){ rangelength: $.validator.format(_("Please enter a value between {0} and {1} characters long.")), range: $.validator.format(_("Please enter a value between {0} and {1}.")), max: $.validator.format(_("Please enter a value less than or equal to {0}.")), - min: $.validator.format(_("Please enter a value greater than or equal to {0}.")) + min: $.validator.format(_("Please enter a value greater than or equal to {0}.")), + letters_numbers: $.validator.format(_("This field can only contain the following characters: letters, numbers, hyphen, and underscore.")) }); }); //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/categories.js b/koha-tmpl/intranet-tmpl/prog/en/js/categories.js index 0746ec7..f69b011 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/categories.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/categories.js @@ -1,13 +1,3 @@ -jQuery.validator.addMethod( "letters_numbers", function(value,element){ - var patt = /^[a-zA-Z0-9\-_]+$/g; - if (patt.test(element.value)) { - return true; - } else { - return false; - } - }, MSG_CATEGORYCODE_CHARS -); - jQuery.validator.addMethod( "enrollment_period", function(){ enrolmentperiod = $("#enrolmentperiod").val(); enrolmentperioddate = $("#enrolmentperioddate").val(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt index 586091e..cb81850 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -25,17 +25,15 @@ "sPaginationType": "four_button" })); - [% UNLESS library %] - $("#Aform").on("submit", function( event ) { - if ( $("#branchcode").val().match(/\s/) ) { - event.preventDefault(); - alert(_("The library code entered contains whitespace characters. Please remove any whitespace characters from the library code")); - return false; - } else { - return true; - } - }); - [% END %] + $("#library_entry").validate({ + rules: { + branchcode: { + required: true, + letters_numbers: true + }, + branchname: "required" + } + }); }); tinyMCE.init({ mode : "textareas", @@ -132,7 +130,7 @@ tinyMCE.init({ [% IF op == 'add_form' %]

[% IF library %]Modify library[% ELSE %]New library[% END %]

-
+
[% IF library %] @@ -271,7 +269,11 @@ tinyMCE.init({ [% library.branchip %] Edit - Delete + + + + + [% END %] @@ -302,7 +304,11 @@ tinyMCE.init({ [% category.codedescription |html %] Edit - Delete +
+ + + +
[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt index 9d8d65b..eb6be8d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -10,7 +10,6 @@ [% INCLUDE 'datatables.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index cd586da..ba6aaba 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -15,6 +15,14 @@ function formatstr(str, col) { }); } +jQuery.validator.addMethod( "letters_numbers", function(value,element){ + var patt = /^[a-zA-Z0-9\-_]+$/g; + if (patt.test(element.value)) { + return true; + } else { + return false; + } +}); // http://stackoverflow.com/questions/14859281/select-tab-by-name-in-jquery-ui-1-10-0/16550804#16550804 $.fn.tabIndex = function () { -- 2.1.4