From edf6056418daa15a620eb70a493ebaa061c802d0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Apr 2015 15:36:34 +0200 Subject: [PATCH] Bug 14060: Remove readonly attributes on date inputs In order to remove accessibility issues due to the readonly attributes on date inputs, this patch will remove them and introduce a javascript validation on them. This patch is not perfect for some reason: I didn't manage to force the user to select a valid date. One solution would be to reopen the datepicker plugin until a valid date is inserted. But it could be annoying for users (and for me: I did not manage to implement this solution). You will note that input is emptied if the date is not valid. This is a quick and efficient solution to prevent submitting invalid date and make Koha explodes. A proper solution would be to implement the check server side send a friendly message to the user. Test plan: For all inputs, try an invalid and a valid date. 1/ Debar a patron 2/ On the checkout tables (circulation and moremember), add a renewal due date (at the bottom of the tables) 3/ On the checkout page, specify a due date 4/ On the return page, specify a return date 5/ On the invoice page (acquisition module), enter a shipment and billing date 6/ On the invoice search page (invoices.pl) use filters shipment and billing dates 7/ On the offline circ page, specify a due date 8/ On the edit patron page (memberentry), add a debarment 9/ On the reserve page (reserve/request.pl), use the date inputs to suspend until a defined date 10/ Edit patrons in a batch (tools/modborrowers.pl) and use the registration and expiry date inputs --- .../prog/en/includes/borrower_debarments.inc | 2 +- .../intranet-tmpl/prog/en/includes/calendar.inc | 29 ++++++++++++++++++++-- .../prog/en/includes/checkouts-table-footer.inc | 2 +- .../intranet-tmpl/prog/en/js/pages/circulation.js | 9 ++++++- .../intranet-tmpl/prog/en/modules/acqui/invoice.tt | 4 +-- .../prog/en/modules/acqui/invoices.tt | 4 +-- .../prog/en/modules/circ/circulation.tt | 14 +++++++---- .../intranet-tmpl/prog/en/modules/circ/offline.tt | 8 ++++-- .../intranet-tmpl/prog/en/modules/circ/returns.tt | 6 ++++- .../prog/en/modules/members/memberentrygen.tt | 2 +- .../prog/en/modules/members/moremember.tt | 5 ---- .../prog/en/modules/reserve/request.tt | 6 ++--- .../prog/en/modules/tools/modborrowers.tt | 5 ++-- 13 files changed, 68 insertions(+), 28 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc index aea0889..2a90666 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc @@ -74,7 +74,7 @@ Add manual restriction
  1. -
  2. +
  3. Clear date
Cancel
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 9fd0ea5..31944d5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -6,6 +6,24 @@ var debug = "[% debug %]"; var dformat = "[% dateformat %]"; var sentmsg = 0; if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");} +var MSG_PLEASE_ENTER_A_VALID_DATE = ("Please enter a valid date."); + +function validate_date (dateText, inst) { + var dateformat = '[% Koha.Preference('dateformat') %]'; + if ( dateformat == 'us' ) { + dateformat = 'mm/dd/yy'; + } else if ( dateformat == 'metric' ) { + dateformat = 'dd/mm/yy'; + } else if (dateformat == 'iso' ) { + dateformat = 'yy-mm-dd'; + } + try { + $.datepicker.parseDate(dateformat, dateText); + } catch (e) { + alert(MSG_PLEASE_ENTER_A_VALID_DATE); + $('#'+inst.id).val(''); + }; +} function Date_from_syspref(dstring) { var dateX = dstring.split(/[-/]/); @@ -87,7 +105,11 @@ $.datepicker.setDefaults({ selectOtherMonths: true }); - $( ".datepicker" ).datepicker(); + $( ".datepicker" ).datepicker({ + onClose: function(dateText, inst) { + validate_date(dateText, inst); + }, + }); // http://jqueryui.com/demos/datepicker/#date-range var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({ changeMonth: true, @@ -100,7 +122,10 @@ $.datepicker.setDefaults({ $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); - } + }, + onClose: function(dateText, inst) { + validate_date(dateText, inst); + }, }); }); //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc index 0de211f..0192ba1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc @@ -5,7 +5,7 @@ [% finetotal %] [% totalprice %]
-

+

diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/pages/circulation.js b/koha-tmpl/intranet-tmpl/prog/en/js/pages/circulation.js index cea3e88..258dfda 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/pages/circulation.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/pages/circulation.js @@ -31,12 +31,19 @@ $(document).ready(function() { }); $("#newduedate").datetimepicker({ + onClose: function(dateText, inst) { + validate_date(dateText, inst); + }, minDate: 1, // require that renewal date is after today hour: 23, minute: 59 }); $("#duedatespec").datetimepicker({ - onClose: function(dateText, inst) { $("#barcode").focus(); }, + onClose: function(dateText, inst) { + if ( validate_date(dateText, inst) ) { + $("#barcode").focus(); + } + }, hour: 23, minute: 59 }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt index 6a0c9cf..602a4cf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -74,10 +74,10 @@
  1. -
  2. +
  3. -
  4. +
  5. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt index 167591b..0274a30 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt @@ -180,10 +180,10 @@ $(document).ready(function() {
  6. -
  7. +
  8. -
  9. +
  10. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 07ef6ce..ebaeb3c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -68,7 +68,11 @@ function toggle_onsite_checkout(){ [% END %] } else { $("#duedatespec").datetimepicker({ - onClose: function(dateText, inst) { $("#barcode").focus(); }, + onClose: function(dateText, inst) { + if (validate_date(dateText, inst) ) { + $("#barcode").focus(); + } + }, hour: 23, minute: 59 }); @@ -347,7 +351,7 @@ $(document).ready(function() { [% IF ( DEBT ) %][% END %] [% IF ( INVALID_DATE ) %]

    - +

    [% ELSE %] @@ -636,9 +640,9 @@ No patron matched [% message %]
    Specify due date [% INCLUDE 'date-format.inc' %]:
    [% IF ( duedatespec ) %] - + [% ELSE %] - + [% END %] [% IF ( stickyduedate ) %] @@ -656,7 +660,7 @@ No patron matched [% message %] [% IF noissues %]
    - +
    [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/offline.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/offline.tt index 3fa54b7..0e66baf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/offline.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/offline.tt @@ -553,7 +553,11 @@ $(document).ready(function () { minute: 59 }); $("#duedatespec").datetimepicker({ - onClose: function(dateText, inst) { setTimeout(function() { $('#checkout-barcode').trigger('focus'), 1 }); }, + onClose: function(dateText, inst) { + if (validate_date(dateText, inst) ) { + setTimeout(function() { $('#checkout-barcode').trigger('focus'), 1 }); + } + }, hour: 23, minute: 59 }); @@ -690,7 +694,7 @@ $(document).ready(function () {
    Specify due date [% INCLUDE 'date-format.inc' %]:
    - + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index ca23a94..9d97fa0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -25,7 +25,11 @@ $(document).ready(function () { [% END %] $("#return_date_override").datetimepicker({ - onClose: function(dateText, inst) { $("#barcode").focus(); }, + onClose: function(dateText, inst) { + if (validate_date(dateText, inst) ) { + $("#barcode").focus(); }, + } + }, defaultDate: -1, hour: 23, minute: 59, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index a3b7a9d..88ab3e1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -979,7 +979,7 @@ Add manual restriction
    1. -
    2. +
    3. Clear date
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 97e547d..6f5ff72 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -83,11 +83,6 @@ $(document).ready(function() { });[% END %] $("#suspend_until").datepicker({ minDate: 1 }); // require that hold suspended until date is after today - $("#newduedate").datetimepicker({ - minDate: 1, // require that renewal date is after today - hour: 23, - minute: 59 - }); }); function uncheck_sibling(me){ nodename=me.getAttribute("name"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index bf85bf6..0bb0532 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -412,14 +412,14 @@ function checkMultiHold() { [% IF ( reserve_in_future ) %]
  11. - + Clear date
  12. [% END %]
  13. - + Clear date
  14. @@ -822,7 +822,7 @@ function checkMultiHold() { [% IF AutoResumeSuspendedHolds %] - + Clear date [% END %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt index 65ce440..4147fec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% USE KohaDates %] [% INCLUDE 'doc-head-open.inc'%] Koha › Tools › Batch patron modification @@ -318,7 +319,7 @@ [% END %] [% IF field.mandatory %] - + [% ELSE %] [% END %] @@ -337,7 +338,7 @@ [% END %] [% END %] [% IF ( field.type == 'date' ) %] - + Clear [% END %] [% IF field.mandatory %] -- 2.1.0