2
0
forked from Wavyzz/dolibarr

work on date edit event (#31112)

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Mohamed DAOUD
2024-09-26 22:46:50 +02:00
committed by GitHub
parent fdb885f0a3
commit 797957dfd3

View File

@@ -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");