This commit is contained in:
James Cole
2018-10-20 09:16:35 +02:00
parent dd0cc2d173
commit 78cd1629de
2 changed files with 52 additions and 2 deletions

View File

@@ -164,7 +164,9 @@ function getTransferExchangeInstructions() {
* When the transaction to create is a transfer some more checks are necessary.
*/
function validateCurrencyForTransfer() {
console.log('in validateCurrencyForTransfer()');
if (what !== "transfer") {
console.log('is not a transfer, so return.');
return;
}
$('#source_amount_holder').show();

View File

@@ -37,16 +37,37 @@ $(document).ready(function () {
});
$('#ffInput_amount').on('change', convertForeignToNative);
// respond to transfer changes:
$('#ffInput_source_id').on('change', function () {
// respond to account changes:
$('#ffInput_source_id').on('change', function (e) {
console.log('Event: #ffInput_source_id::change');
validateCurrencyForTransfer();
// update the two source account currency ID fields (initial value):
initCurrencyIdValues();
// call to selectsForeignCurrency
console.log('Extra call to selectsForeignCurrency()');
selectsForeignCurrency();
// update "source_account_currency".
updateSourceAccountCurrency();
});
$('#ffInput_destination_id').on('change', function () {
console.log('Event: #ffInput_destination_id::change');
validateCurrencyForTransfer();
// update the two source account currency ID fields (initial value):
initCurrencyIdValues();
// call to selectsForeignCurrency
console.log('Extra call to selectsForeignCurrency()');
selectsForeignCurrency();
// update "destination_account_currency".
updateDestinationAccountCurrency();
});
// convert source currency to destination currency (slightly different routine for transfers)
@@ -57,10 +78,37 @@ $(document).ready(function () {
});
/**
* Updates the currency ID of the hidden source account field
* to match the selected account.
*/
function updateSourceAccountCurrency() {
var accountId = $('#ffInput_source_id').val();
var currency = parseInt(accountInfo[accountId].preferredCurrency);
console.log('Now in updateSourceAccountCurrency() for account #' + accountId);
console.log('Preferred currency for this account is #' + currency);
$('input[name="source_account_currency"]').val(currency);
}
/**
* Updates the currency ID of the hidden destination account field
* to match the selected account.
*/
function updateDestinationAccountCurrency() {
var accountId = $('#ffInput_destination_id').val();
var currency = parseInt(accountInfo[accountId].preferredCurrency);
console.log('Now in updateDestinationAccountCurrency() for account #' + accountId);
console.log('Preferred currency for this account is #' + currency);
$('input[name="destination_account_currency"]').val(currency);
}
/**
* Fills two hidden variables with the correct currency ID.
*/
function initCurrencyIdValues() {
console.log('in initCurrencyIdValues()');
var currencyId;
if (journal.transaction_type.type === "Withdrawal") {
// update source from page load info: