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 %}
<script>
document.addEventListener("DOMContentLoaded", (e) => {
{{ id }}Button = document.getElementById("{{ id }}Button");
{{ id }}Button.addEventListener("click", async () =>{
document.getElementById("{{ id }}Button").addEventListener("click", async () =>{
{{ logic | safe }}
});
});

View file

@ -234,8 +234,45 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal"
id="roomEditorCancelButton">Cancel</button>
<button type="button" class="btn btn-primary" id="editorSaveButton">Save</button>
id="roomEditorCancelButton">{{ icons.render_icon('x-lg', 16) }}</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>
@ -245,7 +282,6 @@
{% block script %}
const modal = document.getElementById('roomEditor');
const editorSaveButton = document.getElementById('editorSaveButton');
const cancelButton = document.getElementById('roomEditorCancelButton');
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', () => {
bootstrap.Modal.getInstance(modal).hide();
});