54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
|
|
function getManagedChecks() {
|
|||
|
|
return Array.from(document.querySelectorAll('.managed-check'));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function updateSelectedCount() {
|
|||
|
|
const checkedCount = getManagedChecks().filter((item) => item.checked).length;
|
|||
|
|
const counter = document.getElementById('selectedCount');
|
|||
|
|
if (counter) {
|
|||
|
|
counter.textContent = String(checkedCount);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function toggleAllManaged() {
|
|||
|
|
const checks = getManagedChecks();
|
|||
|
|
if (!checks.length) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const allChecked = checks.every((item) => item.checked);
|
|||
|
|
checks.forEach((item) => {
|
|||
|
|
item.checked = !allChecked;
|
|||
|
|
});
|
|||
|
|
updateSelectedCount();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function updateScheduleControlsState() {
|
|||
|
|
const enabledCheck = document.getElementById('schedule_enabled');
|
|||
|
|
const controlsWrap = document.getElementById('scheduleControls');
|
|||
|
|
if (!enabledCheck || !controlsWrap) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const enabled = enabledCheck.checked;
|
|||
|
|
controlsWrap.classList.toggle('schedule-disabled', !enabled);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|||
|
|
const checks = getManagedChecks();
|
|||
|
|
checks.forEach((item) => item.addEventListener('change', updateSelectedCount));
|
|||
|
|
|
|||
|
|
const toggleBtn = document.getElementById('toggleManaged');
|
|||
|
|
if (toggleBtn) {
|
|||
|
|
toggleBtn.addEventListener('click', toggleAllManaged);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const scheduleEnabled = document.getElementById('schedule_enabled');
|
|||
|
|
if (scheduleEnabled) {
|
|||
|
|
scheduleEnabled.addEventListener('change', updateScheduleControlsState);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
updateSelectedCount();
|
|||
|
|
updateScheduleControlsState();
|
|||
|
|
});
|