3 # Converted to new plugin style (Bug 13437)
5 # Copyright 2000-2002 Katipo Communications
6 # Parts copyright Athens County Public Libraries 2019
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use Koha::DateUtils qw( dt_from_string output_pref );
28 my $function_name = $params->{id};
30 my $date = output_pref({ dt => dt_from_string, dateonly => 1 });
32 my $dateformat_pref = C4::Context->preference('dateformat');
34 $dateformat_pref eq 'us' ? 'm/d/Y'
35 : $dateformat_pref eq 'metric' ? 'd/m/Y'
36 : $dateformat_pref eq 'dmydot' ? 'd.m.Y'
39 my $res = <<END_OF_JS;
41 /* from: cataloguing/value_builder/dateaccessioned.pl */
43 \$(document).ready(function(){
44 \$("#$function_name").flatpickr({
46 altFormat: "$dateformat",
47 altInputClass: "input_marceditor flatpickr-input",
50 /* Set current date on page load */
51 set_to_today($function_name.id);
54 function Focus$function_name(event) {
55 set_to_today(event.data.id);
58 function Click$function_name(event) {
59 event.preventDefault();
60 set_to_today(event.data.id, 1);
63 function set_to_today( id, force ) {
64 /* The force parameter is used in Click but not in Focus ! */
65 if (! id) { alert(_("Bad id ") + id + _(" sent to set_to_today()")); return 0; }
66 var elt = document.querySelector("#" + id);
67 if ( elt.value == '' || force ) {
68 const fp = document.querySelector("#" + id)._flatpickr;
69 fp.setDate(new Date());
77 return { builder => $builder };