From 3166a8299ca6b31d7d9e9ab3fa02232c94d1da65 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 12 Nov 2017 19:30:17 -0500 Subject: [PATCH] Lp 1723651: Use HTML5 Date Input Element For Holds in the OPAC We switch from using HTML text input elements to using the new HTML5 date input element in holds forms for the thaw and expire dates. This gives us the advantage of accepting dates in the user's native format and presenting the backend with a date in ISO format. We can also set a minimum date for expiration and thaw, which we do with a new TT2 macro, get_tomorrow_date. This allows us to avoid date validation to check for dates in he past entered. We add a check in opac/parts/place_hold.tt2 for the XUL staff client and allow it to accept dates in the MM/DD/YYYY format because XULRunner doesn't support the HTML5 date input element. The expire and thaw date elements still accept dates in the MM/DD/YYYY format as well as the YYYY-MM-DD format in the event that they degrade to a text input. This is, unfortunately, only half-documented for the XUL staff client user, since we can't really tell from the server if the user's browser supports the HTML5 date input. Signed-off-by: Jason Stephenson --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 25 ++++++++++++------- Open-ILS/src/templates/opac/myopac/holds/edit.tt2 | 28 +++++++++------------- Open-ILS/src/templates/opac/parts/misc_util.tt2 | 6 +++++ Open-ILS/src/templates/opac/parts/place_hold.tt2 | 5 +++- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 8295e12b51..86879600f0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -913,11 +913,15 @@ sub handle_hold_update { $val->{"pickup_lib"} = $self->cgi->param("pickup_lib"); for my $field (qw/expire_time thaw_date/) { - # XXX TODO make this support other date formats, not just - # MM/DD/YYYY. - next unless $self->cgi->param($field) =~ - m:^(\d{2})/(\d{2})/(\d{4})$:; - $val->{$field} = "$3-$1-$2"; + my $param_value = $self->cgi->param($field); + # Check for US date format grandfathered in for XUL. + if ($param_value =~ m:^(\d{2})/(\d{2})/(\d{4})$:) { + $val->{$field} = "$3-$1-$2"; + } elsif ($param_value =~ m:^\d{4}-\d{2}-\d{2}$:) { + # It looks like an ISO date from HTML5 date input. + $val->{$field} = $param_value; + } + # Otherwise, we drop it on the floor. } $val->{holdable_formats} = # no-op for non-MR holds @@ -1037,10 +1041,11 @@ sub load_place_hold { } if ($cgi->param('hold_suspend')) { $ctx->{frozen} = 1; - # TODO: Make this support other date formats, not just mm/dd/yyyy. - # We should use a date input type on the forms once it is supported by Firefox. - # I didn't do that now because it is not available in a general release. - if ($cgi->param('thaw_date') =~ m:^(\d{2})/(\d{2})/(\d{4})$:){ + # We now use a HTML5 date input, but we're leaving this check in place + # just in case. + if ($cgi->param('thaw_date') =~ m:^\d{4}-\d{2}-\d{2}$:) { + $ctx->{thaw_date} = $cgi->param('thaw_date'); + } elsif ($cgi->param('thaw_date') =~ m:^(\d{2})/(\d{2})/(\d{4})$:){ eval { my $dt = DateTime::Format::ISO8601->parse_datetime("$3-$1-$2"); $ctx->{thaw_date} = $dt->ymd; @@ -1048,6 +1053,8 @@ sub load_place_hold { if ($@) { $logger->warn("ignoring invalid thaw_date when placing hold request"); } + } else { + $logger->warn("ignoring invalid thaw_date when placing hold request"); } } diff --git a/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 b/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 index 6b567a65f1..61fb6e5264 100644 --- a/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 +++ b/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 @@ -13,8 +13,10 @@ hold.human_status = PROCESS get_hold_status hold=hold; # Do this up front to avoid verbosity later - expire_time = ahr.expire_time ? date.format(ctx.parse_datetime(ahr.expire_time), DATE_FORMAT) : ''; - thaw_date = ahr.thaw_date ? date.format(ctx.parse_datetime(ahr.thaw_date), DATE_FORMAT) : ''; + # The HTML5 date element needs an ISO string for the value. + expire_time = ahr.expire_time ? date.format(ctx.parse_datetime(ahr.expire_time), '%Y-%m-%d') : ''; + # The HTML5 date element needs an ISO string for the value. + thaw_date = ahr.thaw_date ? date.format(ctx.parse_datetime(ahr.thaw_date), '%Y-%m-%d') : ''; %]

[% l('Edit Hold') %]

@@ -62,15 +64,9 @@ [% l('Cancel unless filled by') %] - - - - [% l('Enter date in MM/DD/YYYY format') %] - + @@ -93,15 +89,13 @@ [% l('If suspended, activate on') %] - - - - [% l('Enter date in MM/DD/YYYY format') %] + [% END %] - + [% IF hold.metarecord_filters.formats.size OR (hold.metarecord_filters.langs.size.defined && hold.metarecord_filters.langs.size > 1); diff --git a/Open-ILS/src/templates/opac/parts/misc_util.tt2 b/Open-ILS/src/templates/opac/parts/misc_util.tt2 index 97cbd1e7c8..0a1b3cb5b7 100644 --- a/Open-ILS/src/templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/templates/opac/parts/misc_util.tt2 @@ -759,4 +759,10 @@ || CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou; END; + # Get an ISO date string for tomorrow's date for use in hold + # suspension date elements. + MACRO get_tomorrow_date BLOCK; + manip = date.manip; + manip.UnixDate('Noon Tomorrow', '%Y-%m-%d'); + END; -%] diff --git a/Open-ILS/src/templates/opac/parts/place_hold.tt2 b/Open-ILS/src/templates/opac/parts/place_hold.tt2 index 76d8d9e11d..b903fe65f7 100644 --- a/Open-ILS/src/templates/opac/parts/place_hold.tt2 +++ b/Open-ILS/src/templates/opac/parts/place_hold.tt2 @@ -249,8 +249,11 @@ function toggleActivationDate() {
- + + [% IF ctx.proto == 'oils' %] [% l('Enter date in MM/DD/YYYY format') %] + [% END %]