From 797957dfd3fa13e738efe583aa0815ed184524e1 Mon Sep 17 00:00:00 2001 From: Mohamed DAOUD Date: Thu, 26 Sep 2024 22:46:50 +0200 Subject: [PATCH] work on date edit event (#31112) Co-authored-by: Laurent Destailleur --- htdocs/comm/action/card.php | 47 ++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 5fffaba8636..cf7f82f83d2 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1227,7 +1227,29 @@ if ($action == 'create') { console.log("setdatefields"); setdatefields(); }); - + var old_startdate = null; + $("#ap").focus(function() { + old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val()); + }); + $("#ap").next(".ui-datepicker-trigger").click(function() { + old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val()); + }); + $("#ap").change(function() { + setTimeout(function() { + if ($("#p2").val() !== "") { + var new_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val()); + var old_enddate = new Date($("#p2year").val(), $("#p2month").val() - 1, $("#p2day").val()); + if (new_startdate > old_enddate) { + var timeDiff = old_enddate - old_startdate; + var new_enddate = new Date(new_startdate.getTime() + timeDiff); + $("#p2").val(formatDate(new_enddate, "' . $langs->trans('FormatDateShortJavaInput') . '")); + $("#p2day").val(new_enddate.getDate()); + $("#p2month").val(new_enddate.getMonth() + 1); + $("#p2year").val(new_enddate.getFullYear()); + } + } + }, 0); + }); $("#actioncode").change(function() { if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired"); else $("#dateend").removeClass("fieldrequired"); @@ -1819,6 +1841,29 @@ if ($id > 0) { $("#fullday").change(function() { setdatefields(); }); + var old_startdate = null; + $("#ap").focus(function() { + old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val()); + }); + $("#ap").next(".ui-datepicker-trigger").click(function() { + old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val()); + }); + $("#ap").change(function() { + setTimeout(function() { + if ($("#p2").val() !== "") { + var new_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val()); + var old_enddate = new Date($("#p2year").val(), $("#p2month").val() - 1, $("#p2day").val()); + if (new_startdate > old_enddate) { + var timeDiff = old_enddate - old_startdate; + var new_enddate = new Date(new_startdate.getTime() + timeDiff); + $("#p2").val(formatDate(new_enddate, "' . $langs->trans('FormatDateShortJavaInput') . '")); + $("#p2day").val(new_enddate.getDate()); + $("#p2month").val(new_enddate.getMonth() + 1); + $("#p2year").val(new_enddate.getFullYear()); + } + } + }, 0); + }); $("#actioncode").change(function() { if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired"); else $("#dateend").removeClass("fieldrequired");