diff --git a/static/transaction.js b/static/transaction.js index 4e8d122..92ccb69 100644 --- a/static/transaction.js +++ b/static/transaction.js @@ -386,14 +386,43 @@ }); } + var marketList = []; + function fillMarkets(markets) { - markets.forEach(function (market) { - ["market_id", "to_market"].forEach(function (name) { + marketList = markets; + fillMarketSelects(); + } + + /* The bank is offered only where docs/spec.md section 3.11 allows it: a transfer + whose amount is in kroner, as the account it is drawn from or the one it goes + to. Everywhere else it is not a choice. */ + function bankAllowed() { + return type() === "transfer_out" + && Skuld.fieldValue("leg_out_currency") === "nok"; + } + + function fillMarketSelects() { + var allowBank = bankAllowed(); + ["market_id", "to_market"].forEach(function (name) { + var select = document.querySelector('[name="' + name + '"]'); + var keep = select.value; + select.textContent = ""; + if (name === "to_market") { + var empty = document.createElement("option"); + empty.value = ""; + empty.textContent = "Vel konto"; + select.appendChild(empty); + } + marketList.forEach(function (market) { + if (market.bank && !allowBank) { + return; + } var option = document.createElement("option"); option.value = String(market.id); option.textContent = market.name; - document.querySelector('[name="' + name + '"]').appendChild(option); + select.appendChild(option); }); + select.value = keep; }); }