Refactor .gitignore; add patterns for SQLite database files and improve ignored file management

Enhance app initialization; set secret key from environment variable for better security practices

Update work_log model import; change User import path for improved module structure

Refactor routes; add new inventory item creation route and enhance settings handling with JSON form state

Improve ComboBoxWidget; add handleComboAdd function for better option management and integrate with render_combobox macro

Revamp settings template; implement form state management and improve modal functionality for room creation

Add error template; create a new error handling page for better user feedback
This commit is contained in:
Yaro Kasear 2025-06-23 10:05:31 -05:00
parent 142e909a88
commit c6fc1a4795
9 changed files with 269 additions and 113 deletions

View file

@ -15,6 +15,27 @@ const ComboBoxWidget = (() => {
sorted.forEach(option => selectElement.appendChild(option));
}
function handleComboAdd(inputId, listId, stateArray, label = 'entry') {
const input = document.getElementById(inputId);
const value = input.value.trim();
if (!value) {
alert(`Please enter a ${label}.`);
return;
}
const select = document.getElementById(listId);
const exists = Array.from(select.options).some(opt => opt.textContent === value);
if (exists) {
alert(`${label.charAt(0).toUpperCase() + label.slice(1)} "${value}" already exists.`);
return;
}
const option = new Option(value, value);
select.add(option);
formState[stateArray].push(value);
input.value = '';
}
function initComboBox(ns, config = {}) {
const input = document.querySelector(`#${ns}-input`);
const list = document.querySelector(`#${ns}-list`);
@ -76,8 +97,23 @@ const ComboBoxWidget = (() => {
if (config.onAdd) {
config.onAdd(newItem, list, createOption);
} else {
const option = createOption(newItem);
list.appendChild(option);
// Default fallback here
if (config.stateArray && formState && formState[config.stateArray]) {
const exists = Array.from(list.options).some(opt => opt.textContent === newItem);
if (exists) {
alert(`"${newItem}" already exists.`);
return;
}
const option = createOption(newItem);
list.appendChild(option);
formState[config.stateArray].push(newItem);
if (config.sort !== false) {
sortOptions(list);
}
} else {
const option = createOption(newItem);
list.appendChild(option);
}
}
}
@ -85,12 +121,9 @@ const ComboBoxWidget = (() => {
addBtn.disabled = true;
removeBtn.disabled = true;
updateAddButtonIcon();
if (config.sort !== false) {
sortOptions(list);
}
});
removeBtn.addEventListener('click', () => {
Array.from(list.selectedOptions).forEach(option => {
if (config.onRemove) {
@ -110,6 +143,7 @@ const ComboBoxWidget = (() => {
return {
initComboBox,
createOption,
sortOptions
sortOptions,
handleComboAdd
};
})();