2019-05-04 13:58:11 -05:00
|
|
|
<!--
|
|
|
|
- Category.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
|
|
|
<div class="col-sm-12">
|
|
|
|
<div class="input-group">
|
|
|
|
<input
|
|
|
|
ref="input"
|
2019-05-10 22:32:09 -05:00
|
|
|
:value="value"
|
|
|
|
@input="handleInput"
|
2019-05-04 13:58:11 -05:00
|
|
|
type="text"
|
|
|
|
placeholder="Category"
|
|
|
|
autocomplete="off"
|
|
|
|
data-role="input"
|
|
|
|
v-on:keypress="handleEnter"
|
|
|
|
class="form-control"
|
|
|
|
v-on:submit.prevent
|
|
|
|
name="category[]"
|
|
|
|
title="Category">
|
|
|
|
<span class="input-group-btn">
|
|
|
|
<button
|
|
|
|
v-on:click="clearCategory"
|
|
|
|
class="btn btn-default"
|
|
|
|
type="button"><i class="fa fa-trash-o"></i></button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<typeahead
|
|
|
|
:open-on-empty=true
|
|
|
|
:open-on-focus=true
|
|
|
|
v-on:input="selectedItem"
|
|
|
|
:async-src="categoryAutoCompleteURI"
|
|
|
|
v-model="name"
|
|
|
|
:target="target"
|
|
|
|
item-key="name"
|
|
|
|
></typeahead>
|
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: "Category",
|
|
|
|
props: {
|
2019-05-10 22:32:09 -05:00
|
|
|
value: String,
|
2019-05-04 13:58:11 -05:00
|
|
|
inputName: String,
|
2019-05-23 22:29:04 -05:00
|
|
|
error: Array,
|
2019-05-04 13:58:11 -05:00
|
|
|
accountName: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
categoryAutoCompleteURI: null,
|
|
|
|
name: null,
|
|
|
|
target: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ready() {
|
|
|
|
this.name = this.accountName;
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.target = this.$refs.input;
|
2019-08-01 22:25:24 -05:00
|
|
|
this.categoryAutoCompleteURI = document.getElementsByTagName('base')[0].href + "json/categories?search=";
|
2019-05-04 13:58:11 -05:00
|
|
|
},
|
|
|
|
methods: {
|
2019-05-23 22:29:04 -05:00
|
|
|
hasError: function () {
|
|
|
|
return this.error.length > 0;
|
|
|
|
},
|
2019-05-10 22:32:09 -05:00
|
|
|
handleInput(e) {
|
|
|
|
if (typeof this.$refs.input.value === 'string') {
|
|
|
|
this.$emit('input', this.$refs.input.value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.$emit('input', this.$refs.input.value.name);
|
|
|
|
|
|
|
|
},
|
2019-05-04 13:58:11 -05:00
|
|
|
clearCategory: function () {
|
|
|
|
//props.value = '';
|
|
|
|
this.name = '';
|
|
|
|
// some event?
|
|
|
|
this.$emit('clear:category')
|
|
|
|
},
|
|
|
|
selectedItem: function (e) {
|
|
|
|
if (typeof this.name === 'undefined') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// emit the fact that the user selected a type of account
|
|
|
|
// (influencing the destination)
|
|
|
|
this.$emit('select:category', this.name);
|
2019-05-10 22:32:09 -05:00
|
|
|
|
|
|
|
if (typeof this.name === 'string') {
|
|
|
|
this.$emit('input', this.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.$emit('input', this.name.name);
|
2019-05-04 13:58:11 -05:00
|
|
|
},
|
|
|
|
handleEnter: function (e) {
|
|
|
|
// todo feels sloppy
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|