Bug 35977: (follow-up) Cleaner working approach

This patch removes the Date_from_syspref recently added and replaces it
with the correct parseDate call as per bug 35559. We also clean up the
code around setting the input value in the first place and use iso which
is what the rest of flatpickr expects and now is handled correctly in
futuredate pickers.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 1ff3d65c70)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2024-04-30 16:13:25 +01:00 committed by Fridolin Somers
parent 87d6a13172
commit 3880307a9f
3 changed files with 2 additions and 25 deletions

View file

@ -136,28 +136,6 @@
} }
} }
function Date_from_syspref(dstring) {
var dateX = dstring.split(/[-/.]/);
if (debug > 1 && sentmsg < 1) {
sentmsg++;
alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));
}
if (dateformat_pref === "iso") {
return new Date(dateX[0], (dateX[1] - 1), dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d)
} else if (dateformat_pref === "us") {
return new Date(dateX[2], (dateX[0] - 1), dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d)
} else if (dateformat_pref === "metric") {
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d)
} else if (dateformat_pref === "dmydot") {
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d)
} else {
if (debug > 0) {
alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
}
return 0;
}
}
$(document).ready(function(){ $(document).ready(function(){
$(".flatpickr").each(function(){ $(".flatpickr").each(function(){
let options = {}; let options = {};
@ -168,7 +146,7 @@
|| $(this).data("flatpickr-futuredate") === true ) { || $(this).data("flatpickr-futuredate") === true ) {
let original_date = $(this).val(); let original_date = $(this).val();
if ( original_date ) { if ( original_date ) {
original_date = Date_from_syspref( original_date ).getTime(); original_date = flatpickr.parseDate(original_date, 'Y-m-d').getTime();
let tomorrow = new Date().fp_incr(1).getTime(); let tomorrow = new Date().fp_incr(1).getTime();
options['enable'] = [function(date){ options['enable'] = [function(date){

View file

@ -287,7 +287,7 @@
[% IF ( reserve_in_future ) %] [% IF ( reserve_in_future ) %]
<li> <li>
<label for="from[% bibitemloo.biblionumber | html %]">Hold starts on date:</label> <label for="from[% bibitemloo.biblionumber | html %]">Hold starts on date:</label>
<input type="text" name="reserve_date_[% bibitemloo.biblionumber | html %]" id="from[% bibitemloo.biblionumber | html %]" data-start_for="to[% bibitemloo.biblionumber | html %]" data-flatpickr-futureinclusive="true" size="10" class="flatpickr holddatefrom" value="[% today | $raw %]" /> <input type="text" name="reserve_date_[% bibitemloo.biblionumber | html %]" id="from[% bibitemloo.biblionumber | html %]" data-start_for="to[% bibitemloo.biblionumber | html %]" data-flatpickr-futureinclusive="true" size="10" class="flatpickr holddatefrom" value="[% KohaDates.datetime_from_string | $KohaDates dateformat => 'iso' %]" />
<span class="date-format from" data-biblionumber="[% bibitemloo.biblionumber | html %]">[% INCLUDE 'date-format.inc' %]</span> <span class="date-format from" data-biblionumber="[% bibitemloo.biblionumber | html %]">[% INCLUDE 'date-format.inc' %]</span>
<div class="required_label" style="display:none;">Required</div> <div class="required_label" style="display:none;">Required</div>
</li> </li>

View file

@ -623,7 +623,6 @@ if ( C4::Context->preference('AllowHoldDateInFuture')
{ {
$template->param( $template->param(
reserve_in_future => 1, reserve_in_future => 1,
today => dt_from_string,
); );
} }