Bug 30717: Format dates when editing items

This is a result of bug 29369 and bug 27526.
Bug 29369 removed the format of the dates, and bug 27526 assumed that it
was the correct behaviour.

Here we don't want to let the controller know which fields is a date, or
we will have to access the subfield structure to know which subfields
have the "date cataloguing plugin".

This patch suggests to use the altFormat options from flatpickr that
will "Show the user a readable date (as per altFormat), but return
something totally different to the server."

It's actually an option we want to use for all our dates, that will
reduce a lot the overhead in our controllers.

Test plan:
Edit items (additem.pl and in batch) and confirm that the subfields
using the dateaccessioned plugin are displayed according to the
dateformat syspref. Make sure the date is stored correctly.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2022-05-09 10:28:51 +02:00 committed by Fridolin Somers
parent 656e864e6b
commit a3870cc25b

View file

@ -27,7 +27,14 @@ my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
my $date = output_pref({ dt => dt_from_string, dateonly => 1 });
my $dateformat_pref = C4::Context->preference('dateformat');
my $dateformat =
$dateformat_pref eq 'us' ? 'm/d/Y'
: $dateformat_pref eq 'metric' ? 'd/m/Y'
: $dateformat_pref eq 'dmydot' ? 'd.m.Y'
: 'Y-m-d';
my $res = <<END_OF_JS;
<script>
@ -35,6 +42,9 @@ my $builder = sub {
\$(document).ready(function(){
\$("#$function_name").flatpickr({
altInput: true,
altFormat: "$dateformat",
altInputClass: "input_marceditor flatpickr-input",
dateFormat: "Y-m-d"
});
/* Set current date on page load */
@ -53,8 +63,10 @@ function Click$function_name(event) {
function set_to_today( id, force ) {
/* The force parameter is used in Click but not in Focus ! */
if (! id) { alert(_("Bad id ") + id + _(" sent to set_to_today()")); return 0; }
if (\$("#" + id).val() == '' || force ) {
\$("#" + id).val("$date");
var elt = document.querySelector("#" + id);
if ( elt.value == '' || force ) {
const fp = document.querySelector("#" + id)._flatpickr;
fp.setDate(new Date());
}
}
</script>