From 65f9e7f172b2b0c6a56c43e5d9d617f8a4c59ef7 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Sun, 15 Dec 2024 15:38:38 +0100 Subject: [PATCH 1/3] Fix parsing input date for eldy calendar when using short year --- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/js/lib_head.js.php | 75 +++++++++++++++++---------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e820a5ddc21..a291083bf62 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -7271,7 +7271,7 @@ class Form // Input area to enter date manually $retstring .= 'trans("FormatDateShortJavaInput") . '\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript + $retstring .= ' onChange="dpChangeDay(\'' . dol_escape_js($prefix) . '\',\'' . dol_escape_js($langs->trans("FormatDateShortJavaInput")) . '\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript $retstring .= ' autocomplete="off">'; // Icon calendar diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 6f2fe0b3657..44cb68bd697 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -222,37 +222,59 @@ function getObjectFromID(id){ return theObject; } -// Called after selection of a date to save details into detailed fields +// Called after the selection or typing of a date to save details into detailed fields function dpChangeDay(dateFieldID, format) { //showDP.datefieldID=dateFieldID; console.log("Call dpChangeDay, we save date into detailed fields from format = "+format); - var thefield=getObjectFromID(dateFieldID); - var thefieldday=getObjectFromID(dateFieldID+"day"); - var thefieldmonth=getObjectFromID(dateFieldID+"month"); - var thefieldyear=getObjectFromID(dateFieldID+"year"); + var thefield = getObjectFromID(dateFieldID); + var thefieldday = getObjectFromID(dateFieldID+"day"); + var thefieldmonth = getObjectFromID(dateFieldID+"month"); + var thefieldyear = getObjectFromID(dateFieldID+"year"); - var date=getDateFromFormat(thefield.value, format); + var date = getDateFromFormat(thefield.value, format); //console.log(date); if (date) { - thefieldday.value=date.getDate(); - if(thefieldday.onchange) thefieldday.onchange.call(thefieldday); - thefieldmonth.value=date.getMonth()+1; - if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); - thefieldyear.value=date.getFullYear(); - if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + thefieldday.value = date.getDate(); + if (thefieldday.onchange) thefieldday.onchange.call(thefieldday); + thefieldmonth.value = date.getMonth()+1; + if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); + thefieldyear.value = date.getFullYear(); + if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + + return 1; } - else - { - thefieldday.value=''; - if(thefieldday.onchange) thefieldday.onchange.call(thefieldday); - thefieldmonth.value=''; - if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); - thefieldyear.value=''; - if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + + // Replace yyyy into yy + newformat = format.replace(/yyyy/g, 'yy'); + if (newformat != format) { + console.log("dpChangeDay, we try now from format = "+newformat); + + var date = getDateFromFormat(thefield.value, newformat); + //console.log(date); + if (date) + { + thefieldday.value = date.getDate(); + if (thefieldday.onchange) thefieldday.onchange.call(thefieldday); + thefieldmonth.value = date.getMonth()+1; + if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); + thefieldyear.value = date.getFullYear(); + if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + + return 2; + } } + + thefieldday.value = ''; + if (thefieldday.onchange) thefieldday.onchange.call(thefieldday); + thefieldmonth.value = ''; + if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); + thefieldyear.value = ''; + if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + + return 0; } /* @@ -337,13 +359,13 @@ function formatDate(date,format) * Licence: GPL * ================================================================== */ -function getDateFromFormat(val,format) +function getDateFromFormat(val, format) { // alert('getDateFromFormat val='+val+' format='+format); // Force parameters en chaine - val=val+""; - format=format+""; + val = val+""; + format = format+""; if (val == '') return 0; @@ -356,17 +378,14 @@ function getDateFromFormat(val,format) var seconde=now.getSeconds(); var i=0; - var d=0; // -d- follows the date string while -i- follows the format - // string + var d=0; // -d- follows the date string while -i- follows the format string while (i < format.length) { c=format.charAt(i); // Recupere char du format substr=""; j=i; - while ((format.charAt(j)==c) && (j < format.length)) // Recupere char - // successif - // identiques + while ((format.charAt(j)==c) && (j < format.length)) // Get successive similar characters { substr += format.charAt(j++); } From 81f0bb892171f46209979e662faa3aa35c65e9b8 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Sun, 15 Dec 2024 17:47:08 +0100 Subject: [PATCH 2/3] Debug v21 --- htdocs/compta/bank/bankentries_list.php | 14 +++++++++----- htdocs/compta/bank/line.php | 4 ++-- htdocs/compta/bank/releve.php | 5 ++--- htdocs/core/ajax/bankconciliate.php | 10 ++++++---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 057ef86ec08..b7e00c3259c 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -900,7 +900,7 @@ if ($resql) { } // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page - $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?token='.currentToken(); + $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?format=dayreduceformat&token='.currentToken(); print '