Enhance autofill of end date when creating an event

This commit is contained in:
Laurent Destailleur 2020-08-29 06:05:52 +02:00
parent b721930b3b
commit bca9a84710
2 changed files with 27 additions and 10 deletions

View File

@ -839,7 +839,6 @@ if ($action == 'create')
$("#p2").removeAttr("disabled");
}
}
setdatefields();
$("#fullday").change(function() {
console.log("setdatefields");
setdatefields();
@ -853,11 +852,25 @@ if ($action == 'create')
{
$("#doneby").val(-1);
}
});
$("#actioncode").change(function() {
});
$("#actioncode").change(function() {
if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
else $("#dateend").removeClass("fieldrequired");
});
});
$("#aphour,#apmin").change(function() {
if ($("#actioncode").val() == \'AC_RDV\') {
console.log("Start date was changed, we modify end date "+(parseInt($("#aphour").val()))+" "+$("#apmin").val()+" -> "+("00" + (parseInt($("#aphour").val()) + 1)).substr(-2,2));
$("#p2hour").val(("00" + (parseInt($("#aphour").val()) + 1)).substr(-2,2));
$("#p2min").val($("#apmin").val());
$("#p2day").val($("#apday").val());
$("#p2month").val($("#apmonth").val());
$("#p2year").val($("#apyear").val());
$("#p2").val($("#ap").val());
}
});
if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
else $("#dateend").removeClass("fieldrequired");
setdatefields();
})';
print '</script>'."\n";
}
@ -880,8 +893,8 @@ if ($action == 'create')
if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
{
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Type").'</span></b></td><td>';
$default = (empty($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT) ? '' : $conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT);
$formactions->select_type_actions(GETPOST("actioncode", 'aZ09') ?GETPOST("actioncode", 'aZ09') : ($object->type_code ? $object->type_code : $default), "actioncode", "systemauto", 0, -1);
$default = (empty($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT) ? 'AC_RDV' : $conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT);
$formactions->select_type_actions(GETPOSTISSET("actioncode") ? GETPOST("actioncode", 'aZ09') : ($object->type_code ? $object->type_code : $default), "actioncode", "systemauto", 0, -1);
print '</td></tr>';
}
@ -1204,15 +1217,15 @@ if ($action == 'create')
$(".reminderparameters").hide();
}
});
$("#selectremindertype").click(function(){
$("#selectremindertype").click(function(){
var selected_option = $("#selectremindertype option:selected").val();
if(selected_option == "email") {
$("#select_actioncommsendmodel_mail").closest("tr").show();
} else {
$("#select_actioncommsendmodel_mail").closest("tr").hide();
};
});
});
})';
print '</script>'."\n";
}

View File

@ -5594,9 +5594,11 @@ class Form
if ($addnowlink == 1)
{
$reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(\''.dol_print_date(dol_now(), '%H', 'tzuser').'\');';
$reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').change();';
} elseif ($addnowlink == 2)
{
$reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(d.getHours().pad());';
$reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').change();';
}
if ($fullday) $reset_scripts .= ' } ';
@ -5609,9 +5611,11 @@ class Form
if ($addnowlink == 1)
{
$reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(\''.dol_print_date(dol_now(), '%M', 'tzuser').'\');';
$reset_scripts .= 'jQuery(\'#'.$prefix.'min\').change();';
} elseif ($addnowlink == 2)
{
$reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(d.getMinutes().pad());';
$reset_scripts .= 'jQuery(\'#'.$prefix.'min\').change();';
}
if ($fullday) $reset_scripts .= ' } ';
}
@ -5676,7 +5680,7 @@ class Form
* @param string $modelType Model type
* @return string HTML select string
*/
public function select_type_duration($prefix, $selected = 'minute')
public function select_type_duration($prefix, $selected = 'minute')
{
global $langs;