2020-12-29 08:33:46 +01:00
|
|
|
<!--
|
|
|
|
- TransactionDate.vue
|
|
|
|
- Copyright (c) 2020 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>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="text-xs d-none d-lg-block d-xl-block">
|
|
|
|
{{ $t('firefly.date_and_time') }}
|
|
|
|
</div>
|
|
|
|
<div class="input-group">
|
|
|
|
<input
|
|
|
|
ref="date"
|
2021-02-22 18:43:26 +01:00
|
|
|
v-model="dateStr"
|
2021-02-26 06:39:20 +01:00
|
|
|
:class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"
|
2020-12-29 08:33:46 +01:00
|
|
|
:disabled="index > 0"
|
2021-02-26 06:39:20 +01:00
|
|
|
:placeholder="dateStr"
|
|
|
|
:title="$t('firefly.date')"
|
2020-12-29 08:33:46 +01:00
|
|
|
autocomplete="off"
|
|
|
|
name="date[]"
|
2021-02-26 06:39:20 +01:00
|
|
|
type="date"
|
2020-12-29 08:33:46 +01:00
|
|
|
>
|
|
|
|
<input
|
|
|
|
ref="time"
|
2021-02-22 18:43:26 +01:00
|
|
|
v-model="timeStr"
|
2021-02-26 06:39:20 +01:00
|
|
|
:class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"
|
2020-12-29 08:33:46 +01:00
|
|
|
:disabled="index > 0"
|
2021-02-26 06:39:20 +01:00
|
|
|
:placeholder="timeStr"
|
|
|
|
:title="$t('firefly.time')"
|
2020-12-29 08:33:46 +01:00
|
|
|
autocomplete="off"
|
|
|
|
name="time[]"
|
2021-02-26 06:39:20 +01:00
|
|
|
type="time"
|
2020-12-29 08:33:46 +01:00
|
|
|
>
|
|
|
|
</div>
|
2021-01-31 07:26:52 +01:00
|
|
|
<span v-if="errors.length > 0">
|
|
|
|
<span v-for="error in errors" class="text-danger small">{{ error }}<br/></span>
|
|
|
|
</span>
|
2020-12-29 08:33:46 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
2021-02-22 18:43:26 +01:00
|
|
|
props: ['index', 'errors', 'date', 'time'],
|
2020-12-29 08:33:46 +01:00
|
|
|
name: "TransactionDate",
|
2021-02-22 18:43:26 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
localDate: this.date,
|
|
|
|
localTime: this.time
|
|
|
|
}
|
2020-12-29 08:33:46 +01:00
|
|
|
},
|
2021-02-22 18:43:26 +01:00
|
|
|
methods: {},
|
2020-12-29 08:33:46 +01:00
|
|
|
computed: {
|
2021-02-22 18:43:26 +01:00
|
|
|
dateStr: {
|
2020-12-29 08:33:46 +01:00
|
|
|
get() {
|
2021-02-22 18:43:26 +01:00
|
|
|
if (this.localDate instanceof Date && !isNaN(this.localDate)) {
|
|
|
|
return this.localDate.toISOString().split('T')[0];
|
2021-01-31 07:26:52 +01:00
|
|
|
}
|
|
|
|
return '';
|
2020-12-29 08:33:46 +01:00
|
|
|
},
|
|
|
|
set(value) {
|
2021-01-17 19:52:53 +01:00
|
|
|
// bit of a hack but meh.
|
2021-02-22 18:43:26 +01:00
|
|
|
if ('' === value) {
|
|
|
|
// reset to today
|
|
|
|
this.localDate = new Date();
|
|
|
|
this.$emit('set-date', {date: this.localDate});
|
|
|
|
return;
|
2021-02-10 06:55:56 +01:00
|
|
|
}
|
2021-02-22 18:43:26 +01:00
|
|
|
this.localDate = new Date(value);
|
|
|
|
this.$emit('set-date', {date: this.localDate});
|
2020-12-29 08:33:46 +01:00
|
|
|
}
|
|
|
|
},
|
2021-02-22 18:43:26 +01:00
|
|
|
timeStr: {
|
2020-12-29 08:33:46 +01:00
|
|
|
get() {
|
2021-02-22 18:43:26 +01:00
|
|
|
if (this.localTime instanceof Date && !isNaN(this.localTime)) {
|
|
|
|
return ('0' + this.localTime.getHours()).slice(-2) + ':' + ('0' + this.localTime.getMinutes()).slice(-2) + ':' + ('0' + this.localTime.getSeconds()).slice(-2);
|
2021-01-31 07:26:52 +01:00
|
|
|
}
|
|
|
|
return '';
|
2020-12-29 08:33:46 +01:00
|
|
|
},
|
|
|
|
set(value) {
|
2021-02-22 18:43:26 +01:00
|
|
|
if ('' === value) {
|
|
|
|
this.localTime.setHours(0);
|
|
|
|
this.localTime.setMinutes(0);
|
|
|
|
this.localTime.setSeconds(0);
|
|
|
|
this.$emit('set-time', {time: this.localTime});
|
2021-02-10 06:55:56 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-17 19:52:53 +01:00
|
|
|
// bit of a hack but meh.
|
2021-02-22 18:43:26 +01:00
|
|
|
let current = new Date(this.localTime.getTime());
|
2021-01-17 19:52:53 +01:00
|
|
|
let parts = value.split(':');
|
|
|
|
current.setHours(parseInt(parts[0]));
|
|
|
|
current.setMinutes(parseInt(parts[1]));
|
|
|
|
current.setSeconds(parseInt(parts[2]));
|
2021-02-22 18:43:26 +01:00
|
|
|
this.localTime = current;
|
|
|
|
this.$emit('set-time', {time: this.localTime});
|
2020-12-29 08:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|