Files
mixtape/zero.Backoffice.UI/old_app/components/pickers/dateRangePicker/daterangepicker.vue
T

162 lines
3.7 KiB
Vue
Raw Normal View History

2020-08-17 10:59:13 +02:00
<template>
<div class="ui-daterangepicker" :class="{'is-disabled': disabled }">
2021-12-23 14:39:00 +01:00
<button v-if="!inline" type="button" class="ui-linktext" @click="schedule" v-localize="scheduleLocalize" :disabled="disabled"></button>
2021-10-08 12:41:00 +02:00
<div v-if="inline && value" class="ui-daterangepicker-inline">
2021-09-12 13:00:07 +02:00
<div class="ui-daterangepicker-group">
<ui-property :vertical="true">
<ui-datepicker v-model="value.from" :time="time" />
</ui-property>
</div>
<div class="ui-daterangepicker-group" v-if="rangeEnd">
<ui-property :vertical="true">
<ui-datepicker v-model="value.to" :time="time" />
</ui-property>
</div>
</div>
2020-08-17 10:59:13 +02:00
</div>
</template>
<script>
import Strings from 'zero/helpers/strings.js';
2020-08-17 10:59:13 +02:00
import { extend as _extend } from 'underscore';
2020-11-01 22:20:29 +01:00
import DaterangepickerOverlay from './overlay.vue';
import Overlay from 'zero/helpers/overlay.js';
2020-08-17 10:59:13 +02:00
import dayjs from 'dayjs';
const DATETIME_FORMAT = 'DD.MM.YY HH:mm';
const DATE_FORMAT = 'DD.MM.YY';
export default {
name: 'uiDaterangepicker',
components: { DaterangepickerOverlay },
props: {
value: {
type: Object,
default: {
from: null,
to: null
}
},
disabled: {
type: Boolean,
default: false
},
format: {
type: String,
default: null
},
time: {
type: Boolean,
default: false,
},
2020-10-20 16:00:55 +02:00
maxDate: {
2020-08-17 10:59:13 +02:00
type: [String, Date],
default: null
},
2020-10-20 16:00:55 +02:00
minDate: {
2020-08-17 10:59:13 +02:00
type: [String, Date],
default: null
},
2020-10-20 16:00:55 +02:00
fromLabel: {
2020-08-17 10:59:13 +02:00
type: String,
2021-09-12 13:00:07 +02:00
default: '@ui.date.range_from'
2020-08-17 10:59:13 +02:00
},
2020-10-20 16:00:55 +02:00
toLabel: {
2020-08-17 10:59:13 +02:00
type: String,
2021-09-12 13:00:07 +02:00
default: '@ui.date.range_to'
2020-08-17 10:59:13 +02:00
},
amPm: {
type: Boolean,
default: false
},
inline: {
type: Boolean,
default: false
},
2020-12-05 15:33:52 +01:00
rangeEnd: {
type: Boolean,
default: true
},
2020-08-17 10:59:13 +02:00
options: {
type: Object,
default: () => { }
}
},
data: () => ({
id: null,
output: null,
pickerOptions: {}
}),
computed: {
scheduleLocalize()
{
return {
2021-01-16 16:52:50 +01:00
key: !this.value || (!this.value.from && !this.value.to) ? '@ui.date.set' :
2020-08-17 10:59:13 +02:00
(this.value.from && !this.value.to ? '@ui.date.x' :
(!this.value.from && this.value.to ? '@ui.date.y' : '@ui.date.xtoy')),
tokens: {
2021-03-16 13:57:52 +01:00
x: this.value ? Strings.date(this.value.from, this.format || (this.time ? DATETIME_FORMAT : DATE_FORMAT)) : null,
y: this.value ? Strings.date(this.value.to, this.format || (this.time ? DATETIME_FORMAT : DATE_FORMAT)) : null
2020-08-17 10:59:13 +02:00
}
};
}
},
created()
{
this.id = 'daterangepicker-' + Strings.guid();
},
methods: {
schedule()
{
Overlay.open({
component: DaterangepickerOverlay,
options: {
format: this.format,
time: this.time,
2020-10-20 16:00:55 +02:00
max: this.maxDate,
min: this.minDate,
fromText: this.fromLabel,
toText: this.toLabel,
2020-12-05 15:33:52 +01:00
amPm: this.amPm,
rangeEnd: this.rangeEnd
2020-08-17 10:59:13 +02:00
},
model: {
from: this.value.from,
to: this.value.to
},
}).then(res =>
{
this.$emit('change', res);
this.$emit('input', res);
}, () => { });
}
}
}
</script>
<style lang="scss">
2021-12-23 14:39:00 +01:00
.ui-daterangepicker.is-primary .ui-linktext
{
color: var(--color-primary);
2020-09-05 17:35:47 +02:00
font-weight: 700;
2020-09-07 01:26:15 +02:00
text-decoration-color: var(--color-primary) !important;
}
2021-09-12 13:00:07 +02:00
.ui-daterangepicker-inline
{
display: flex;
gap: var(--padding-s);
}
2020-08-17 10:59:13 +02:00
</style>