Expand view + JS for view to cope with new factory

This commit is contained in:
James Cole
2018-02-24 09:17:48 +01:00
parent 166cdad58b
commit 6fe5b50410
3 changed files with 73 additions and 30 deletions

View File

@@ -23,7 +23,7 @@
$(document).ready(function () { $(document).ready(function () {
"use strict"; "use strict";
// hide ALL exchange things and AMOUNT things // hide ALL exchange things and AMOUNT fields
$('#exchange_rate_instruction_holder').hide(); $('#exchange_rate_instruction_holder').hide();
$('#native_amount_holder').hide(); $('#native_amount_holder').hide();
$('#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. // when user changes source account or destination, native currency may be different.
$('select[name="source_account_id"]').on('change', updateNativeCurrency); $('select[name="source_account_id"]').on('change', function() {
$('select[name="destination_account_id"]').on('change', updateNativeCurrency); 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) // convert foreign currency to native currency (when input changes, exchange rate)
$('#ffInput_amount').on('change', convertForeignToNative); $('#ffInput_amount').on('change', convertForeignToNative);
@@ -52,6 +63,55 @@ $(document).ready(function () {
$('#ffInput_description').focus(); $('#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 * This function generates a small helper text to explain the user
* that they have selected a foreign currency. * that they have selected a foreign currency.
@@ -68,31 +128,6 @@ function getExchangeInstructions() {
return text; 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; break;
} }
// get instructions all the time. // get instructions all the time.
updateNativeCurrency(useAccountCurrency); //updateNativeCurrency(useAccountCurrency);
console.log('End of update form');
selectsDifferentSource();
selectsDifferentDestination();
selectsForeignCurrency(); selectsForeignCurrency();
// do something for transfers:
validateCurrencyForTransfer();
} }
/** /**

View File

@@ -49,7 +49,7 @@
{% endif %} {% endif %}
{{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }} {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
{{ ExpandedForm.checkbox('active','1') }} {{ ExpandedForm.checkbox('active','1', preFilled.active) }}
</div> </div>
</div> </div>

View File

@@ -203,6 +203,8 @@
</div> </div>
</div> </div>
</div> </div>
<input type="hidden" name="source_account_currency" value="0" />
<input type="hidden" name="destination_account_currency" value="0" />
</form> </form>
{% endblock %} {% endblock %}