Settings buttons adjusted.

This commit is contained in:
Yaro Kasear 2025-07-15 12:35:07 -05:00
parent 1f2f0bac91
commit ad8354ea3d
2 changed files with 40 additions and 39 deletions

View file

@ -6,9 +6,7 @@
{% if logic %} {% if logic %}
<script> <script>
document.addEventListener("DOMContentLoaded", (e) => { document.addEventListener("DOMContentLoaded", (e) => {
{{ id }}Button = document.getElementById("{{ id }}Button"); document.getElementById("{{ id }}Button").addEventListener("click", async () =>{
{{ id }}Button.addEventListener("click", async () =>{
{{ logic | safe }} {{ logic | safe }}
}); });
}); });

View file

@ -234,8 +234,45 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal" <button type="button" class="btn btn-danger" data-bs-dismiss="modal"
id="roomEditorCancelButton">Cancel</button> id="roomEditorCancelButton">{{ icons.render_icon('x-lg', 16) }}</button>
<button type="button" class="btn btn-primary" id="editorSaveButton">Save</button> {% set editorSaveLogic %}
const modal = document.getElementById('roomEditor');
const name = document.getElementById('roomName').value.trim();
const sectionVal = document.getElementById('roomSection').value;
const funcVal = document.getElementById('roomFunction').value;
let idRaw = document.getElementById('roomId').value;
if (!name) {
alert('Please enter a room name.');
return;
}
const roomList = document.getElementById('room-list');
let existingOption = Array.from(roomList.options).find(opt => opt.value === idRaw);
if (!idRaw) {
idRaw = ComboBoxWidget.createTempId("room");
}
if (!existingOption) {
existingOption = ComboBoxWidget.createOption(name, idRaw);
roomList.appendChild(existingOption);
}
existingOption.textContent = name;
existingOption.value = idRaw;
existingOption.dataset.sectionId = sectionVal || "";
existingOption.dataset.functionId = funcVal || "";
ComboBoxWidget.sortOptions(roomList);
bootstrap.Modal.getInstance(modal).hide();
{% endset %}
{{ buttons.render_button(
id='editorSave',
icon='floppy',
logic=editorSaveLogic
) }}
</div> </div>
</div> </div>
</div> </div>
@ -245,7 +282,6 @@
{% block script %} {% block script %}
const modal = document.getElementById('roomEditor'); const modal = document.getElementById('roomEditor');
const editorSaveButton = document.getElementById('editorSaveButton');
const cancelButton = document.getElementById('roomEditorCancelButton'); const cancelButton = document.getElementById('roomEditorCancelButton');
const form = document.getElementById('settingsForm'); const form = document.getElementById('settingsForm');
@ -280,39 +316,6 @@
}); });
}); });
editorSaveButton.addEventListener('click', () => {
const name = document.getElementById('roomName').value.trim();
const sectionVal = document.getElementById('roomSection').value;
const funcVal = document.getElementById('roomFunction').value;
let idRaw = document.getElementById('roomId').value;
if (!name) {
alert('Please enter a room name.');
return;
}
const roomList = document.getElementById('room-list');
let existingOption = Array.from(roomList.options).find(opt => opt.value === idRaw);
if (!idRaw) {
idRaw = ComboBoxWidget.createTempId("room");
}
if (!existingOption) {
existingOption = ComboBoxWidget.createOption(name, idRaw);
roomList.appendChild(existingOption);
}
existingOption.textContent = name;
existingOption.value = idRaw;
existingOption.dataset.sectionId = sectionVal || "";
existingOption.dataset.functionId = funcVal || "";
ComboBoxWidget.sortOptions(roomList);
bootstrap.Modal.getInstance(modal).hide();
});
cancelButton.addEventListener('click', () => { cancelButton.addEventListener('click', () => {
bootstrap.Modal.getInstance(modal).hide(); bootstrap.Modal.getInstance(modal).hide();
}); });