Files
raven-client/ayanova/src/components/date-control.vue
2021-03-19 17:01:40 +00:00

142 lines
4.1 KiB
Vue

<template>
<div>
<v-row>
<template v-if="!readonly">
<v-col cols="12">
<v-dialog v-model="dlgdate" width="300px">
<template v-slot:activator="{ on }">
<v-text-field
v-on="on"
prepend-icon="$ayiCalendarAlt"
@click:prepend="dlgdate = true"
:value="dateValue"
:label="label"
:rules="rules"
readonly
:error="!!hasErrors"
:data-cy="'dtfpick:' + testId"
></v-text-field>
</template>
<v-date-picker
:value="dateValue"
@input="updateDateValue"
:locale="languageName"
:data-cy="'dpick:' + testId"
>
<v-btn text color="primary" @click="$emit('input', null)">{{
$ay.t("Delete")
}}</v-btn>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="dlgdate = false">{{
$ay.t("OK")
}}</v-btn>
</v-date-picker>
</v-dialog>
</v-col>
</template>
<template v-else>
<v-col cols="12">
<v-text-field
:value="readonlyFormat()"
:label="label"
readonly
prepend-icon="$ayiCalendarAlt"
></v-text-field>
</v-col>
</template>
</v-row>
<div class="v-messages theme--light error--text mt-n5" role="alert">
<div class="v-messages__wrapper">
<div class="v-messages__message">{{ allErrors() }}</div>
</div>
</div>
</div>
</template>
<script>
/* Xeslint-disable */
//******************************** NOTE: this control also captures the TIME even though it's DATE only, this is an intentional design decision to support field change to date or date AND time and is considered a display issue */
export default {
data: () => ({
dlgdate: false,
//cache display format stuff
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
languageName: window.$gz.locale.getResolvedLanguage()
// defaultLocale: window.$gz.locale.get BrowserFirstLanguage().split("-", 1)[0]
}),
props: {
label: { type: String, default: null },
rules: { type: Array, default: undefined },
errorMessages: { type: Array, default: null },
value: { type: String, default: null },
readonly: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
testId: { type: String, default: null }
},
computed: {
hasErrors() {
return this.errorMessages != null && this.errorMessages.length > 0;
},
timeValue() {
return window.$gz.locale.utcDateStringToLocal8601TimeOnlyString(
this.value,
this.timeZoneName
);
},
dateValue() {
return window.$gz.locale.utcDateStringToLocal8601DateOnlyString(
this.value,
this.timeZoneName
);
}
},
methods: {
allErrors() {
let ret = "";
if (this.errorMessages != null && this.errorMessages.length > 0) {
ret += this.errorMessages.toString();
}
return ret;
},
readonlyFormat() {
return window.$gz.locale.utcDateToShortDateLocalized(
this.value,
this.timeZoneName,
this.languageName
);
},
updateDateValue(v) {
this.updateValue(v, this.timeValue);
this.dlgdate = false;
},
updateValue(theDate, theTime) {
let vm = this;
if (!theDate) {
let v = new Date();
let fullYear = v.getFullYear();
let fullMonth = v.getMonth() + 1;
if (fullMonth < 10) {
fullMonth = "0" + fullMonth.toString();
}
let fullDay = v.getDate();
if (fullDay < 10) {
fullDay = "0" + fullDay.toString();
}
theDate = fullYear + "-" + fullMonth + "-" + fullDay;
}
if (!theTime) {
theTime = "00:00:00";
}
let ret = window.$gz.locale.localTimeDateStringToUTC8601String(
theDate + "T" + theTime,
vm.timeZoneName
);
vm.$emit("input", ret);
}
}
};
</script>