|
|
|
@ -537,7 +537,104 @@ function displayWarnings() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const personInfoDiv = document.getElementById('personInfo');
|
|
|
|
|
const personStartTime = document.getElementById('person_start_time');
|
|
|
|
|
const personEndTime = document.getElementById('person_end_time');
|
|
|
|
|
const personDays = document.getElementById('person_days');
|
|
|
|
|
function displayPersonInfoDiv() {
|
|
|
|
|
const singlePerson = hash.person && hash.person.name;
|
|
|
|
|
personInfoDiv.style.display = singlePerson ? '' : 'none';
|
|
|
|
|
if (!singlePerson) return;
|
|
|
|
|
|
|
|
|
|
const info = schedule.infoFor(hash.person);
|
|
|
|
|
|
|
|
|
|
personStartTime.value = new utils.Time(info.start_time ?? schedule.start_time).inputValue;
|
|
|
|
|
personEndTime.value = new utils.Time(info.end_time ?? schedule.end_time).inputValue;
|
|
|
|
|
|
|
|
|
|
personStartTime.step = schedule.granularity.total_seconds;
|
|
|
|
|
personEndTime.step = schedule.granularity.total_seconds;
|
|
|
|
|
|
|
|
|
|
utils.clearChildren(personDays);
|
|
|
|
|
|
|
|
|
|
for (const day of utils.allDays.filter(d => schedule.all_days.includes(d)
|
|
|
|
|
|| info.days && info.days.includes(d))) {
|
|
|
|
|
const dayLabel = document.createElement('label');
|
|
|
|
|
const dayName = utils.DayString(day);
|
|
|
|
|
const dayCheckbox = document.createElement('input');
|
|
|
|
|
|
|
|
|
|
dayCheckbox.type = 'checkbox';
|
|
|
|
|
dayCheckbox.checked = (info.days ?? schedule.all_days).includes(day);
|
|
|
|
|
dayCheckbox.addEventListener('change', async e => {
|
|
|
|
|
let newDays = info.days;
|
|
|
|
|
if (!e.target.checked) {
|
|
|
|
|
if (schedule.assignments.some(a => a.hasPersonExplicitlyOnDay(hash.person, day))) {
|
|
|
|
|
alert("Cannot remove schedule for " + dayName
|
|
|
|
|
+ " because " + hash.person.name
|
|
|
|
|
+ " is in events on that day.");
|
|
|
|
|
e.target.checked = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!newDays) newDays = [...schedule.all_days];
|
|
|
|
|
newDays.splice(schedule.all_days.indexOf(day), 1);
|
|
|
|
|
} else {
|
|
|
|
|
newDays = schedule.all_days.filter(d => (info.days ?? schedule.all_days).includes(d) || d === day);
|
|
|
|
|
}
|
|
|
|
|
if (newDays && utils.setEqual(newDays, schedule.all_days)) {
|
|
|
|
|
newDays = undefined;
|
|
|
|
|
}
|
|
|
|
|
schedule.setInfoFor(hash.person, {days: newDays});
|
|
|
|
|
await saveSchedule();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dayLabel.appendChild(dayCheckbox);
|
|
|
|
|
dayLabel.appendChild(document.createTextNode(dayName));
|
|
|
|
|
personDays.appendChild(dayLabel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
personStartTime.addEventListener('change', utils.debounceAsync(async e => {
|
|
|
|
|
const newStartTime = utils.Time.fromInputValue(e.target.value);
|
|
|
|
|
const assignments = schedule.assignments.filter(a => a.hasPersonExplicitlyOnAnyDay(hash.person));
|
|
|
|
|
if (assignments) {
|
|
|
|
|
const earliestStart = assignments.map(a => a.start_time).sort((a, b) => a.cmp(b))[0];
|
|
|
|
|
if (earliestStart.cmp(newStartTime) < 0) {
|
|
|
|
|
alert("Cannot change start time to " + newStartTime.to12HourString()
|
|
|
|
|
+ " because it is after the earliest assignment for "
|
|
|
|
|
+ hash.person.name + " starts at "
|
|
|
|
|
+ earliestStart.to12HourString() + ".");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
schedule.setInfoFor(hash.person, {start_time:
|
|
|
|
|
newStartTime.cmp(schedule.start_time) !== 0
|
|
|
|
|
? newStartTime.asJsonObject()
|
|
|
|
|
: undefined});
|
|
|
|
|
await saveSchedule();
|
|
|
|
|
}, 1000));
|
|
|
|
|
|
|
|
|
|
personEndTime.addEventListener('change', utils.debounceAsync(async e => {
|
|
|
|
|
const newEndTime = utils.Time.fromInputValue(e.target.value);
|
|
|
|
|
const assignments = schedule.assignments.filter(a => a.hasPersonExplicitlyOnAnyDay(hash.person));
|
|
|
|
|
if (assignments) {
|
|
|
|
|
const latestEnd = assignments.map(a => a.end_time).sort((a, b) => b.cmp(a))[0];
|
|
|
|
|
if (latestEnd.cmp(newEndTime) > 0) {
|
|
|
|
|
alert("Cannot change end time to " + newEndTime.to12HourString()
|
|
|
|
|
+ " because it is before the latest assignment for "
|
|
|
|
|
+ hash.person.name + " ends at "
|
|
|
|
|
+ latestEnd.to12HourString() + ".");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
schedule.setInfoFor(hash.person, {end_time:
|
|
|
|
|
newEndTime.cmp(schedule.end_time) !== 0
|
|
|
|
|
? newEndTime.asJsonObject()
|
|
|
|
|
: undefined});
|
|
|
|
|
await saveSchedule();
|
|
|
|
|
}, 1000));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function displaySchedule() {
|
|
|
|
|
displayPersonInfoDiv();
|
|
|
|
|
utils.clearChildren(schedulesDiv);
|
|
|
|
|
if (hash.day && !schedule.all_days.includes(hash.day)) {
|
|
|
|
|
updateHash({day: undefined});
|
|
|
|
|