From f471ed3903e9aedb2db06b634ffded308b23d198 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 15 Apr 2016 14:56:14 -0400 Subject: [PATCH] Bug 16286 - Use validation plugin when adding or editing patron category MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch updates the patron category entry form so that it is validated using the staff client's globally-included form validation plugin. This patch also moves the page's JavaScript into a separate file. To test, apply the patch and go to Administration -> Patron categories. - Create a new category. Try to submit the form with the following fields empty: - Category code - Description - Both enrollment period fields - Category type - Try to enter data in the category code field which contains characters other than letters, numbers, hyphens, or underscores. - Try to enter non-numeric data in the following fields: - Enrollment period in months - Age required - Upper age limit - Enrollment fee - Hold fee - Try to submit the form with both enrollment period fields filled. Followed test plan, works as expected. Signed-off-by: Marc Véron Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- .../intranet-tmpl/prog/en/js/categories.js | 97 +++++++++++++++ .../prog/en/modules/admin/categories.tt | 114 +++--------------- 2 files changed, 112 insertions(+), 99 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/categories.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/categories.js b/koha-tmpl/intranet-tmpl/prog/en/js/categories.js new file mode 100644 index 0000000000..0c3437992f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/js/categories.js @@ -0,0 +1,97 @@ +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(); + if ( $("#enrolmentperiod").val() !== "" && $("#enrolmentperioddate").val() !== "" ) { + return false; + } else { + return true; + } + }, MSG_ONE_ENROLLMENTPERIOD +); + + +$(document).ready(function() { + $("#table_categorie").dataTable($.extend(true, {}, dataTablesDefaults, { + "aoColumnDefs": [{ + "aTargets": [-1, -2], + "bSortable": false, + "bSearchable": false + }, { + "aTargets": [3, 4, 5], + "sType": "natural" + }, ], + "aaSorting": [ + [1, "asc"] + ], + "sPaginationType": "four_button" + })); + + $("#enrolmentperioddate").datepicker({ + minDate: 1 + }); // Require that "until date" be in the future + + if ($("#branches option:selected").length < 1) { + $("#branches option:first").attr("selected", "selected"); + } + + $("#categorycode").on("blur",function(){ + toUC(this); + }); + + $("#category_form").validate({ + rules: { + categorycode: { + required: true, + letters_numbers: true + }, + description: "required", + enrolmentperiod: { + required: function(element){ + return $("#enrolmentperioddate").val() === ""; + }, + number: true, + enrollment_period: true + }, + enrolmentperioddate: { + required: function(element){ + return $("#enrolmentperiod").val() === ""; + }, + enrollment_period: true + }, + dateofbirthrequired: { + number: true + }, + upperagelimit: { + number: true + }, + enrolmentfee: { + number: true + }, + reservefee: { + number: true + }, + category_type: { + required: true + } + }, + messages: { + enrolmentperiod: { + required: MSG_ONE_ENROLLMENTPERIOD + }, + enrolmentperioddate: { + required: MSG_ONE_ENROLLMENTPERIOD + } + } + + }); +}); \ No newline at end of file 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 3ccc41b619..0f426415eb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -9,98 +9,12 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'datatables.inc' %] - + @@ -141,7 +55,7 @@ [% END %] [% IF op == 'add_form' %] -
+ [% IF category %] @@ -159,28 +73,27 @@ [% ELSE %]
  • - + Required
  • [% END %]
  • - + Required
  • - + Enrollment period:
    Choose one
    1. - months + months
    2. - -
      Cannot have "months" and "until date" at the same time
      +
    @@ -307,7 +220,10 @@ [% INCLUDE 'messaging-preference-form.inc' %] [% END %] -
    +
    + + Cancel +
  • [% END %] -- 2.39.5