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

83 lines
2.9 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">
<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">
2019-08-23 06:10:03 +02: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",
2019-05-24 05:29:04 +02:00
props: ['transactionType', 'value', 'error'],
mounted() {
this.loadBudgets();
2019-09-06 16:29:52 +02:00
// console.log('budget value');
// console.log(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: '(no budget)',
id: 0,
}
];
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>