|
@@ -45,12 +45,15 @@
|
|
|
<section class="tile-light compact">
|
|
<section class="tile-light compact">
|
|
|
<div class="card-grid">
|
|
<div class="card-grid">
|
|
|
<% schedules.forEach((item) => { %>
|
|
<% schedules.forEach((item) => { %>
|
|
|
- <article class="utility-card">
|
|
|
|
|
- <p class="eyebrow"><%= item.is_enabled ? '启用' : '停用' %></p>
|
|
|
|
|
- <h3><%= item.name %></h3>
|
|
|
|
|
- <p><%= item.time %> · <%= actionLabel(item.action) %> · <%= targetLabel(item.target_channel) %></p>
|
|
|
|
|
- <p><%= repeatLabel(item.repeat_type) %><% if (item.weekdays) { %>:<%= item.weekdays.split(',').map(weekdayLabel).join('、') %><% } %></p>
|
|
|
|
|
|
|
+ <article class="utility-card schedule-card <%= item.is_enabled ? '' : 'schedule-disabled' %>" data-schedule-card data-id="<%= item.id %>" data-name="<%= item.name %>" data-target-channel="<%= item.target_channel %>" data-action="<%= item.action %>" data-time="<%= item.time %>" data-repeat-type="<%= item.repeat_type %>" data-weekdays="<%= item.weekdays %>">
|
|
|
|
|
+ <p class="eyebrow schedule-status <%= item.is_enabled ? 'schedule-status-enabled' : 'schedule-status-disabled' %>"><%= item.is_enabled ? '启用' : '停用' %></p>
|
|
|
|
|
+ <div class="schedule-content">
|
|
|
|
|
+ <h3><%= item.name %></h3>
|
|
|
|
|
+ <p><%= item.time %> · <%= actionLabel(item.action) %> · <%= targetLabel(item.target_channel) %></p>
|
|
|
|
|
+ <p><%= repeatLabel(item.repeat_type) %><% if (item.weekdays) { %>:<%= item.weekdays.split(',').map(weekdayLabel).join('、') %><% } %></p>
|
|
|
|
|
+ </div>
|
|
|
<div class="inline-actions">
|
|
<div class="inline-actions">
|
|
|
|
|
+ <button class="button-secondary small" type="button" data-edit-schedule>修改</button>
|
|
|
<form method="post" action="/schedules/<%= item.id %>/toggle"><button class="button-secondary small"><%= item.is_enabled ? '停用' : '启用' %></button></form>
|
|
<form method="post" action="/schedules/<%= item.id %>/toggle"><button class="button-secondary small"><%= item.is_enabled ? '停用' : '启用' %></button></form>
|
|
|
<form method="post" action="/schedules/<%= item.id %>/delete"><button class="button-secondary small">删除</button></form>
|
|
<form method="post" action="/schedules/<%= item.id %>/delete"><button class="button-secondary small">删除</button></form>
|
|
|
</div>
|
|
</div>
|
|
@@ -64,11 +67,11 @@
|
|
|
<div class="modal-header">
|
|
<div class="modal-header">
|
|
|
<div>
|
|
<div>
|
|
|
<p class="eyebrow">Schedule</p>
|
|
<p class="eyebrow">Schedule</p>
|
|
|
- <h2>添加计划</h2>
|
|
|
|
|
|
|
+ <h2 id="scheduleDialogTitle">添加计划</h2>
|
|
|
</div>
|
|
</div>
|
|
|
<button class="modal-close" type="button" id="closeScheduleDialog" aria-label="关闭">×</button>
|
|
<button class="modal-close" type="button" id="closeScheduleDialog" aria-label="关闭">×</button>
|
|
|
</div>
|
|
</div>
|
|
|
- <form method="post" action="/schedules" class="form-grid modal-form">
|
|
|
|
|
|
|
+ <form method="post" action="/schedules" class="form-grid modal-form" id="scheduleForm">
|
|
|
<label>名称<input name="name" required placeholder="例如 工作日开灯"></label>
|
|
<label>名称<input name="name" required placeholder="例如 工作日开灯"></label>
|
|
|
<label>目标
|
|
<label>目标
|
|
|
<select name="target_channel">
|
|
<select name="target_channel">
|
|
@@ -100,7 +103,7 @@
|
|
|
</div>
|
|
</div>
|
|
|
<div class="modal-actions">
|
|
<div class="modal-actions">
|
|
|
<button class="button-secondary" type="button" id="cancelScheduleDialog">取消</button>
|
|
<button class="button-secondary" type="button" id="cancelScheduleDialog">取消</button>
|
|
|
- <button class="button-primary">创建计划</button>
|
|
|
|
|
|
|
+ <button class="button-primary" id="scheduleSubmitButton">创建计划</button>
|
|
|
</div>
|
|
</div>
|
|
|
</form>
|
|
</form>
|
|
|
</dialog>
|
|
</dialog>
|
|
@@ -110,6 +113,9 @@
|
|
|
const openScheduleDialog = document.getElementById('openScheduleDialog');
|
|
const openScheduleDialog = document.getElementById('openScheduleDialog');
|
|
|
const closeScheduleDialog = document.getElementById('closeScheduleDialog');
|
|
const closeScheduleDialog = document.getElementById('closeScheduleDialog');
|
|
|
const cancelScheduleDialog = document.getElementById('cancelScheduleDialog');
|
|
const cancelScheduleDialog = document.getElementById('cancelScheduleDialog');
|
|
|
|
|
+ const scheduleDialogTitle = document.getElementById('scheduleDialogTitle');
|
|
|
|
|
+ const scheduleForm = document.getElementById('scheduleForm');
|
|
|
|
|
+ const scheduleSubmitButton = document.getElementById('scheduleSubmitButton');
|
|
|
const repeatType = document.getElementById('repeatType');
|
|
const repeatType = document.getElementById('repeatType');
|
|
|
const weekdayPicker = document.getElementById('weekdayPicker');
|
|
const weekdayPicker = document.getElementById('weekdayPicker');
|
|
|
|
|
|
|
@@ -123,7 +129,37 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- openScheduleDialog.addEventListener('click', () => scheduleDialog.showModal());
|
|
|
|
|
|
|
+ function openCreateScheduleDialog() {
|
|
|
|
|
+ scheduleDialogTitle.textContent = '添加计划';
|
|
|
|
|
+ scheduleSubmitButton.textContent = '创建计划';
|
|
|
|
|
+ scheduleForm.action = '/schedules';
|
|
|
|
|
+ scheduleForm.reset();
|
|
|
|
|
+ syncWeekdayPicker();
|
|
|
|
|
+ scheduleDialog.showModal();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function openEditScheduleDialog(card) {
|
|
|
|
|
+ scheduleDialogTitle.textContent = '修改计划';
|
|
|
|
|
+ scheduleSubmitButton.textContent = '保存修改';
|
|
|
|
|
+ scheduleForm.action = `/schedules/${card.dataset.id}/update`;
|
|
|
|
|
+ scheduleForm.elements.name.value = card.dataset.name || '';
|
|
|
|
|
+ scheduleForm.elements.target_channel.value = card.dataset.targetChannel || '0';
|
|
|
|
|
+ scheduleForm.elements.action.value = card.dataset.action || 'open';
|
|
|
|
|
+ scheduleForm.elements.time.value = card.dataset.time || '';
|
|
|
|
|
+ scheduleForm.elements.repeat_type.value = card.dataset.repeatType || 'daily';
|
|
|
|
|
+
|
|
|
|
|
+ const weekdays = (card.dataset.weekdays || '').split(',').filter(Boolean);
|
|
|
|
|
+ weekdayPicker.querySelectorAll('input[type="checkbox"]').forEach((input) => {
|
|
|
|
|
+ input.checked = weekdays.includes(input.value);
|
|
|
|
|
+ });
|
|
|
|
|
+ syncWeekdayPicker();
|
|
|
|
|
+ scheduleDialog.showModal();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ openScheduleDialog.addEventListener('click', openCreateScheduleDialog);
|
|
|
|
|
+ document.querySelectorAll('[data-edit-schedule]').forEach((button) => {
|
|
|
|
|
+ button.addEventListener('click', () => openEditScheduleDialog(button.closest('[data-schedule-card]')));
|
|
|
|
|
+ });
|
|
|
closeScheduleDialog.addEventListener('click', () => scheduleDialog.close());
|
|
closeScheduleDialog.addEventListener('click', () => scheduleDialog.close());
|
|
|
cancelScheduleDialog.addEventListener('click', () => scheduleDialog.close());
|
|
cancelScheduleDialog.addEventListener('click', () => scheduleDialog.close());
|
|
|
scheduleDialog.addEventListener('click', (event) => {
|
|
scheduleDialog.addEventListener('click', (event) => {
|