diff --git a/public/js/ff/transactions/single/create.js b/public/js/ff/transactions/single/create.js index d12878a468..7ecf067652 100644 --- a/public/js/ff/transactions/single/create.js +++ b/public/js/ff/transactions/single/create.js @@ -23,7 +23,7 @@ $(document).ready(function () { "use strict"; - // hide ALL exchange things and AMOUNT things + // hide ALL exchange things and AMOUNT fields $('#exchange_rate_instruction_holder').hide(); $('#native_amount_holder').hide(); $('#amount_holder').hide(); @@ -38,8 +38,19 @@ $(document).ready(function () { // when user changes source account or destination, native currency may be different. - $('select[name="source_account_id"]').on('change', updateNativeCurrency); - $('select[name="destination_account_id"]').on('change', updateNativeCurrency); + $('select[name="source_account_id"]').on('change', function() { + selectsDifferentSource(); + // do something for transfers: + validateCurrencyForTransfer(); + }); + $('select[name="destination_account_id"]').on('change', function() { + selectsDifferentDestination(); + // do something for transfers: + validateCurrencyForTransfer(); + }); + + //$('select[name="source_account_id"]').on('change', updateNativeCurrency); + //$('select[name="destination_account_id"]').on('change', updateNativeCurrency); // convert foreign currency to native currency (when input changes, exchange rate) $('#ffInput_amount').on('change', convertForeignToNative); @@ -52,6 +63,55 @@ $(document).ready(function () { $('#ffInput_description').focus(); }); +/** + * The user selects a different source account. Applies to withdrawals + * and transfers. + */ +function selectsDifferentSource() { + if (what === "deposit") { + console.log('User is making a deposit. Don\'t bother with source.'); + $('input[name="source_account_currency"]').val("0"); + return; + } + // store original currency ID of the selected account in a separate var: + var sourceId = $('select[name="source_account_id"]').val(); + var sourceCurrency = accountInfo[sourceId].preferredCurrency; + $('input[name="source_account_currency"]').val(sourceCurrency); + console.log('Set source account currency to ' + sourceCurrency); + + // change input thing: + $('.currency-option[data-id="' + sourceCurrency + '"]').click(); + $('[data-toggle="dropdown"]').parent().removeClass('open'); + $('select[name="source_account_id"]').focus(); + + return; +} + +/** + * The user selects a different source account. Applies to withdrawals + * and transfers. + */ +function selectsDifferentDestination() { + if (what === "withdrawal") { + console.log('User is making a withdrawal. Don\'t bother with destination.'); + $('input[name="destination_account_currency"]').val("0"); + return; + } + // store original currency ID of the selected account in a separate var: + var destinationId = $('select[name="destination_account_id"]').val(); + var destinationCurrency = accountInfo[destinationId].preferredCurrency; + $('input[name="destination_account_currency"]').val(destinationCurrency); + console.log('Set destinationId account currency to ' + destinationCurrency); + + // change input thing: + $('.currency-option[data-id="' + destinationCurrency + '"]').click(); + $('[data-toggle="dropdown"]').parent().removeClass('open'); + $('select[name="destination_account_id"]').focus(); + + return; +} + + /** * This function generates a small helper text to explain the user * that they have selected a foreign currency. @@ -68,31 +128,6 @@ function getExchangeInstructions() { return text; } -/** - * There is an input that shows the currency symbol that is native to the selected - * acccount. So when the user changes the selected account, the native currency is updated: - */ -function updateNativeCurrency(useAccountCurrency) { - var nativeCurrencyId; - if (useAccountCurrency) { - var newAccountId = getAccountId(); - nativeCurrencyId = accountInfo[newAccountId].preferredCurrency; - } - if (!useAccountCurrency) { - nativeCurrencyId = overruleCurrency; - } - - $('.currency-option[data-id="' + nativeCurrencyId + '"]').click(); - $('[data-toggle="dropdown"]').parent().removeClass('open'); - if (what === 'withdrawal') { - $('select[name="source_account_id"]').focus(); - } - if (what === 'deposit') { - $('select[name="destination_account_id"]').focus(); - } - validateCurrencyForTransfer(); -} - /** * */ @@ -202,8 +237,14 @@ function updateForm() { break; } // get instructions all the time. - updateNativeCurrency(useAccountCurrency); + //updateNativeCurrency(useAccountCurrency); + console.log('End of update form'); + selectsDifferentSource(); + selectsDifferentDestination(); selectsForeignCurrency(); + + // do something for transfers: + validateCurrencyForTransfer(); } /** diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig index b793c6b9d7..d1a14908cb 100644 --- a/resources/views/accounts/edit.twig +++ b/resources/views/accounts/edit.twig @@ -49,7 +49,7 @@ {% endif %} {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }} - {{ ExpandedForm.checkbox('active','1') }} + {{ ExpandedForm.checkbox('active','1', preFilled.active) }} diff --git a/resources/views/transactions/single/create.twig b/resources/views/transactions/single/create.twig index 91fa5a7b1a..e8f2f7bde5 100644 --- a/resources/views/transactions/single/create.twig +++ b/resources/views/transactions/single/create.twig @@ -203,6 +203,8 @@ + + {% endblock %}