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

125 lines
4.2 KiB
Vue
Raw Normal View History

2019-05-29 21:56:39 +02:00
<!--
- TransactionDescription.vue
2020-01-25 06:08:56 +01:00
- Copyright (c) 2019 james@firefly-iii.org
2019-05-29 21:56:39 +02:00
-
- This file is part of Firefly III (https://github.com/firefly-iii).
2019-05-29 21:56:39 +02:00
-
- 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.
2019-05-29 21:56:39 +02:00
-
- This program is distributed in the hope that it will be useful,
2019-05-29 21:56:39 +02:00
- 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.
2019-05-29 21:56:39 +02:00
-
- 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/>.
2019-05-29 21:56:39 +02:00
-->
2019-05-24 05:29:04 +02:00
<template>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}">
2019-12-30 15:24:02 +01:00
<div class="col-sm-12 text-sm">
{{ $t('firefly.description') }}
</div>
2019-05-24 05:29:04 +02:00
<div class="col-sm-12">
<div class="input-group">
<input
type="text"
class="form-control"
name="description[]"
:title="$t('firefly.description')"
v-on:keypress="handleEnter"
v-on:submit.prevent
ref="descr"
autocomplete="off"
v-bind:placeholder="$t('firefly.description')"
:value="value" @input="handleInput"
>
<span class="input-group-btn">
<button
v-on:click="clearDescription"
tabIndex="-1"
class="btn btn-default"
type="button"><i class="fa fa-trash-o"></i></button>
</span>
</div>
2019-08-22 19:07:01 +02:00
<typeahead
:open-on-empty=true
:open-on-focus=true
v-on:input="selectedItem"
:async-src="descriptionAutoCompleteURI"
v-model="name"
:target="target"
item-key="description"
></typeahead>
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 {
props: ['error', 'value', 'index'],
name: "TransactionDescription",
2019-08-22 19:07:01 +02:00
mounted() {
this.target = this.$refs.descr;
this.descriptionAutoCompleteURI = document.getElementsByTagName('base')[0].href + "api/v1/autocomplete/transactions?query=";
this.$refs.descr.focus();
2019-08-22 19:07:01 +02:00
},
2020-03-13 06:22:50 +01:00
components: {
},
2019-08-22 19:07:01 +02:00
data() {
return {
descriptionAutoCompleteURI: null,
name: null,
description: null,
target: null,
}
},
2019-05-24 05:29:04 +02:00
methods: {
2020-03-13 06:22:50 +01:00
search: function(input) {
return ['ab','cd'];
},
2019-05-24 05:29:04 +02:00
hasError: function () {
return this.error.length > 0;
},
clearDescription: function () {
//props.value = '';
2020-03-13 06:22:50 +01:00
this.description = '';
this.$refs.descr.value = '';
this.$emit('input', this.$refs.descr.value);
// some event?
this.$emit('clear:description')
},
2019-05-24 05:29:04 +02:00
handleInput(e) {
2019-08-22 19:10:57 +02:00
this.$emit('input', this.$refs.descr.value);
2019-08-22 19:07:01 +02:00
},
handleEnter: function (e) {
// todo feels sloppy
2019-08-22 19:07:01 +02:00
if (e.keyCode === 13) {
//e.preventDefault();
2019-08-22 19:07:01 +02:00
}
},
selectedItem: function (e) {
2019-08-27 06:45:35 +02:00
if (typeof this.name === 'undefined') {
return;
}
if (typeof this.name === 'string') {
return;
}
this.$refs.descr.value = this.name.description;
this.$emit('input', this.$refs.descr.value);
2019-08-22 19:07:01 +02:00
},
2019-05-24 05:29:04 +02:00
}
}
</script>
<style scoped>
</style>