Files
firefly-iii/resources/assets/js/components/transactions/Budget.vue

87 lines
3.1 KiB
Vue
Raw Normal View History

2019-05-29 21:56:39 +02:00
<!--
- Budget.vue
- Copyright (c) 2019 thegrumpydictator@gmail.com
-
- This file is part of Firefly III (https://github.com/firefly-iii).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program 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 Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<template>
2019-05-24 05:29:04 +02:00
<div class="form-group"
v-bind:class="{ 'has-error': hasError()}"
2019-08-18 09:07:08 +02:00
v-if="typeof this.transactionType === 'undefined' || this.transactionType === 'withdrawal' || this.transactionType === 'Withdrawal' || this.transactionType === '' || null === this.transactionType">
2019-12-30 15:24:02 +01:00
<div class="col-sm-12 text-sm">
{{ $t('firefly.budget') }}
</div>
<div class="col-sm-12">
2019-08-23 06:10:03 +02:00
<select name="budget[]" ref="budget" v-model="value" @input="handleInput" class="form-control"
2019-05-24 05:29:04 +02:00
v-if="this.budgets.length > 0">
2020-01-03 11:30:21 +01:00
<option v-for="cBudget in this.budgets" :label="cBudget.name" :value="cBudget.id">{{cBudget.name}}</option>
</select>
2019-05-24 05:29:04 +02:00
<ul class="list-unstyled" v-for="error in this.error">
<li class="text-danger">{{ error }}</li>
</ul>
</div>
</div>
</template>
<script>
export default {
name: "Budget",
props: ['transactionType', 'value', 'error','no_budget'],
mounted() {
this.loadBudgets();
2020-01-03 11:30:21 +01:00
//this.value = null === this.value ? 0 : this.value;
},
data() {
return {
budgets: [],
}
},
methods: {
2019-05-11 05:32:09 +02:00
handleInput(e) {
this.$emit('input', this.$refs.budget.value);
},
2019-05-24 05:29:04 +02:00
hasError: function () {
return this.error.length > 0;
},
loadBudgets: function () {
let URI = document.getElementsByTagName('base')[0].href + "json/budgets";
axios.get(URI, {}).then((res) => {
this.budgets = [
{
name: this.no_budget,
id: 0,
2020-01-03 11:30:21 +01:00
},
{
name: this.no_budget,
id: null,
}
];
for (const key in res.data) {
if (res.data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
this.budgets.push(res.data[key]);
}
}
});
}
}
}
</script>
<style scoped>
</style>