Restructure code to rename a variable.

This commit is contained in:
James Cole
2018-06-30 05:21:21 +02:00
parent 2d7b7c2f3f
commit c9356c1237
50 changed files with 325 additions and 321 deletions

View File

@@ -24,16 +24,16 @@ $(document).ready(function () {
"use strict";
// destination account names:
if ($('input[name^="destination_account_name["]').length > 0) {
if ($('input[name^="destination_name["]').length > 0) {
$.getJSON('json/expense-accounts').done(function (data) {
$('input[name^="destination_account_name["]').typeahead({source: data, autoSelect: false});
$('input[name^="destination_name["]').typeahead({source: data, autoSelect: false});
});
}
// source account name
if ($('input[name^="source_account_name["]').length > 0) {
if ($('input[name^="source_name["]').length > 0) {
$.getJSON('json/revenue-accounts').done(function (data) {
$('input[name^="source_account_name["]').typeahead({source: data, autoSelect: false});
$('input[name^="source_name["]').typeahead({source: data, autoSelect: false});
});
}

View File

@@ -65,15 +65,15 @@ function setCommonAutocomplete() {
});
if ($('input[name="destination_account_name"]').length > 0) {
if ($('input[name="destination_name"]').length > 0) {
$.getJSON('json/expense-accounts').done(function (data) {
$('input[name="destination_account_name"]').typeahead({source: data, autoSelect: false});
$('input[name="destination_name"]').typeahead({source: data, autoSelect: false});
});
}
if ($('input[name="source_account_name"]').length > 0) {
if ($('input[name="source_name"]').length > 0) {
$.getJSON('json/revenue-accounts').done(function (data) {
$('input[name="source_account_name"]').typeahead({source: data, autoSelect: false});
$('input[name="source_name"]').typeahead({source: data, autoSelect: false});
});
}
@@ -160,8 +160,8 @@ function updateNativeAmount(data) {
* Instructions for transfers
*/
function getTransferExchangeInstructions() {
var sourceAccount = $('select[name="source_account_id"]').val();
var destAccount = $('select[name="destination_account_id"]').val();
var sourceAccount = $('select[name="source_id"]').val();
var destAccount = $('select[name="destination_id"]').val();
var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;
var destinationCurrency = accountInfo[destAccount].preferredCurrency;
@@ -180,8 +180,8 @@ function validateCurrencyForTransfer() {
return;
}
$('#source_amount_holder').show();
var sourceAccount = $('select[name="source_account_id"]').val();
var destAccount = $('select[name="destination_account_id"]').val();
var sourceAccount = $('select[name="source_id"]').val();
var destAccount = $('select[name="destination_id"]').val();
var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;
var sourceSymbol = currencyInfo[sourceCurrency].symbol;
var destinationCurrency = accountInfo[destAccount].preferredCurrency;
@@ -208,8 +208,8 @@ function validateCurrencyForTransfer() {
*
*/
function convertSourceToDestination() {
var sourceAccount = $('select[name="source_account_id"]').val();
var destAccount = $('select[name="destination_account_id"]').val();
var sourceAccount = $('select[name="source_id"]').val();
var destAccount = $('select[name="destination_id"]').val();
var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;
var destinationCurrency = accountInfo[destAccount].preferredCurrency;

View File

@@ -38,20 +38,17 @@ $(document).ready(function () {
// when user changes source account or destination, native currency may be different.
$('select[name="source_account_id"]').on('change', function() {
$('select[name="source_id"]').on('change', function() {
selectsDifferentSource();
// do something for transfers:
validateCurrencyForTransfer();
});
$('select[name="destination_account_id"]').on('change', function() {
$('select[name="destination_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);
@@ -74,7 +71,7 @@ function selectsDifferentSource() {
return;
}
// store original currency ID of the selected account in a separate var:
var sourceId = $('select[name="source_account_id"]').val();
var sourceId = $('select[name="source_id"]').val();
var sourceCurrency = accountInfo[sourceId].preferredCurrency;
$('input[name="source_account_currency"]').val(sourceCurrency);
console.log('selectsDifferenctSource(): Set source account currency to ' + sourceCurrency);
@@ -82,7 +79,7 @@ function selectsDifferentSource() {
// change input thing:
$('.currency-option[data-id="' + sourceCurrency + '"]').click();
$('[data-toggle="dropdown"]').parent().removeClass('open');
$('select[name="source_account_id"]').focus();
$('select[name="source_id"]').focus();
}
/**
@@ -96,7 +93,7 @@ function selectsDifferentDestination() {
return;
}
// store original currency ID of the selected account in a separate var:
var destinationId = $('select[name="destination_account_id"]').val();
var destinationId = $('select[name="destination_id"]').val();
var destinationCurrency = accountInfo[destinationId].preferredCurrency;
$('input[name="destination_account_currency"]').val(destinationCurrency);
console.log('selectsDifferentDestination(): Set destinationId account currency to ' + destinationCurrency);
@@ -104,7 +101,7 @@ function selectsDifferentDestination() {
// change input thing:
$('.currency-option[data-id="' + destinationCurrency + '"]').click();
$('[data-toggle="dropdown"]').parent().removeClass('open');
$('select[name="destination_account_id"]').focus();
$('select[name="destination_id"]').focus();
}
@@ -153,19 +150,19 @@ function updateForm() {
$('input[name="what"]').val(what);
var destName = $('#ffInput_destination_account_name');
var srcName = $('#ffInput_source_account_name');
var destName = $('#ffInput_destination_name');
var srcName = $('#ffInput_source_name');
switch (what) {
case 'withdrawal':
// show source_id and dest_name
document.getElementById('source_account_id_holder').style.display = 'block';
document.getElementById('destination_account_name_holder').style.display = 'block';
document.getElementById('source_id_holder').style.display = 'block';
document.getElementById('destination_name_holder').style.display = 'block';
// hide others:
document.getElementById('source_account_name_holder').style.display = 'none';
document.getElementById('destination_account_id_holder').style.display = 'none';
document.getElementById('source_name_holder').style.display = 'none';
document.getElementById('destination_id_holder').style.display = 'none';
document.getElementById('budget_id_holder').style.display = 'block';
// hide piggy bank:
@@ -185,12 +182,12 @@ function updateForm() {
break;
case 'deposit':
// show source_name and dest_id:
document.getElementById('source_account_name_holder').style.display = 'block';
document.getElementById('destination_account_id_holder').style.display = 'block';
document.getElementById('source_name_holder').style.display = 'block';
document.getElementById('destination_id_holder').style.display = 'block';
// hide others:
document.getElementById('source_account_id_holder').style.display = 'none';
document.getElementById('destination_account_name_holder').style.display = 'none';
document.getElementById('source_id_holder').style.display = 'none';
document.getElementById('destination_name_holder').style.display = 'none';
// hide budget
document.getElementById('budget_id_holder').style.display = 'none';
@@ -212,12 +209,12 @@ function updateForm() {
break;
case 'transfer':
// show source_id and dest_id:
document.getElementById('source_account_id_holder').style.display = 'block';
document.getElementById('destination_account_id_holder').style.display = 'block';
document.getElementById('source_id_holder').style.display = 'block';
document.getElementById('destination_id_holder').style.display = 'block';
// hide others:
document.getElementById('source_account_name_holder').style.display = 'none';
document.getElementById('destination_account_name_holder').style.display = 'none';
document.getElementById('source_name_holder').style.display = 'none';
document.getElementById('destination_name_holder').style.display = 'none';
// hide budget
document.getElementById('budget_id_holder').style.display = 'none';
@@ -288,10 +285,10 @@ function clickButton(e) {
*/
function getAccountId() {
if (what === "withdrawal") {
return $('select[name="source_account_id"]').val();
return $('select[name="source_id"]').val();
}
if (what === "deposit" || what === "transfer") {
return $('select[name="destination_account_id"]').val();
return $('select[name="destination_id"]').val();
}
return undefined;
}

View File

@@ -38,12 +38,12 @@ $(document).ready(function () {
$('#ffInput_amount').on('change', convertForeignToNative);
// respond to transfer changes:
$('#ffInput_source_account_id').on('change', function () {
$('#ffInput_source_id').on('change', function () {
validateCurrencyForTransfer();
// update the two source account currency ID fields (initial value):
initCurrencyIdValues();
});
$('#ffInput_destination_account_id').on('change', function () {
$('#ffInput_destination_id').on('change', function () {
validateCurrencyForTransfer();
// update the two source account currency ID fields (initial value):
initCurrencyIdValues();
@@ -77,9 +77,9 @@ function initCurrencyIdValues() {
$('input[name="destination_account_currency"]').val(currencyId);
return;
}
var sourceAccount = $('select[name="source_account_id"]').val();
var sourceAccount = $('select[name="source_id"]').val();
console.log('Source account is ' + sourceAccount);
var destAccount = $('select[name="destination_account_id"]').val();
var destAccount = $('select[name="destination_id"]').val();
console.log('Destination account is ' + destAccount);
var sourceCurrency = parseInt(accountInfo[sourceAccount].preferredCurrency);
@@ -134,10 +134,10 @@ function updateInitialPage() {
function getAccountId() {
console.log('in getAccountId()');
if (journal.transaction_type.type === "Withdrawal") {
return $('select[name="source_account_id"]').val();
return $('select[name="source_id"]').val();
}
if (journal.transaction_type.type === "Deposit") {
return $('select[name="destination_account_id"]').val();
return $('select[name="destination_id"]').val();
}
alert('Cannot handle ' + journal.transaction_type.type);

View File

@@ -191,12 +191,12 @@ function resetDivSplits() {
var input = $(v);
input.attr('name', 'transactions[' + i + '][transaction_description]');
});
// ends with ][destination_account_name]
// ends with ][destination_name]
$.each($('input[name$="][destination_name]"]'), function (i, v) {
var input = $(v);
input.attr('name', 'transactions[' + i + '][destination_name]');
});
// ends with ][source_account_name]
// ends with ][source_name]
$.each($('input[name$="][source_name]"]'), function (i, v) {
var input = $(v);
input.attr('name', 'transactions[' + i + '][source_name]');