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

107 lines
3.6 KiB
Vue
Raw Normal View History

2019-05-29 21:56:39 +02:00
<!--
- Budget.vue
2020-01-25 06:08:56 +01:00
- Copyright (c) 2019 james@firefly-iii.org
-
- 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">
2020-07-19 17:24:29 +02:00
<select
name="budget[]"
ref="budget"
v-model="selected"
@input="handleInput"
2020-07-19 17:24:29 +02:00
v-on:change="signalChange"
:title="$t('firefly.budget')"
class="form-control"
v-if="this.budgets.length > 0">
2020-07-19 17:24:29 +02:00
<option v-for="cBudget in this.budgets"
:label="cBudget.name"
:value="cBudget.id">{{cBudget.name}}
</option>
</select>
2020-03-13 06:22:50 +01:00
<p class="help-block" v-if="this.budgets.length === 1" v-html="$t('firefly.no_budget_pointer')"></p>
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: {
2020-07-19 17:24:29 +02:00
transactionType: String,
value: {
2020-07-19 17:24:29 +02:00
type: [String, Number],
default: 0
},
error: Array,
no_budget: String,
},
mounted() {
this.loadBudgets();
},
data() {
return {
selected: this.value,
budgets: [],
}
},
methods: {
// Fixes edit change budget not updating on every broswer
signalChange: function(e) {
this.$emit('input', this.$refs.budget.value);
},
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 () {
2020-07-26 19:30:24 +02:00
let URI = document.getElementsByTagName('base')[0].href + 'api/v1/autocomplete/budgets?limit=1337';
axios.get(URI, {}).then((res) => {
2020-02-14 08:43:57 +01:00
this.budgets = [
{
name: this.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>
2020-07-19 17:24:29 +02:00
</style>