2019-05-04 13:58:11 -05:00
|
|
|
<!--
|
|
|
|
- Amount.vue
|
|
|
|
- Copyright (c) 2019 thegrumpydictator@gmail.com
|
|
|
|
-
|
|
|
|
- This file is part of Firefly III.
|
|
|
|
-
|
|
|
|
- Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
- it under the terms of the GNU General Public License as published by
|
|
|
|
- the Free Software Foundation, either version 3 of the License, or
|
|
|
|
- (at your option) any later version.
|
|
|
|
-
|
|
|
|
- Firefly III is distributed in the hope that it will be useful,
|
|
|
|
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
- GNU General Public License for more details.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the GNU General Public License
|
|
|
|
- along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
2019-05-23 22:29:04 -05:00
|
|
|
<div class="form-group" v-bind:class="{ 'has-error': hasError()}">
|
2019-05-04 13:58:11 -05:00
|
|
|
<label class="col-sm-4 control-label" ref="cur"></label>
|
|
|
|
<div class="col-sm-8">
|
2019-05-23 22:29:04 -05:00
|
|
|
<input type="number" ref="amount" :value="value" @input="handleInput" step="any"
|
|
|
|
class="form-control"
|
2019-05-10 22:32:09 -05:00
|
|
|
name="amount[]"
|
2019-05-04 13:58:11 -05:00
|
|
|
title="amount" autocomplete="off" placeholder="Amount">
|
2019-05-23 22:29:04 -05:00
|
|
|
<ul class="list-unstyled" v-for="error in this.error">
|
|
|
|
<li class="text-danger">{{ error }}</li>
|
|
|
|
</ul>
|
2019-05-04 13:58:11 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: "Amount",
|
2019-05-23 22:29:04 -05:00
|
|
|
props: ['source', 'destination', 'transactionType', 'value', 'error'],
|
2019-05-04 13:58:11 -05:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
sourceAccount: this.source,
|
|
|
|
destinationAccount: this.destination,
|
2019-05-10 22:32:09 -05:00
|
|
|
type: this.transactionType
|
2019-05-04 13:58:11 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2019-05-10 22:32:09 -05:00
|
|
|
handleInput(e) {
|
|
|
|
this.$emit('input', this.$refs.amount.value);
|
|
|
|
},
|
2019-05-23 22:29:04 -05:00
|
|
|
hasError: function () {
|
|
|
|
return this.error.length > 0;
|
|
|
|
},
|
2019-05-04 13:58:11 -05:00
|
|
|
changeData: function () {
|
2019-06-01 13:38:18 -05:00
|
|
|
let transactionType = this.transactionType;
|
2019-05-25 02:17:46 -05:00
|
|
|
// reset of all are empty:
|
2019-06-01 13:38:18 -05:00
|
|
|
//console.log('Type "' + transactionType + '"');
|
2019-05-25 02:17:46 -05:00
|
|
|
//console.log('Source "' + this.source.name + '"');
|
|
|
|
//console.log('Dest "' + this.destination.name + '"');
|
2019-06-01 13:38:18 -05:00
|
|
|
if (!transactionType && !this.source.name && !this.destination.name) {
|
2019-05-25 02:17:46 -05:00
|
|
|
$(this.$refs.cur).text('');
|
|
|
|
return;
|
|
|
|
}
|
2019-06-01 13:38:18 -05:00
|
|
|
if(null === transactionType) {
|
|
|
|
transactionType = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('' === transactionType && '' !== this.source.currency_name) {
|
2019-05-25 02:17:46 -05:00
|
|
|
$(this.$refs.cur).text(this.source.currency_name);
|
|
|
|
return;
|
|
|
|
}
|
2019-06-01 13:38:18 -05:00
|
|
|
if ('' === transactionType && '' !== this.destination.currency_name) {
|
2019-05-25 02:17:46 -05:00
|
|
|
$(this.$refs.cur).text(this.destination.currency_name);
|
2019-05-04 13:58:11 -05:00
|
|
|
return;
|
|
|
|
}
|
2019-06-01 13:38:18 -05:00
|
|
|
if (transactionType === 'Withdrawal' || transactionType === 'Transfer') {
|
2019-05-25 02:17:46 -05:00
|
|
|
$(this.$refs.cur).text(this.source.currency_name);
|
2019-05-04 13:58:11 -05:00
|
|
|
return;
|
|
|
|
}
|
2019-06-01 13:38:18 -05:00
|
|
|
if (transactionType === 'Deposit') {
|
2019-05-25 02:17:46 -05:00
|
|
|
$(this.$refs.cur).text(this.destination.currency_name);
|
2019-05-04 13:58:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
source: function () {
|
|
|
|
this.changeData();
|
|
|
|
},
|
|
|
|
destination: function () {
|
|
|
|
this.changeData();
|
|
|
|
},
|
|
|
|
transactionType: function () {
|
|
|
|
this.changeData();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.changeData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|