{% extends "layout.html" %} {% block title %}{{ title }}{% endblock %} {% block content %}
{% endblock %} {% block script %} const formState = { brands: [], types: [], sections: [], functions: [], rooms: [] }; document.addEventListener('DOMContentLoaded', () => { const modal = document.getElementById('roomEditor'); const saveButton = document.getElementById('roomEditorSaveButton'); const cancelButton = document.getElementById('roomEditorCancelButton'); const form = document.getElementById('settingsForm'); // Replace the whole submission logic with just JSON form.addEventListener('submit', () => { document.getElementById('formStateField').value = JSON.stringify(formState); }); // Modal populates dropdowns fresh from the page every time it opens modal.addEventListener('show.bs.modal', () => { const modalSections = document.getElementById('roomSection'); const modalFunctions = document.getElementById('roomFunction'); const pageSections = document.getElementById('section-list'); const pageFunctions = document.getElementById('function-list'); modalSections.innerHTML = ''; modalFunctions.innerHTML = ''; modalSections.appendChild(new Option("Select a section", "")); modalFunctions.appendChild(new Option("Select a function", "")); Array.from(pageSections.options).forEach(opt => modalSections.appendChild(new Option(opt.textContent, opt.value)) ); Array.from(pageFunctions.options).forEach(opt => modalFunctions.appendChild(new Option(opt.textContent, opt.value)) ); }); saveButton.addEventListener('click', () => { const name = document.getElementById('roomName').value.trim(); const section = document.getElementById('roomSection').value; const func = document.getElementById('roomFunction').value; if (!name) { alert('Please enter a room name.'); return; } // Avoid duplicate visible names const roomList = document.getElementById('room-list'); const exists = Array.from(roomList.options).some(opt => opt.textContent.trim() === name); if (exists) { alert(`Room "${name}" already exists.`); return; } // Add to select box visibly const option = ComboBoxWidget.createOption(name); roomList.appendChild(option); ComboBoxWidget.sortOptions(roomList); // Track in state object formState.rooms.push({ name, section_id: section, function_id: func }); bootstrap.Modal.getInstance(modal).hide(); }); cancelButton.addEventListener('click', () => { bootstrap.Modal.getInstance(modal).hide(); }); }); {% endblock %}