|
|
|
@ -1,27 +1,27 @@
|
|
|
|
|
// change the date field consistently with day field
|
|
|
|
|
function add_change_day_handler(elem, day_field_id, date_field_id) {
|
|
|
|
|
function add_change_day_handler(elem, day_input_id, startdate_input_id) {
|
|
|
|
|
elem.addEventListener('change', function(e) {
|
|
|
|
|
const setted_weekday = document.getElementById(day_field_id).value;
|
|
|
|
|
const date_input = document.getElementById(date_field_id);
|
|
|
|
|
if (date_input.value.length !== 0 && setted_weekday.length !== 0){
|
|
|
|
|
const date = new Date(date_input.value);
|
|
|
|
|
const setted_weekday = document.getElementById(day_input_id).value;
|
|
|
|
|
const startdate_input = document.getElementById(startdate_input_id);
|
|
|
|
|
if (startdate_input.value.length !== 0 && setted_weekday.length !== 0){
|
|
|
|
|
const date = new Date(startdate_input.value);
|
|
|
|
|
let weekday = date.getDay();
|
|
|
|
|
weekday = (weekday == 0) ? 7 : weekday;
|
|
|
|
|
if (weekday != setted_weekday ) {
|
|
|
|
|
let weekday_diff = setted_weekday - weekday;
|
|
|
|
|
date.setDate(date.getDate() + weekday_diff);
|
|
|
|
|
date_input.value = date.toISOString().split('T')[0];
|
|
|
|
|
startdate_input.value = date.toISOString().split('T')[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// change the day field consistently with date field
|
|
|
|
|
function add_change_date_handler(elem, day_field_id, date_field_id) {
|
|
|
|
|
// change the day field consistently with date field - unused!
|
|
|
|
|
function add_change_date_handler(elem, day_input_id, startdate_input_id) {
|
|
|
|
|
elem.addEventListener('change', function(e) {
|
|
|
|
|
const setted_date = document.getElementById(date_field_id).value;
|
|
|
|
|
const setted_date = document.getElementById(startdate_input_id).value;
|
|
|
|
|
if (setted_date.length !== 0) {
|
|
|
|
|
const day_input = document.getElementById(day_field_id);
|
|
|
|
|
const day_input = document.getElementById(day_input_id);
|
|
|
|
|
let setted_weekday = day_input.value;
|
|
|
|
|
let date_weekday = new Date(setted_date).getDay();
|
|
|
|
|
date_weekday = (date_weekday == 0) ? 7 : date_weekday;
|
|
|
|
@ -32,17 +32,51 @@ function add_change_date_handler(elem, day_field_id, date_field_id) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add_required_date_handler(elem, prefix, input_number) {
|
|
|
|
|
elem.addEventListener('change', function(e){
|
|
|
|
|
set_date_as_required_if_cadence_is_set(prefix, input_number);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function set_date_as_required_if_cadence_is_set(prefix, input_number) {
|
|
|
|
|
const cadence = document.getElementById(prefix + "_cadence_" + input_number);
|
|
|
|
|
const startdate = document.getElementById(prefix + "_startdate_" + input_number);
|
|
|
|
|
const msg = document.getElementById(prefix +"_message_" + input_number);
|
|
|
|
|
if (cadence.value != 1 && startdate.value == "") {
|
|
|
|
|
if (!msg){
|
|
|
|
|
const textAlert = document.createElement("p");
|
|
|
|
|
const text = document.createTextNode("attenzione: se non viene inserita la data di inizio la cadenza sarà interpretata come settimanale");
|
|
|
|
|
textAlert.appendChild(text);
|
|
|
|
|
textAlert.id = prefix + "_message_" + input_number;
|
|
|
|
|
textAlert.style = "color:red;font-size:12px;width:90%;";
|
|
|
|
|
startdate.parentNode.appendChild(textAlert);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (msg) {
|
|
|
|
|
startdate.parentNode.removeChild(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < 7 ; i++) {
|
|
|
|
|
let onair_day_input = document.getElementById("on_air_day_" + i);
|
|
|
|
|
let rerun_day_input = document.getElementById("rerun_day_" + i);
|
|
|
|
|
let onair_date_input = document.getElementById("on_air_start_date_" + i);
|
|
|
|
|
let rerun_date_input = document.getElementById("rerun_start_date_" + i);
|
|
|
|
|
add_change_day_handler(onair_day_input, "on_air_day_" + i, "on_air_start_date_" + i);
|
|
|
|
|
add_change_day_handler(rerun_day_input, "rerun_day_" + i, "rerun_start_date_" + i);
|
|
|
|
|
add_change_day_handler(onair_date_input, "on_air_day_" + i, "on_air_start_date_" + i);
|
|
|
|
|
add_change_day_handler(rerun_date_input, "rerun_day_" + i, "rerun_start_date_" + i);
|
|
|
|
|
// add_change_date_handler(onair_date_input, "on_air_day_" + i, "on_air_start_date_" + i);
|
|
|
|
|
// add_change_date_handler(rerun_date_input, "rerun_day_" + i, "rerun_start_date_" + i);
|
|
|
|
|
let onair_date_input = document.getElementById("on_air_startdate_" + i);
|
|
|
|
|
let rerun_date_input = document.getElementById("rerun_startdate_" + i);
|
|
|
|
|
let onair_cadence_input = document.getElementById("on_air_cadence_" + i);
|
|
|
|
|
let rerun_cadence_input = document.getElementById("rerun_cadence_" + i);
|
|
|
|
|
|
|
|
|
|
add_change_day_handler(onair_day_input, "on_air_day_" + i, "on_air_startdate_" + i);
|
|
|
|
|
add_change_day_handler(rerun_day_input, "rerun_day_" + i, "rerun_startdate_" + i);
|
|
|
|
|
add_change_day_handler(onair_date_input, "on_air_day_" + i, "on_air_startdate_" + i);
|
|
|
|
|
add_change_day_handler(rerun_date_input, "rerun_day_" + i, "rerun_startdate_" + i);
|
|
|
|
|
|
|
|
|
|
set_date_as_required_if_cadence_is_set("on_air", i);
|
|
|
|
|
set_date_as_required_if_cadence_is_set("rerun", i);
|
|
|
|
|
|
|
|
|
|
add_required_date_handler(onair_cadence_input, "on_air", i);
|
|
|
|
|
add_required_date_handler(rerun_cadence_input, "rerun", i);
|
|
|
|
|
add_required_date_handler(onair_date_input, "on_air", i);
|
|
|
|
|
add_required_date_handler(rerun_date_input, "rerun", i);
|
|
|
|
|
}
|