diff --git a/frontend/src/components/transactions/Create.vue b/frontend/src/components/transactions/Create.vue index 3fa9cdf4f8..10a5caf589 100644 --- a/frontend/src/components/transactions/Create.vue +++ b/frontend/src/components/transactions/Create.vue @@ -35,18 +35,7 @@ v-on:uploaded-attachments="uploadedAttachment($event)" v-on:set-description="storeField($event)" v-on:set-marker-location="storeLocation($event)" - v-on:set-source-account-id="storeAccountValue(index, 'source', 'id', $event)" - v-on:set-source-account-name="storeAccountValue(index, 'source', 'name', $event)" - v-on:set-source-account-type="storeAccountValue(index, 'source', 'type', $event)" - v-on:set-source-account-currency-id="storeAccountValue(index, 'source', 'currency_id', $event)" - v-on:set-source-account-currency-code="storeAccountValue(index, 'source', 'currency_code', $event)" - v-on:set-source-account-currency-symbol="storeAccountValue(index, 'source', 'currency_symbol', $event)" - v-on:set-destination-account-id="storeAccountValue(index, 'destination', 'id', $event)" - v-on:set-destination-account-name="storeAccountValue(index, 'destination', 'name', $event)" - v-on:set-destination-account-type="storeAccountValue(index, 'destination', 'type', $event)" - v-on:set-destination-account-currency-id="storeAccountValue(index, 'destination', 'currency_id', $event)" - v-on:set-destination-account-currency-code="storeAccountValue(index, 'destination', 'currency_code', $event)" - v-on:set-destination-account-currency-symbol="storeAccountValue(index, 'destination', 'currency_symbol', $event)" + v-on:set-account="storeAccountValue($event)" v-on:switch-accounts="switchAccounts($event)" v-on:set-amount="storeAmount(index, $event)" v-on:set-foreign-currency-id="storeForeignCurrencyId(index, $event)" @@ -399,16 +388,18 @@ export default { /** * Responds to changed account. */ - storeAccountValue: function (index, direction, field, value) { - // depending on these account values - let key = direction + '_account_' + field; - //console.log('storeAccountValue(' + index + ', "' + direction + '", "' + field + '", "' + key + '") = "' + value + '"'); - this.updateField({index: index, field: key, value: value}); - if ('type' === field) { - this.calculateTransactionType(index); - } + storeAccountValue: function (payload) { + this.updateField({index: payload.index, field: payload.direction + '_account_id', value: payload.id}); + this.updateField({index: payload.index, field: payload.direction + '_account_type', value: payload.type}); + this.updateField({index: payload.index, field: payload.direction + '_account_name', value: payload.name}); + + this.updateField({index: payload.index, field: payload.direction + '_account_currency_id', value: payload.currency_id}); + this.updateField({index: payload.index, field: payload.direction + '_account_currency_code', value: payload.currency_code}); + this.updateField({index: payload.index, field: payload.direction + '_account_currency_symbol', value: payload.currency_symbol}); + + this.calculateTransactionType(payload.index); }, - storeField: function(payload) { + storeField: function (payload) { this.updateField(payload); }, storeDescription: function (index, value) { diff --git a/frontend/src/components/transactions/TransactionAccount.vue b/frontend/src/components/transactions/TransactionAccount.vue index 57d5f97dc8..c992869e77 100644 --- a/frontend/src/components/transactions/TransactionAccount.vue +++ b/frontend/src/components/transactions/TransactionAccount.vue @@ -135,42 +135,45 @@ export default { }, watch: { selectedAccount: function (value) { - //console.log('Emit on selected account'); + console.log('Emit on selected account'); this.selectedAccountTrigger = true; this.account = value; - this.$emit(this.emitAccountId, value.id); - this.$emit(this.emitAccountType, value.type); - this.$emit(this.emitAccountName, value.name); - this.$emit(this.emitAccountCurrencyId, value.currency_id); - this.$emit(this.emitAccountCurrencyCode, value.currency_code); - this.$emit(this.emitAccountCurrencySymbol, value.currency_symbol); - //this.$emit(this.emitAccount, value); + + this.$emit('set-account', + { + index: this.index, + direction: this.direction, + id: value.id, + type: value.type, + name: value.name, + currency_id: value.currency_id, + currency_code: value.currency_code, + currency_symbol: value.currency_symbol, + } + ); this.accountName = this.account.name_with_balance; - - // call method to set what the opposing accounts should be. - // and what the - }, accountName: function (value) { if (false === this.selectedAccountTrigger) { console.log('Save to change name!'); - this.$emit(this.emitAccountId, null); - this.$emit(this.emitAccountType, null); - this.$emit(this.emitAccountName, value); - this.$emit(this.emitAccountCurrencyId, null); - this.$emit(this.emitAccountCurrencyCode, null); - this.$emit(this.emitAccountCurrencySymbol, null); - //this.$emit(this.emitAccount, {name: value, type: null, id: null, currency_id: null, currency_code: null, currency_symbol: null}); - // also reset local account thing, but dont be weird about it + this.$emit('set-account', + { + index: this.index, + direction: this.direction, + id: null, + type: null, + name: value, + currency_id: null, + currency_code: null, + currency_symbol: null, + } + ); this.accountTrigger = false; this.account = {name: value, type: null, id: null, currency_id: null, currency_code: null, currency_symbol: null}; - } this.selectedAccountTrigger = false; }, account: function (value) { - //this.updateField({field: this.accountKey, index: this.index, value: value}); - // set the opposing account allowed set. let opposingAccounts = []; let type = value.type ? value.type : 'no_type'; if ('undefined' !== typeof this.allowedOpposingTypes[this.direction]) {