portfolio-edit: add button writes position to localStorage
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
ee6966399c
commit
58576a86fc
1 changed files with 52 additions and 0 deletions
|
|
@ -124,4 +124,56 @@
|
|||
tickerInput.addEventListener('blur', validateTicker);
|
||||
document.getElementById('pf-add-qty').addEventListener('input', updateSubmitState);
|
||||
document.getElementById('pf-add-cost').addEventListener('input', updateSubmitState);
|
||||
|
||||
// ---- Add button → localStorage merge -------------------------------
|
||||
|
||||
function resetForm() {
|
||||
tickerInput.value = '';
|
||||
document.getElementById('pf-add-qty').value = '';
|
||||
document.getElementById('pf-add-cost').value = '';
|
||||
document.getElementById('pf-add-date').value = '';
|
||||
validated = null;
|
||||
setStatus(tickerStatus, '', '');
|
||||
costCurrencyEl.textContent = '';
|
||||
clearDuplicateWarning();
|
||||
updateSubmitState();
|
||||
tickerInput.focus();
|
||||
}
|
||||
|
||||
function addPosition() {
|
||||
if (submitBtn.disabled) return;
|
||||
const qty = parseFloat(document.getElementById('pf-add-qty').value);
|
||||
const cost = parseFloat(document.getElementById('pf-add-cost').value);
|
||||
const sym = validated.symbol;
|
||||
|
||||
const pie = window.CassandraPortfolio.loadPie() || {
|
||||
pie_name: null,
|
||||
base_currency: 'GBP',
|
||||
positions: [],
|
||||
totals: {invested: 0, value: 0, result: 0},
|
||||
warnings: [],
|
||||
};
|
||||
pie.positions = pie.positions || [];
|
||||
pie.positions.push({
|
||||
yahoo_ticker: sym,
|
||||
t212_slice: sym, // shared shape with CSV path
|
||||
name: validated.name || sym,
|
||||
qty: qty,
|
||||
avg_cost: cost,
|
||||
currency: validated.currency || 'USD',
|
||||
});
|
||||
window.CassandraPortfolio.savePie(pie);
|
||||
window.CassandraPortfolio.mountAndRender();
|
||||
resetForm();
|
||||
}
|
||||
|
||||
submitBtn.addEventListener('click', addPosition);
|
||||
|
||||
// Submit on Enter from any input within the form.
|
||||
form.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter' && !submitBtn.disabled) {
|
||||
e.preventDefault();
|
||||
addPosition();
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue