feat: Implement currency management with models, routes, and UI updates; add backfill script for existing records
This commit is contained in:
@@ -41,6 +41,42 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const capexCurrencySelect = document.getElementById("capex-form-currency");
|
||||
const opexCurrencySelect = document.getElementById("opex-form-currency");
|
||||
|
||||
// If no currency options were injected server-side, fetch from API
|
||||
const fetchCurrencyOptions = async () => {
|
||||
try {
|
||||
const resp = await fetch("/api/currencies/");
|
||||
if (!resp.ok) return;
|
||||
const list = await resp.json();
|
||||
if (Array.isArray(list) && list.length) {
|
||||
currencyOptions = list;
|
||||
populateCurrencySelects();
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Unable to fetch currency options", err);
|
||||
}
|
||||
};
|
||||
|
||||
const populateCurrencySelects = () => {
|
||||
const selectElements = [capexCurrencySelect, opexCurrencySelect].filter(Boolean);
|
||||
selectElements.forEach((sel) => {
|
||||
if (!sel) return;
|
||||
// Clear non-empty options except the empty placeholder
|
||||
const placeholder = sel.querySelector("option[value='']");
|
||||
sel.innerHTML = "";
|
||||
if (placeholder) sel.appendChild(placeholder);
|
||||
currencyOptions.forEach((opt) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = opt.id;
|
||||
option.textContent = opt.name || opt.id;
|
||||
sel.appendChild(option);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// populate from injected options first, then fetch to refresh
|
||||
if (currencyOptions && currencyOptions.length) populateCurrencySelects();
|
||||
else fetchCurrencyOptions();
|
||||
|
||||
const showFeedback = (element, message, type = "success") => {
|
||||
if (!element) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user