fix(schedule): add delete button to schedule edit modal so schedules can be removed from the UI (DELETE /api/schedules/:id already existed)

This commit is contained in:
ScreenTinker 2026-05-11 23:05:03 -05:00
parent 0b9aa56e75
commit f88805f36d

View file

@ -107,12 +107,15 @@ export async function render(container) {
<div class="form-group"><label>${t('schedule.priority')}</label><input type="number" id="schedPriority" class="input" value="0" min="0" max="100"></div> <div class="form-group"><label>${t('schedule.priority')}</label><input type="number" id="schedPriority" class="input" value="0" min="0" max="100"></div>
<div class="form-group"><label>${t('schedule.color')}</label><input type="color" id="schedColor" value="#3B82F6" style="width:60px;height:32px;border:none;cursor:pointer"></div> <div class="form-group"><label>${t('schedule.color')}</label><input type="color" id="schedColor" value="#3B82F6" style="width:60px;height:32px;border:none;cursor:pointer"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer" style="display:flex;justify-content:space-between;gap:8px">
<button class="btn btn-danger" id="deleteScheduleBtn" style="display:none">${t('common.delete')}</button>
<div style="display:flex;gap:8px;margin-left:auto">
<button class="btn btn-secondary" onclick="document.getElementById('scheduleModal').style.display='none'">${t('common.cancel')}</button> <button class="btn btn-secondary" onclick="document.getElementById('scheduleModal').style.display='none'">${t('common.cancel')}</button>
<button class="btn btn-primary" id="saveScheduleBtn">${t('common.save')}</button> <button class="btn btn-primary" id="saveScheduleBtn">${t('common.save')}</button>
</div> </div>
</div> </div>
</div> </div>
</div>
`; `;
let currentWeekStart = new Date(weekStart); let currentWeekStart = new Date(weekStart);
@ -223,6 +226,7 @@ export async function render(container) {
} }
updateTargetVisibility(); updateTargetVisibility();
document.getElementById('deleteScheduleBtn').style.display = '';
document.getElementById('scheduleModal').style.display = 'flex'; document.getElementById('scheduleModal').style.display = 'flex';
} }
@ -236,9 +240,23 @@ export async function render(container) {
deviceRadio.checked = true; deviceRadio.checked = true;
deviceSelect.value = document.getElementById('schedDevice').value; deviceSelect.value = document.getElementById('schedDevice').value;
updateTargetVisibility(); updateTargetVisibility();
document.getElementById('deleteScheduleBtn').style.display = 'none';
document.getElementById('scheduleModal').style.display = 'flex'; document.getElementById('scheduleModal').style.display = 'flex';
}; };
document.getElementById('deleteScheduleBtn').onclick = async () => {
if (!editingId) return;
if (!confirm(t('schedule.confirm_delete') || 'Delete this schedule?')) return;
try {
await API(`/schedules/${editingId}`, { method: 'DELETE' });
document.getElementById('scheduleModal').style.display = 'none';
showToast(t('schedule.toast.deleted') || 'Schedule deleted', 'success');
loadCalendar();
} catch (err) {
showToast(err.message, 'error');
}
};
document.getElementById('saveScheduleBtn').onclick = async () => { document.getElementById('saveScheduleBtn').onclick = async () => {
const isGroup = groupRadio.checked; const isGroup = groupRadio.checked;
const contentId = document.getElementById('schedContent').value; const contentId = document.getElementById('schedContent').value;