2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-11 08:10:29 +00:00
|
|
|
<span ref="container" :id="d_id" :class="cx('root')" :style="sx('root')" v-bind="ptmi('root')">
|
2024-03-19 14:14:13 +00:00
|
|
|
<InputText
|
2022-09-14 11:26:01 +00:00
|
|
|
v-if="!inline"
|
|
|
|
:ref="inputRef"
|
|
|
|
:id="inputId"
|
|
|
|
role="combobox"
|
2024-03-18 10:01:35 +00:00
|
|
|
:class="[inputClass, cx('input')]"
|
2022-09-14 11:26:01 +00:00
|
|
|
:style="inputStyle"
|
2024-03-18 10:01:35 +00:00
|
|
|
:value="inputFieldValue"
|
2022-09-14 11:26:01 +00:00
|
|
|
:placeholder="placeholder"
|
2024-03-18 10:01:35 +00:00
|
|
|
:invalid="invalid"
|
|
|
|
:variant="variant"
|
|
|
|
:unstyled="unstyled"
|
2022-12-08 11:04:25 +00:00
|
|
|
autocomplete="off"
|
2022-09-14 11:26:01 +00:00
|
|
|
aria-autocomplete="none"
|
|
|
|
aria-haspopup="dialog"
|
|
|
|
:aria-expanded="overlayVisible"
|
|
|
|
:aria-controls="panelId"
|
|
|
|
:aria-labelledby="ariaLabelledby"
|
|
|
|
:aria-label="ariaLabel"
|
|
|
|
inputmode="none"
|
|
|
|
:disabled="disabled"
|
2022-12-08 11:04:25 +00:00
|
|
|
:readonly="!manualInput || readonly"
|
2022-09-14 11:26:01 +00:00
|
|
|
:tabindex="0"
|
|
|
|
@input="onInput"
|
2022-12-08 11:04:25 +00:00
|
|
|
@click="onInputClick"
|
2022-09-14 11:26:01 +00:00
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@keydown="onKeyDown"
|
2024-03-18 10:01:35 +00:00
|
|
|
:pt="ptm('input')"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2024-03-18 10:01:35 +00:00
|
|
|
<slot v-if="showIcon && iconDisplay === 'button'" name="dropdownbutton">
|
|
|
|
<button
|
|
|
|
:class="cx('dropdownButton')"
|
|
|
|
:disabled="disabled"
|
|
|
|
@click="onButtonClick"
|
|
|
|
type="button"
|
|
|
|
:aria-label="$primevue.config.locale.chooseDate"
|
|
|
|
aria-haspopup="dialog"
|
|
|
|
:aria-expanded="overlayVisible"
|
|
|
|
:aria-controls="panelId"
|
|
|
|
v-bind="ptm('dropdownButton')"
|
|
|
|
>
|
2023-09-06 06:59:31 +00:00
|
|
|
<slot name="dropdownicon" :class="icon">
|
2024-03-18 10:01:35 +00:00
|
|
|
<component :is="icon ? 'span' : 'CalendarIcon'" :class="icon" v-bind="ptm('dropdownButtonIcon')" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
2024-03-18 10:01:35 +00:00
|
|
|
</button>
|
|
|
|
</slot>
|
2023-11-23 09:29:16 +00:00
|
|
|
<template v-else-if="showIcon && iconDisplay === 'input'">
|
2024-04-09 06:13:39 +00:00
|
|
|
<span :class="cx('inputIconContainer')">
|
|
|
|
<slot name="inputicon" :class="cx('inputIcon')" :clickCallback="onButtonClick">
|
|
|
|
<component :is="icon ? 'i' : 'CalendarIcon'" :class="[icon, cx('inputIcon')]" @click="onButtonClick" v-bind="ptm('inputicon')" />
|
|
|
|
</slot>
|
|
|
|
</span>
|
2023-11-23 09:29:16 +00:00
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
<Portal :appendTo="appendTo" :disabled="inline">
|
2023-08-02 11:59:53 +00:00
|
|
|
<transition name="p-connected-overlay" @enter="onOverlayEnter($event)" @after-enter="onOverlayEnterComplete" @after-leave="onOverlayAfterLeave" @leave="onOverlayLeave" v-bind="ptm('transition')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<div
|
|
|
|
v-if="inline || overlayVisible"
|
|
|
|
:ref="overlayRef"
|
|
|
|
:id="panelId"
|
2023-07-06 12:13:28 +00:00
|
|
|
:class="[cx('panel'), panelClass]"
|
2022-09-14 11:26:01 +00:00
|
|
|
:style="panelStyle"
|
|
|
|
:role="inline ? null : 'dialog'"
|
|
|
|
:aria-modal="inline ? null : 'true'"
|
|
|
|
:aria-label="$primevue.config.locale.chooseDate"
|
|
|
|
@click="onOverlayClick"
|
|
|
|
@keydown="onOverlayKeyDown"
|
|
|
|
@mouseup="onOverlayMouseUp"
|
2024-03-19 14:14:13 +00:00
|
|
|
v-bind="ptm('panel')"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!timeOnly">
|
2024-04-06 22:44:28 +00:00
|
|
|
<div :class="cx('group')" v-bind="ptm('group')">
|
|
|
|
<div v-for="(month, groupIndex) of months" :key="month.month + month.year" :class="cx('calendar')" v-bind="ptm('calendar')">
|
2023-05-19 11:14:50 +00:00
|
|
|
<div :class="cx('header')" v-bind="ptm('header')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="header"></slot>
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2022-09-14 11:26:01 +00:00
|
|
|
v-show="showOtherMonths ? groupIndex === 0 : false"
|
2023-05-19 10:32:44 +00:00
|
|
|
:ref="previousButtonRef"
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('previousButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
:aria-label="currentView === 'year' ? $primevue.config.locale.prevDecade : currentView === 'month' ? $primevue.config.locale.prevYear : $primevue.config.locale.prevMonth"
|
2024-04-09 06:05:44 +00:00
|
|
|
:unstyled="unstyled"
|
|
|
|
@click="onPrevButtonClick"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
v-bind="navigatorButtonProps"
|
|
|
|
:pt="ptm('previousButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="navigator"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="previousicon">
|
|
|
|
<component :is="previousIcon ? 'span' : 'ChevronLeftIcon'" :class="[previousIcon, slotProps.class]" v-bind="ptm('previousButton')['icon']" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2023-05-19 11:14:50 +00:00
|
|
|
<div :class="cx('title')" v-bind="ptm('title')">
|
2023-09-05 14:12:09 +00:00
|
|
|
<template v-if="$primevue.config.locale.showMonthAfterYear">
|
2023-07-09 14:46:01 +00:00
|
|
|
<button
|
|
|
|
v-if="currentView !== 'year'"
|
|
|
|
type="button"
|
|
|
|
@click="switchToYearView"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
:class="cx('yearTitle')"
|
|
|
|
:disabled="switchViewButtonDisabled"
|
|
|
|
:aria-label="$primevue.config.locale.chooseYear"
|
|
|
|
v-bind="ptm('yearTitle')"
|
|
|
|
data-pc-group-section="view"
|
|
|
|
>
|
|
|
|
{{ getYear(month) }}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-if="currentView === 'date'"
|
|
|
|
type="button"
|
|
|
|
@click="switchToMonthView"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
:class="cx('monthTitle')"
|
|
|
|
:disabled="switchViewButtonDisabled"
|
|
|
|
:aria-label="$primevue.config.locale.chooseMonth"
|
|
|
|
v-bind="ptm('monthTitle')"
|
|
|
|
data-pc-group-section="view"
|
|
|
|
>
|
|
|
|
{{ getMonthName(month.month) }}
|
|
|
|
</button>
|
2023-09-05 14:12:09 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2023-07-09 14:46:01 +00:00
|
|
|
<button
|
|
|
|
v-if="currentView === 'date'"
|
|
|
|
type="button"
|
|
|
|
@click="switchToMonthView"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
:class="cx('monthTitle')"
|
|
|
|
:disabled="switchViewButtonDisabled"
|
|
|
|
:aria-label="$primevue.config.locale.chooseMonth"
|
|
|
|
v-bind="ptm('monthTitle')"
|
|
|
|
data-pc-group-section="view"
|
|
|
|
>
|
|
|
|
{{ getMonthName(month.month) }}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-if="currentView !== 'year'"
|
|
|
|
type="button"
|
|
|
|
@click="switchToYearView"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
:class="cx('yearTitle')"
|
|
|
|
:disabled="switchViewButtonDisabled"
|
|
|
|
:aria-label="$primevue.config.locale.chooseYear"
|
|
|
|
v-bind="ptm('yearTitle')"
|
|
|
|
data-pc-group-section="view"
|
|
|
|
>
|
|
|
|
{{ getYear(month) }}
|
|
|
|
</button>
|
2023-09-05 14:12:09 +00:00
|
|
|
</template>
|
2023-05-19 11:14:50 +00:00
|
|
|
<span v-if="currentView === 'year'" :class="cx('decadeTitle')" v-bind="ptm('decadeTitle')">
|
2023-03-09 11:08:26 +00:00
|
|
|
<slot name="decade" :years="yearPickerValues"> {{ yearPickerValues[0].value }} - {{ yearPickerValues[yearPickerValues.length - 1].value }} </slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2022-09-14 11:26:01 +00:00
|
|
|
v-show="showOtherMonths ? (numberOfMonths === 1 ? true : groupIndex === numberOfMonths - 1) : false"
|
2023-05-19 10:32:44 +00:00
|
|
|
:ref="nextButtonRef"
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('nextButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
:aria-label="currentView === 'year' ? $primevue.config.locale.nextDecade : currentView === 'month' ? $primevue.config.locale.nextYear : $primevue.config.locale.nextMonth"
|
2024-04-09 06:05:44 +00:00
|
|
|
:unstyled="unstyled"
|
|
|
|
@click="onNextButtonClick"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
v-bind="navigatorButtonProps"
|
|
|
|
:pt="ptm('nextButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="navigator"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="nexticon">
|
|
|
|
<component :is="nextIcon ? 'span' : 'ChevronRightIcon'" :class="[nextIcon, slotProps.class]" v-bind="ptm('nextButton')['icon']" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2024-04-06 22:44:28 +00:00
|
|
|
<table v-if="currentView === 'date'" :class="cx('grid')" role="grid" v-bind="ptm('grid')">
|
|
|
|
<thead v-bind="ptm('tableHeader')">
|
|
|
|
<tr v-bind="ptm('tableHeaderRow')">
|
|
|
|
<th v-if="showWeek" scope="col" :class="cx('weekHeader')" v-bind="ptm('weekHeader', { context: { disabled: showWeek } })" :data-p-disabled="showWeek" data-pc-group-section="tableheadercell">
|
|
|
|
<slot name="weekheaderlabel">
|
|
|
|
<span v-bind="ptm('weekHeaderLabel', { context: { disabled: showWeek } })" data-pc-group-section="tableheadercelllabel">
|
|
|
|
{{ weekHeaderLabel }}
|
2022-09-06 12:03:37 +00:00
|
|
|
</span>
|
2024-04-06 22:44:28 +00:00
|
|
|
</slot>
|
|
|
|
</th>
|
|
|
|
<th v-for="weekDay of weekDays" :key="weekDay" scope="col" :abbr="weekDay" v-bind="ptm('tableHeaderCell')" data-pc-group-section="tableheadercell" :class="cx('weekDay')">
|
|
|
|
<span v-bind="ptm('weekDay')" data-pc-group-section="tableheadercelllabel" :class="cx('weekDay')">{{ weekDay }}</span>
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody v-bind="ptm('tableBody')">
|
|
|
|
<tr v-for="(week, i) of month.dates" :key="week[0].day + '' + week[0].month" v-bind="ptm('tableBodyRow')">
|
|
|
|
<td v-if="showWeek" :class="cx('weekNumber')" v-bind="ptm('weekNumber')" data-pc-group-section="tablebodycell">
|
|
|
|
<span :class="cx('weekLabelContainer')" v-bind="ptm('weekLabelContainer', { context: { disabled: showWeek } })" :data-p-disabled="showWeek" data-pc-group-section="tablebodycelllabel">
|
|
|
|
<slot name="weeklabel" :weekNumber="month.weekNumbers[i]">
|
|
|
|
<span v-if="month.weekNumbers[i] < 10" style="visibility: hidden" v-bind="ptm('weekLabel')">0</span>
|
|
|
|
{{ month.weekNumbers[i] }}
|
|
|
|
</slot>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td
|
|
|
|
v-for="date of week"
|
|
|
|
:key="date.day + '' + date.month"
|
|
|
|
:aria-label="date.day"
|
|
|
|
:class="cx('day', { date })"
|
|
|
|
v-bind="
|
|
|
|
ptm('day', {
|
|
|
|
context: {
|
|
|
|
date,
|
|
|
|
today: date.today,
|
|
|
|
otherMonth: date.otherMonth,
|
|
|
|
selected: isSelected(date),
|
|
|
|
disabled: !date.selectable
|
|
|
|
}
|
|
|
|
})
|
|
|
|
"
|
|
|
|
:data-p-today="date.today"
|
|
|
|
:data-p-other-month="date.otherMonth"
|
|
|
|
data-pc-group-section="tablebodycell"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
v-ripple
|
|
|
|
:class="cx('dayLabel', { date })"
|
|
|
|
@click="onDateSelect($event, date)"
|
|
|
|
draggable="false"
|
|
|
|
@keydown="onDateCellKeydown($event, date, groupIndex)"
|
|
|
|
:aria-selected="isSelected(date)"
|
|
|
|
:aria-disabled="!date.selectable"
|
2023-07-31 06:18:21 +00:00
|
|
|
v-bind="
|
2024-04-06 22:44:28 +00:00
|
|
|
ptm('dayLabel', {
|
2023-07-31 06:18:21 +00:00
|
|
|
context: {
|
|
|
|
date,
|
|
|
|
today: date.today,
|
2024-02-20 09:18:07 +00:00
|
|
|
otherMonth: date.otherMonth,
|
|
|
|
selected: isSelected(date),
|
|
|
|
disabled: !date.selectable
|
2023-07-31 06:18:21 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
"
|
2024-04-06 22:44:28 +00:00
|
|
|
:data-p-disabled="!date.selectable"
|
|
|
|
:data-p-highlight="isSelected(date)"
|
|
|
|
data-pc-group-section="tablebodycelllabel"
|
2023-07-31 06:18:21 +00:00
|
|
|
>
|
2024-04-06 22:44:28 +00:00
|
|
|
<slot name="date" :date="date">{{ date.day }}</slot>
|
|
|
|
</span>
|
|
|
|
<div v-if="isSelected(date)" class="p-hidden-accessible" aria-live="polite" v-bind="ptm('hiddenSelectedDay')" :data-p-hidden-accessible="true">
|
|
|
|
{{ date.day }}
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-24 00:59:42 +00:00
|
|
|
<div v-if="currentView === 'month'" :class="cx('monthPicker')" v-bind="ptm('monthPicker')">
|
2023-01-25 08:42:15 +00:00
|
|
|
<span
|
|
|
|
v-for="(m, i) of monthPickerValues"
|
|
|
|
:key="m"
|
|
|
|
v-ripple
|
|
|
|
@click="onMonthSelect($event, { month: m, index: i })"
|
|
|
|
@keydown="onMonthCellKeydown($event, { month: m, index: i })"
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('month', { month: m, index: i })"
|
2023-07-31 06:18:21 +00:00
|
|
|
v-bind="
|
|
|
|
ptm('month', {
|
|
|
|
context: {
|
|
|
|
month: m,
|
|
|
|
monthIndex: i,
|
|
|
|
selected: isMonthSelected(i),
|
|
|
|
disabled: !m.selectable
|
|
|
|
}
|
|
|
|
})
|
|
|
|
"
|
2023-05-19 10:32:44 +00:00
|
|
|
:data-p-disabled="!m.selectable"
|
|
|
|
:data-p-highlight="isMonthSelected(i)"
|
2023-01-25 08:42:15 +00:00
|
|
|
>
|
2023-03-09 11:08:26 +00:00
|
|
|
{{ m.value }}
|
2023-07-03 22:20:35 +00:00
|
|
|
<div v-if="isMonthSelected(i)" class="p-hidden-accessible" aria-live="polite" v-bind="ptm('hiddenMonth')" :data-p-hidden-accessible="true">
|
2023-03-09 11:08:26 +00:00
|
|
|
{{ m.value }}
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</span>
|
|
|
|
</div>
|
2023-05-24 00:59:42 +00:00
|
|
|
<div v-if="currentView === 'year'" :class="cx('yearPicker')" v-bind="ptm('yearPicker')">
|
2023-01-25 08:42:15 +00:00
|
|
|
<span
|
|
|
|
v-for="y of yearPickerValues"
|
|
|
|
:key="y.value"
|
|
|
|
v-ripple
|
|
|
|
@click="onYearSelect($event, y)"
|
|
|
|
@keydown="onYearCellKeydown($event, y)"
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('year', { year: y })"
|
2023-07-31 06:18:21 +00:00
|
|
|
v-bind="
|
|
|
|
ptm('year', {
|
|
|
|
context: {
|
|
|
|
year: y,
|
|
|
|
selected: isYearSelected(y.value),
|
|
|
|
disabled: !y.selectable
|
|
|
|
}
|
|
|
|
})
|
|
|
|
"
|
2023-05-19 10:32:44 +00:00
|
|
|
:data-p-disabled="!y.selectable"
|
|
|
|
:data-p-highlight="isYearSelected(y.value)"
|
2023-01-25 08:42:15 +00:00
|
|
|
>
|
|
|
|
{{ y.value }}
|
2023-07-03 22:20:35 +00:00
|
|
|
<div v-if="isYearSelected(y.value)" class="p-hidden-accessible" aria-live="polite" v-bind="ptm('hiddenYear')" :data-p-hidden-accessible="true">
|
2023-01-25 08:42:15 +00:00
|
|
|
{{ y.value }}
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-05-19 11:14:50 +00:00
|
|
|
<div v-if="(showTime || timeOnly) && currentView === 'date'" :class="cx('timePicker')" v-bind="ptm('timePicker')">
|
2023-09-01 10:04:38 +00:00
|
|
|
<div :class="cx('hourPicker')" v-bind="ptm('hourPicker')" data-pc-group-section="timepickerContainer">
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('incrementButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:aria-label="$primevue.config.locale.nextHour"
|
2024-04-09 06:05:44 +00:00
|
|
|
:unstyled="unstyled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onTimePickerElementMouseDown($event, 0, 1)"
|
|
|
|
@mouseup="onTimePickerElementMouseUp($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
@mouseleave="onTimePickerElementMouseLeave()"
|
|
|
|
@keydown.enter="onTimePickerElementMouseDown($event, 0, 1)"
|
|
|
|
@keydown.space="onTimePickerElementMouseDown($event, 0, 1)"
|
|
|
|
@keyup.enter="onTimePickerElementMouseUp($event)"
|
|
|
|
@keyup.space="onTimePickerElementMouseUp($event)"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('incrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="incrementicon">
|
|
|
|
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="[incrementIcon, slotProps.class]" v-bind="ptm('incrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2023-09-01 10:04:38 +00:00
|
|
|
<span v-bind="ptm('hour')" data-pc-group-section="timepickerlabel">{{ formattedCurrentHour }}</span>
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('decrementButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:aria-label="$primevue.config.locale.prevHour"
|
2024-04-09 06:05:44 +00:00
|
|
|
:unstyled="unstyled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onTimePickerElementMouseDown($event, 0, -1)"
|
|
|
|
@mouseup="onTimePickerElementMouseUp($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
@mouseleave="onTimePickerElementMouseLeave()"
|
|
|
|
@keydown.enter="onTimePickerElementMouseDown($event, 0, -1)"
|
|
|
|
@keydown.space="onTimePickerElementMouseDown($event, 0, -1)"
|
|
|
|
@keyup.enter="onTimePickerElementMouseUp($event)"
|
|
|
|
@keyup.space="onTimePickerElementMouseUp($event)"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('decrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="decrementicon">
|
|
|
|
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="[decrementIcon, slotProps.class]" v-bind="ptm('decrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-09-01 10:04:38 +00:00
|
|
|
<div :class="cx('separatorContainer')" v-bind="ptm('separatorContainer')" data-pc-group-section="timepickerContainer">
|
|
|
|
<span v-bind="ptm('separator')" data-pc-group-section="timepickerlabel">{{ timeSeparator }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-09-01 10:04:38 +00:00
|
|
|
<div :class="cx('minutePicker')" v-bind="ptm('minutePicker')" data-pc-group-section="timepickerContainer">
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('incrementButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:aria-label="$primevue.config.locale.nextMinute"
|
2024-04-09 06:05:44 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
:unstyled="unstyled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onTimePickerElementMouseDown($event, 1, 1)"
|
|
|
|
@mouseup="onTimePickerElementMouseUp($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
@mouseleave="onTimePickerElementMouseLeave()"
|
|
|
|
@keydown.enter="onTimePickerElementMouseDown($event, 1, 1)"
|
|
|
|
@keydown.space="onTimePickerElementMouseDown($event, 1, 1)"
|
|
|
|
@keyup.enter="onTimePickerElementMouseUp($event)"
|
|
|
|
@keyup.space="onTimePickerElementMouseUp($event)"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('incrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="incrementicon">
|
|
|
|
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="[incrementIcon, slotProps.class]" v-bind="ptm('incrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2023-09-01 10:04:38 +00:00
|
|
|
<span v-bind="ptm('minute')" data-pc-group-section="timepickerlabel">{{ formattedCurrentMinute }}</span>
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('decrementButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:aria-label="$primevue.config.locale.prevMinute"
|
2024-04-09 06:05:44 +00:00
|
|
|
:disabled="disabled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onTimePickerElementMouseDown($event, 1, -1)"
|
|
|
|
@mouseup="onTimePickerElementMouseUp($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
@mouseleave="onTimePickerElementMouseLeave()"
|
|
|
|
@keydown.enter="onTimePickerElementMouseDown($event, 1, -1)"
|
|
|
|
@keydown.space="onTimePickerElementMouseDown($event, 1, -1)"
|
|
|
|
@keyup.enter="onTimePickerElementMouseUp($event)"
|
|
|
|
@keyup.space="onTimePickerElementMouseUp($event)"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('decrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="decrementicon">
|
|
|
|
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="[decrementIcon, slotProps.class]" v-bind="ptm('decrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-09-01 10:04:38 +00:00
|
|
|
<div v-if="showSeconds" :class="cx('separatorContainer')" v-bind="ptm('separatorContainer')" data-pc-group-section="timepickerContainer">
|
|
|
|
<span v-bind="ptm('separator')" data-pc-group-section="timepickerlabel">{{ timeSeparator }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-09-01 10:04:38 +00:00
|
|
|
<div v-if="showSeconds" :class="cx('secondPicker')" v-bind="ptm('secondPicker')" data-pc-group-section="timepickerContainer">
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('incrementButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:aria-label="$primevue.config.locale.nextSecond"
|
2024-04-09 06:05:44 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
:unstyled="unstyled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onTimePickerElementMouseDown($event, 2, 1)"
|
|
|
|
@mouseup="onTimePickerElementMouseUp($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
@mouseleave="onTimePickerElementMouseLeave()"
|
|
|
|
@keydown.enter="onTimePickerElementMouseDown($event, 2, 1)"
|
|
|
|
@keydown.space="onTimePickerElementMouseDown($event, 2, 1)"
|
|
|
|
@keyup.enter="onTimePickerElementMouseUp($event)"
|
|
|
|
@keyup.space="onTimePickerElementMouseUp($event)"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('incrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="incrementicon">
|
|
|
|
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="[incrementIcon, slotProps.class]" v-bind="ptm('incrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2023-09-01 10:04:38 +00:00
|
|
|
<span v-bind="ptm('second')" data-pc-group-section="timepickerlabel">{{ formattedCurrentSecond }}</span>
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-05-19 11:14:50 +00:00
|
|
|
:class="cx('decrementButton')"
|
2022-09-14 11:26:01 +00:00
|
|
|
:aria-label="$primevue.config.locale.prevSecond"
|
2024-04-09 06:05:44 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
:unstyled="unstyled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onTimePickerElementMouseDown($event, 2, -1)"
|
|
|
|
@mouseup="onTimePickerElementMouseUp($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
@mouseleave="onTimePickerElementMouseLeave()"
|
|
|
|
@keydown.enter="onTimePickerElementMouseDown($event, 2, -1)"
|
|
|
|
@keydown.space="onTimePickerElementMouseDown($event, 2, -1)"
|
|
|
|
@keyup.enter="onTimePickerElementMouseUp($event)"
|
|
|
|
@keyup.space="onTimePickerElementMouseUp($event)"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('decrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="decrementicon">
|
|
|
|
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="[decrementIcon, slotProps.class]" v-bind="ptm('decrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-09-01 10:04:38 +00:00
|
|
|
<div v-if="hourFormat == '12'" :class="cx('separatorContainer')" v-bind="ptm('separatorContainer')" data-pc-group-section="timepickerContainer">
|
|
|
|
<span v-bind="ptm('separator')" data-pc-group-section="timepickerlabel">{{ timeSeparator }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-05-19 11:14:50 +00:00
|
|
|
<div v-if="hourFormat == '12'" :class="cx('ampmPicker')" v-bind="ptm('ampmPicker')">
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-09-01 10:04:38 +00:00
|
|
|
:class="cx('incrementButton')"
|
|
|
|
:aria-label="$primevue.config.locale.am"
|
2024-04-09 06:05:44 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
:unstyled="unstyled"
|
2023-09-01 10:04:38 +00:00
|
|
|
@click="toggleAMPM($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('incrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="incrementicon" :class="cx('incrementIcon')">
|
|
|
|
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="[cx('incrementIcon'), slotProps.class]" v-bind="ptm('incrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2023-09-01 10:04:38 +00:00
|
|
|
<span v-bind="ptm('ampm')" data-pc-group-section="timepickerlabel">{{ pm ? $primevue.config.locale.pm : $primevue.config.locale.am }}</span>
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
2023-09-01 10:04:38 +00:00
|
|
|
:class="cx('decrementButton')"
|
|
|
|
:aria-label="$primevue.config.locale.pm"
|
2024-04-09 06:05:44 +00:00
|
|
|
:disabled="disabled"
|
2023-09-01 10:04:38 +00:00
|
|
|
@click="toggleAMPM($event)"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
2024-04-09 06:05:44 +00:00
|
|
|
v-bind="timepickerButtonProps"
|
|
|
|
:pt="ptm('decrementButton')"
|
2023-09-01 10:04:38 +00:00
|
|
|
data-pc-group-section="timepickerbutton"
|
|
|
|
>
|
2024-04-09 06:05:44 +00:00
|
|
|
<template #icon="slotProps">
|
|
|
|
<slot name="decrementicon" :class="cx('decrementIcon')">
|
|
|
|
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="[cx('decrementIcon'), slotProps.class]" v-bind="ptm('decrementButton')['icon']" data-pc-group-section="timepickerlabel" />
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</Button>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-19 11:14:50 +00:00
|
|
|
<div v-if="showButtonBar" :class="cx('buttonbar')" v-bind="ptm('buttonbar')">
|
2024-04-09 06:05:44 +00:00
|
|
|
<Button
|
|
|
|
:label="todayLabel"
|
|
|
|
@click="onTodayButtonClick($event)"
|
|
|
|
:class="cx('todayButton')"
|
|
|
|
:unstyled="unstyled"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
v-bind="todayButtonProps"
|
|
|
|
:pt="ptm('todayButton')"
|
|
|
|
data-pc-group-section="button"
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
:label="clearLabel"
|
|
|
|
@click="onClearButtonClick($event)"
|
|
|
|
:class="cx('clearButton')"
|
|
|
|
:unstyled="unstyled"
|
|
|
|
@keydown="onContainerButtonKeydown"
|
|
|
|
v-bind="clearButtonProps"
|
|
|
|
:pt="ptm('clearButton')"
|
|
|
|
data-pc-group-section="button"
|
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
<slot name="footer"></slot>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</Portal>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-04-09 06:05:44 +00:00
|
|
|
import Button from 'primevue/button';
|
2023-04-18 12:53:43 +00:00
|
|
|
import CalendarIcon from 'primevue/icons/calendar';
|
|
|
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
|
|
|
import ChevronLeftIcon from 'primevue/icons/chevronleft';
|
|
|
|
import ChevronRightIcon from 'primevue/icons/chevronright';
|
|
|
|
import ChevronUpIcon from 'primevue/icons/chevronup';
|
2024-03-18 10:01:35 +00:00
|
|
|
import InputText from 'primevue/inputtext';
|
2022-12-08 11:04:25 +00:00
|
|
|
import OverlayEventBus from 'primevue/overlayeventbus';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Portal from 'primevue/portal';
|
2022-12-08 11:04:25 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
|
|
|
import { ConnectedOverlayScrollHandler, DomHandler, UniqueComponentId, ZIndexUtils } from 'primevue/utils';
|
2023-05-19 12:16:12 +00:00
|
|
|
import BaseCalendar from './BaseCalendar.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Calendar',
|
2023-05-19 10:32:44 +00:00
|
|
|
extends: BaseCalendar,
|
2024-02-11 08:10:29 +00:00
|
|
|
inheritAttrs: false,
|
2022-09-06 12:03:37 +00:00
|
|
|
emits: ['show', 'hide', 'input', 'month-change', 'year-change', 'date-select', 'update:modelValue', 'today-click', 'clear-click', 'focus', 'blur', 'keydown'],
|
|
|
|
navigationState: null,
|
|
|
|
timePickerChange: false,
|
|
|
|
scrollHandler: null,
|
|
|
|
outsideClickListener: null,
|
|
|
|
resizeListener: null,
|
2023-11-21 17:28:15 +00:00
|
|
|
matchMediaListener: null,
|
2022-09-06 12:03:37 +00:00
|
|
|
overlay: null,
|
|
|
|
input: null,
|
2023-05-19 10:32:44 +00:00
|
|
|
previousButton: null,
|
|
|
|
nextButton: null,
|
2022-09-06 12:03:37 +00:00
|
|
|
timePickerTimer: null,
|
|
|
|
preventFocus: false,
|
|
|
|
typeUpdate: false,
|
2022-09-14 11:26:01 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2024-02-02 15:46:27 +00:00
|
|
|
d_id: this.id,
|
2022-09-14 11:26:01 +00:00
|
|
|
currentMonth: null,
|
|
|
|
currentYear: null,
|
|
|
|
currentHour: null,
|
|
|
|
currentMinute: null,
|
|
|
|
currentSecond: null,
|
|
|
|
pm: null,
|
|
|
|
focused: false,
|
|
|
|
overlayVisible: false,
|
2023-11-15 10:25:37 +00:00
|
|
|
currentView: this.view,
|
2023-11-21 17:28:15 +00:00
|
|
|
query: null,
|
2023-11-15 10:25:37 +00:00
|
|
|
queryMatches: false
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
2024-04-16 09:35:02 +00:00
|
|
|
id: function (newValue) {
|
|
|
|
this.d_id = newValue || UniqueComponentId();
|
2024-02-02 15:46:27 +00:00
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
modelValue(newValue) {
|
|
|
|
this.updateCurrentMetaData();
|
|
|
|
|
|
|
|
if (!this.typeUpdate && !this.inline && this.input) {
|
2024-03-18 10:01:35 +00:00
|
|
|
this.input.value = this.inputFieldValue;
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.typeUpdate = false;
|
|
|
|
},
|
|
|
|
showTime() {
|
|
|
|
this.updateCurrentMetaData();
|
|
|
|
},
|
2023-11-03 07:01:09 +00:00
|
|
|
minDate() {
|
|
|
|
this.updateCurrentMetaData();
|
|
|
|
},
|
|
|
|
maxDate() {
|
|
|
|
this.updateCurrentMetaData();
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
months() {
|
|
|
|
if (this.overlay) {
|
|
|
|
if (!this.focused) {
|
|
|
|
if (this.inline) {
|
|
|
|
this.preventFocus = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(this.updateFocus, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
numberOfMonths() {
|
|
|
|
this.destroyResponsiveStyleElement();
|
|
|
|
this.createResponsiveStyle();
|
|
|
|
},
|
|
|
|
responsiveOptions() {
|
|
|
|
this.destroyResponsiveStyleElement();
|
|
|
|
this.createResponsiveStyle();
|
|
|
|
},
|
|
|
|
currentView() {
|
|
|
|
Promise.resolve(null).then(() => this.alignOverlay());
|
2024-02-01 11:49:22 +00:00
|
|
|
},
|
|
|
|
view(newValue) {
|
|
|
|
this.currentView = newValue;
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
created() {
|
|
|
|
this.updateCurrentMetaData();
|
|
|
|
},
|
|
|
|
mounted() {
|
2024-04-16 09:35:02 +00:00
|
|
|
this.d_id = this.d_id || UniqueComponentId();
|
2022-09-06 12:03:37 +00:00
|
|
|
this.createResponsiveStyle();
|
2023-11-21 17:28:15 +00:00
|
|
|
this.bindMatchMediaListener();
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (this.inline) {
|
|
|
|
this.overlay && this.overlay.setAttribute(this.attributeSelector, '');
|
|
|
|
|
|
|
|
if (!this.disabled) {
|
|
|
|
this.preventFocus = true;
|
|
|
|
this.initFocusableCell();
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2024-03-18 10:01:35 +00:00
|
|
|
this.input.value = this.inputFieldValue;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
if (this.overlay) {
|
|
|
|
this.preventFocus = true;
|
2023-03-27 10:53:24 +00:00
|
|
|
setTimeout(this.updateFocus, 0);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.input && this.selectionStart != null && this.selectionEnd != null) {
|
|
|
|
this.input.selectionStart = this.selectionStart;
|
|
|
|
this.input.selectionEnd = this.selectionEnd;
|
|
|
|
this.selectionStart = null;
|
|
|
|
this.selectionEnd = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
if (this.timePickerTimer) {
|
|
|
|
clearTimeout(this.timePickerTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.destroyResponsiveStyleElement();
|
|
|
|
|
|
|
|
this.unbindOutsideClickListener();
|
|
|
|
this.unbindResizeListener();
|
2023-11-21 17:28:15 +00:00
|
|
|
this.unbindMatchMediaListener();
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (this.scrollHandler) {
|
|
|
|
this.scrollHandler.destroy();
|
|
|
|
this.scrollHandler = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.overlay && this.autoZIndex) {
|
|
|
|
ZIndexUtils.clear(this.overlay);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlay = null;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
isComparable() {
|
|
|
|
return this.modelValue != null && typeof this.modelValue !== 'string';
|
|
|
|
},
|
|
|
|
isSelected(dateMeta) {
|
|
|
|
if (!this.isComparable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
if (this.isSingleSelection()) {
|
|
|
|
return this.isDateEquals(this.modelValue, dateMeta);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isMultipleSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let selected = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let date of this.modelValue) {
|
|
|
|
selected = this.isDateEquals(date, dateMeta);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (selected) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selected;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isRangeSelection()) {
|
|
|
|
if (this.modelValue[1]) return this.isDateEquals(this.modelValue[0], dateMeta) || this.isDateEquals(this.modelValue[1], dateMeta) || this.isDateBetween(this.modelValue[0], this.modelValue[1], dateMeta);
|
2022-09-06 12:03:37 +00:00
|
|
|
else {
|
|
|
|
return this.isDateEquals(this.modelValue[0], dateMeta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isMonthSelected(month) {
|
|
|
|
if (this.isComparable()) {
|
|
|
|
let value = this.isRangeSelection() ? this.modelValue[0] : this.modelValue;
|
|
|
|
|
2023-10-05 13:05:24 +00:00
|
|
|
if (this.isMultipleSelection()) {
|
2023-10-15 12:10:02 +00:00
|
|
|
return value.some((currentValue) => currentValue.getMonth() === month && currentValue.getFullYear() === this.currentYear);
|
2023-10-05 13:05:24 +00:00
|
|
|
} else {
|
2023-10-15 12:10:02 +00:00
|
|
|
return value.getMonth() === month && value.getFullYear() === this.currentYear;
|
2023-10-05 13:05:24 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isYearSelected(year) {
|
|
|
|
if (this.isComparable()) {
|
|
|
|
let value = this.isRangeSelection() ? this.modelValue[0] : this.modelValue;
|
|
|
|
|
2023-10-05 13:05:24 +00:00
|
|
|
if (this.isMultipleSelection()) {
|
|
|
|
return value.some((currentValue) => currentValue.getFullYear() === year);
|
|
|
|
} else {
|
|
|
|
return value.getFullYear() === year;
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isDateEquals(value, dateMeta) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (value) return value.getDate() === dateMeta.day && value.getMonth() === dateMeta.month && value.getFullYear() === dateMeta.year;
|
|
|
|
else return false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
isDateBetween(start, end, dateMeta) {
|
|
|
|
let between = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (start && end) {
|
|
|
|
let date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return start.getTime() <= date.getTime() && end.getTime() >= date.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
return between;
|
|
|
|
},
|
|
|
|
getFirstDayOfMonthIndex(month, year) {
|
|
|
|
let day = new Date();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
day.setDate(1);
|
|
|
|
day.setMonth(month);
|
|
|
|
day.setFullYear(year);
|
|
|
|
|
|
|
|
let dayIndex = day.getDay() + this.sundayIndex;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return dayIndex >= 7 ? dayIndex - 7 : dayIndex;
|
|
|
|
},
|
|
|
|
getDaysCountInMonth(month, year) {
|
|
|
|
return 32 - this.daylightSavingAdjust(new Date(year, month, 32)).getDate();
|
|
|
|
},
|
|
|
|
getDaysCountInPrevMonth(month, year) {
|
|
|
|
let prev = this.getPreviousMonthAndYear(month, year);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return this.getDaysCountInMonth(prev.month, prev.year);
|
|
|
|
},
|
|
|
|
getPreviousMonthAndYear(month, year) {
|
|
|
|
let m, y;
|
|
|
|
|
|
|
|
if (month === 0) {
|
|
|
|
m = 11;
|
|
|
|
y = year - 1;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
m = month - 1;
|
|
|
|
y = year;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
return { month: m, year: y };
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
getNextMonthAndYear(month, year) {
|
|
|
|
let m, y;
|
|
|
|
|
|
|
|
if (month === 11) {
|
|
|
|
m = 0;
|
|
|
|
y = year + 1;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
m = month + 1;
|
|
|
|
y = year;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
return { month: m, year: y };
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
daylightSavingAdjust(date) {
|
|
|
|
if (!date) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
|
|
|
|
|
|
|
|
return date;
|
|
|
|
},
|
|
|
|
isToday(today, day, month, year) {
|
|
|
|
return today.getDate() === day && today.getMonth() === month && today.getFullYear() === year;
|
|
|
|
},
|
|
|
|
isSelectable(day, month, year, otherMonth) {
|
|
|
|
let validMin = true;
|
|
|
|
let validMax = true;
|
|
|
|
let validDate = true;
|
|
|
|
let validDay = true;
|
|
|
|
|
|
|
|
if (otherMonth && !this.selectOtherMonths) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minDate) {
|
|
|
|
if (this.minDate.getFullYear() > year) {
|
|
|
|
validMin = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.minDate.getFullYear() === year) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.minDate.getMonth() > month) {
|
|
|
|
validMin = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.minDate.getMonth() === month) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.minDate.getDate() > day) {
|
|
|
|
validMin = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maxDate) {
|
|
|
|
if (this.maxDate.getFullYear() < year) {
|
|
|
|
validMax = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.maxDate.getFullYear() === year) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.maxDate.getMonth() < month) {
|
|
|
|
validMax = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.maxDate.getMonth() === month) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.maxDate.getDate() < day) {
|
|
|
|
validMax = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.disabledDates) {
|
2022-09-14 11:26:01 +00:00
|
|
|
validDate = !this.isDateDisabled(day, month, year);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.disabledDays) {
|
2022-09-14 11:26:01 +00:00
|
|
|
validDay = !this.isDayDisabled(day, month, year);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return validMin && validMax && validDate && validDay;
|
|
|
|
},
|
|
|
|
onOverlayEnter(el) {
|
|
|
|
el.setAttribute(this.attributeSelector, '');
|
2024-04-09 06:24:28 +00:00
|
|
|
const styles = !this.inline ? { position: 'absolute', top: '0', left: '0' } : undefined;
|
2023-05-19 10:32:44 +00:00
|
|
|
|
|
|
|
DomHandler.addStyles(el, styles);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (this.autoZIndex) {
|
2024-04-09 06:24:28 +00:00
|
|
|
ZIndexUtils.set('overlay', el, this.baseZIndex || this.$primevue.config.zIndex.overlay);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.alignOverlay();
|
|
|
|
this.$emit('show');
|
|
|
|
},
|
|
|
|
onOverlayEnterComplete() {
|
|
|
|
this.bindOutsideClickListener();
|
|
|
|
this.bindScrollListener();
|
|
|
|
this.bindResizeListener();
|
|
|
|
},
|
|
|
|
onOverlayAfterLeave(el) {
|
|
|
|
if (this.autoZIndex) {
|
|
|
|
ZIndexUtils.clear(el);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onOverlayLeave() {
|
|
|
|
this.currentView = this.view;
|
|
|
|
this.unbindOutsideClickListener();
|
|
|
|
this.unbindScrollListener();
|
|
|
|
this.unbindResizeListener();
|
|
|
|
this.$emit('hide');
|
|
|
|
|
|
|
|
this.overlay = null;
|
|
|
|
},
|
|
|
|
onPrevButtonClick(event) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.showOtherMonths) {
|
|
|
|
this.navigationState = { backward: true, button: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onNextButtonClick(event) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.showOtherMonths) {
|
|
|
|
this.navigationState = { backward: false, button: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
navBackward(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (!this.isEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.currentView === 'month') {
|
|
|
|
this.decrementYear();
|
2023-03-30 08:46:23 +00:00
|
|
|
this.$emit('year-change', { month: this.currentMonth, year: this.currentYear });
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.currentView === 'year') {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.decrementDecade();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (event.shiftKey) {
|
|
|
|
this.decrementYear();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.currentMonth === 0) {
|
|
|
|
this.currentMonth = 11;
|
|
|
|
this.decrementYear();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentMonth--;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('month-change', { month: this.currentMonth + 1, year: this.currentYear });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
navForward(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (!this.isEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.currentView === 'month') {
|
|
|
|
this.incrementYear();
|
2023-03-30 08:46:23 +00:00
|
|
|
this.$emit('year-change', { month: this.currentMonth, year: this.currentYear });
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.currentView === 'year') {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.incrementDecade();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (event.shiftKey) {
|
|
|
|
this.incrementYear();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.currentMonth === 11) {
|
|
|
|
this.currentMonth = 0;
|
|
|
|
this.incrementYear();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentMonth++;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('month-change', { month: this.currentMonth + 1, year: this.currentYear });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
decrementYear() {
|
|
|
|
this.currentYear--;
|
|
|
|
},
|
|
|
|
decrementDecade() {
|
|
|
|
this.currentYear = this.currentYear - 10;
|
|
|
|
},
|
|
|
|
incrementYear() {
|
|
|
|
this.currentYear++;
|
|
|
|
},
|
|
|
|
incrementDecade() {
|
|
|
|
this.currentYear = this.currentYear + 10;
|
|
|
|
},
|
|
|
|
switchToMonthView(event) {
|
|
|
|
this.currentView = 'month';
|
|
|
|
setTimeout(this.updateFocus, 0);
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
switchToYearView(event) {
|
|
|
|
this.currentView = 'year';
|
|
|
|
setTimeout(this.updateFocus, 0);
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
isEnabled() {
|
|
|
|
return !this.disabled && !this.readonly;
|
|
|
|
},
|
|
|
|
updateCurrentTimeMeta(date) {
|
|
|
|
let currentHour = date.getHours();
|
|
|
|
|
|
|
|
if (this.hourFormat === '12') {
|
|
|
|
this.pm = currentHour > 11;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (currentHour >= 12) currentHour = currentHour == 12 ? 12 : currentHour - 12;
|
|
|
|
else currentHour = currentHour == 0 ? 12 : currentHour;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.currentHour = Math.floor(currentHour / this.stepHour) * this.stepHour;
|
|
|
|
this.currentMinute = Math.floor(date.getMinutes() / this.stepMinute) * this.stepMinute;
|
|
|
|
this.currentSecond = Math.floor(date.getSeconds() / this.stepSecond) * this.stepSecond;
|
|
|
|
},
|
|
|
|
bindOutsideClickListener() {
|
|
|
|
if (!this.outsideClickListener) {
|
|
|
|
this.outsideClickListener = (event) => {
|
|
|
|
if (this.overlayVisible && this.isOutsideClicked(event)) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
document.addEventListener('mousedown', this.outsideClickListener);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unbindOutsideClickListener() {
|
|
|
|
if (this.outsideClickListener) {
|
|
|
|
document.removeEventListener('mousedown', this.outsideClickListener);
|
|
|
|
this.outsideClickListener = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bindScrollListener() {
|
|
|
|
if (!this.scrollHandler) {
|
|
|
|
this.scrollHandler = new ConnectedOverlayScrollHandler(this.$refs.container, () => {
|
|
|
|
if (this.overlayVisible) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.scrollHandler.bindScrollListener();
|
|
|
|
},
|
|
|
|
unbindScrollListener() {
|
|
|
|
if (this.scrollHandler) {
|
|
|
|
this.scrollHandler.unbindScrollListener();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bindResizeListener() {
|
|
|
|
if (!this.resizeListener) {
|
|
|
|
this.resizeListener = () => {
|
|
|
|
if (this.overlayVisible && !DomHandler.isTouchDevice()) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
window.addEventListener('resize', this.resizeListener);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unbindResizeListener() {
|
|
|
|
if (this.resizeListener) {
|
|
|
|
window.removeEventListener('resize', this.resizeListener);
|
|
|
|
this.resizeListener = null;
|
|
|
|
}
|
|
|
|
},
|
2023-11-21 17:28:15 +00:00
|
|
|
bindMatchMediaListener() {
|
|
|
|
if (!this.matchMediaListener) {
|
|
|
|
const query = matchMedia(`(max-width: ${this.breakpoint})`);
|
|
|
|
|
|
|
|
this.query = query;
|
|
|
|
this.queryMatches = query.matches;
|
|
|
|
|
|
|
|
this.matchMediaListener = () => {
|
|
|
|
this.queryMatches = query.matches;
|
|
|
|
this.mobileActive = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.query.addEventListener('change', this.matchMediaListener);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unbindMatchMediaListener() {
|
|
|
|
if (this.matchMediaListener) {
|
|
|
|
this.query.removeEventListener('change', this.matchMediaListener);
|
|
|
|
this.matchMediaListener = null;
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
isOutsideClicked(event) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return !(this.$el.isSameNode(event.target) || this.isNavIconClicked(event) || this.$el.contains(event.target) || (this.overlay && this.overlay.contains(event.target)));
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
isNavIconClicked(event) {
|
2023-05-19 10:32:44 +00:00
|
|
|
return (this.previousButton && (this.previousButton.isSameNode(event.target) || this.previousButton.contains(event.target))) || (this.nextButton && (this.nextButton.isSameNode(event.target) || this.nextButton.contains(event.target)));
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
alignOverlay() {
|
2024-04-09 06:24:28 +00:00
|
|
|
if (this.overlay) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.appendTo === 'self' || this.inline) {
|
|
|
|
DomHandler.relativePosition(this.overlay, this.$el);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.view === 'date') {
|
|
|
|
this.overlay.style.width = DomHandler.getOuterWidth(this.overlay) + 'px';
|
|
|
|
this.overlay.style.minWidth = DomHandler.getOuterWidth(this.$el) + 'px';
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlay.style.width = DomHandler.getOuterWidth(this.$el) + 'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
DomHandler.absolutePosition(this.overlay, this.$el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onButtonClick() {
|
|
|
|
if (this.isEnabled()) {
|
|
|
|
if (!this.overlayVisible) {
|
|
|
|
this.input.focus();
|
|
|
|
this.overlayVisible = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isDateDisabled(day, month, year) {
|
|
|
|
if (this.disabledDates) {
|
|
|
|
for (let disabledDate of this.disabledDates) {
|
|
|
|
if (disabledDate.getFullYear() === year && disabledDate.getMonth() === month && disabledDate.getDate() === day) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isDayDisabled(day, month, year) {
|
|
|
|
if (this.disabledDays) {
|
|
|
|
let weekday = new Date(year, month, day);
|
|
|
|
let weekdayNumber = weekday.getDay();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return this.disabledDays.indexOf(weekdayNumber) !== -1;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
onMonthDropdownChange(value) {
|
|
|
|
this.currentMonth = parseInt(value);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('month-change', { month: this.currentMonth + 1, year: this.currentYear });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onYearDropdownChange(value) {
|
|
|
|
this.currentYear = parseInt(value);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('year-change', { month: this.currentMonth + 1, year: this.currentYear });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onDateSelect(event, dateMeta) {
|
|
|
|
if (this.disabled || !dateMeta.selectable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
DomHandler.find(this.overlay, 'table td span:not([data-p-disabled="true"])').forEach((cell) => (cell.tabIndex = -1));
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
event.currentTarget.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isMultipleSelection() && this.isSelected(dateMeta)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
let newValue = this.modelValue.filter((date) => !this.isDateEquals(date, dateMeta));
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.updateModel(newValue);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.shouldSelectDate(dateMeta)) {
|
|
|
|
if (dateMeta.otherMonth) {
|
|
|
|
this.currentMonth = dateMeta.month;
|
|
|
|
this.currentYear = dateMeta.year;
|
|
|
|
this.selectDate(dateMeta);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.selectDate(dateMeta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isSingleSelection() && (!this.showTime || this.hideOnDateTimeSelect)) {
|
|
|
|
setTimeout(() => {
|
2022-12-08 11:04:25 +00:00
|
|
|
if (this.input) {
|
|
|
|
this.input.focus();
|
|
|
|
}
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlayVisible = false;
|
|
|
|
}, 150);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectDate(dateMeta) {
|
|
|
|
let date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
|
|
|
|
|
|
|
|
if (this.showTime) {
|
2024-01-26 11:43:39 +00:00
|
|
|
if (this.hourFormat === '12' && this.currentHour !== 12) {
|
|
|
|
this.pm ? date.setHours(this.currentHour + 12) : date.setHours(this.currentHour);
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
date.setMinutes(this.currentMinute);
|
|
|
|
date.setSeconds(this.currentSecond);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minDate && this.minDate > date) {
|
|
|
|
date = this.minDate;
|
|
|
|
this.currentHour = date.getHours();
|
|
|
|
this.currentMinute = date.getMinutes();
|
|
|
|
this.currentSecond = date.getSeconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maxDate && this.maxDate < date) {
|
|
|
|
date = this.maxDate;
|
|
|
|
this.currentHour = date.getHours();
|
|
|
|
this.currentMinute = date.getMinutes();
|
|
|
|
this.currentSecond = date.getSeconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
let modelVal = null;
|
|
|
|
|
|
|
|
if (this.isSingleSelection()) {
|
|
|
|
modelVal = date;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isMultipleSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
modelVal = this.modelValue ? [...this.modelValue, date] : [date];
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isRangeSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.modelValue && this.modelValue.length) {
|
|
|
|
let startDate = this.modelValue[0];
|
|
|
|
let endDate = this.modelValue[1];
|
|
|
|
|
|
|
|
if (!endDate && date.getTime() >= startDate.getTime()) {
|
|
|
|
endDate = date;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
startDate = date;
|
|
|
|
endDate = null;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
modelVal = [startDate, endDate];
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
modelVal = [date, null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modelVal !== null) {
|
|
|
|
this.updateModel(modelVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isRangeSelection() && this.hideOnRangeSelection && modelVal[1] !== null) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}, 150);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('date-select', date);
|
|
|
|
},
|
|
|
|
updateModel(value) {
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
},
|
|
|
|
shouldSelectDate() {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.isMultipleSelection()) return this.maxDateCount != null ? this.maxDateCount > (this.modelValue ? this.modelValue.length : 0) : true;
|
|
|
|
else return true;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
isSingleSelection() {
|
|
|
|
return this.selectionMode === 'single';
|
|
|
|
},
|
|
|
|
isRangeSelection() {
|
|
|
|
return this.selectionMode === 'range';
|
|
|
|
},
|
|
|
|
isMultipleSelection() {
|
|
|
|
return this.selectionMode === 'multiple';
|
|
|
|
},
|
|
|
|
formatValue(value) {
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
let formattedValue = '';
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (value) {
|
|
|
|
try {
|
|
|
|
if (this.isSingleSelection()) {
|
|
|
|
formattedValue = this.formatDateTime(value);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isMultipleSelection()) {
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let dateAsString = this.formatDateTime(value[i]);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
formattedValue += dateAsString;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
if (i !== value.length - 1) {
|
2022-09-06 12:03:37 +00:00
|
|
|
formattedValue += ', ';
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isRangeSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (value && value.length) {
|
|
|
|
let startDate = value[0];
|
|
|
|
let endDate = value[1];
|
|
|
|
|
|
|
|
formattedValue = this.formatDateTime(startDate);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (endDate) {
|
|
|
|
formattedValue += ' - ' + this.formatDateTime(endDate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} catch (err) {
|
2022-09-06 12:03:37 +00:00
|
|
|
formattedValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return formattedValue;
|
|
|
|
},
|
|
|
|
formatDateTime(date) {
|
|
|
|
let formattedValue = null;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (date) {
|
2023-12-11 10:20:45 +00:00
|
|
|
if (this.timeOnly) {
|
|
|
|
formattedValue = this.formatTime(date);
|
|
|
|
} else {
|
|
|
|
formattedValue = this.formatDate(date, this.datePattern);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-12-11 10:20:45 +00:00
|
|
|
if (this.showTime) {
|
|
|
|
formattedValue += ' ' + this.formatTime(date);
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return formattedValue;
|
|
|
|
},
|
|
|
|
formatDate(date, format) {
|
|
|
|
if (!date) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
let iFormat;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
const lookAhead = (match) => {
|
2022-09-14 11:26:01 +00:00
|
|
|
const matches = iFormat + 1 < format.length && format.charAt(iFormat + 1) === match;
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
iFormat++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
formatNumber = (match, value, len) => {
|
|
|
|
let num = '' + value;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (lookAhead(match)) {
|
|
|
|
while (num.length < len) {
|
|
|
|
num = '0' + num;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return num;
|
|
|
|
},
|
|
|
|
formatName = (match, value, shortNames, longNames) => {
|
2022-09-14 11:26:01 +00:00
|
|
|
return lookAhead(match) ? longNames[value] : shortNames[value];
|
2022-09-06 12:03:37 +00:00
|
|
|
};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
let output = '';
|
|
|
|
let literal = false;
|
|
|
|
|
|
|
|
if (date) {
|
|
|
|
for (iFormat = 0; iFormat < format.length; iFormat++) {
|
|
|
|
if (literal) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
|
2022-09-06 12:03:37 +00:00
|
|
|
literal = false;
|
|
|
|
} else {
|
|
|
|
output += format.charAt(iFormat);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (format.charAt(iFormat)) {
|
|
|
|
case 'd':
|
|
|
|
output += formatNumber('d', date.getDate(), 2);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
output += formatName('D', date.getDay(), this.$primevue.config.locale.dayNamesShort, this.$primevue.config.locale.dayNames);
|
|
|
|
break;
|
|
|
|
case 'o':
|
2022-09-14 11:26:01 +00:00
|
|
|
output += formatNumber('o', Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
output += formatNumber('m', date.getMonth() + 1, 2);
|
|
|
|
break;
|
|
|
|
case 'M':
|
2022-09-14 11:26:01 +00:00
|
|
|
output += formatName('M', date.getMonth(), this.$primevue.config.locale.monthNamesShort, this.$primevue.config.locale.monthNames);
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
output += lookAhead('y') ? date.getFullYear() : (date.getFullYear() % 100 < 10 ? '0' : '') + (date.getFullYear() % 100);
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
output += date.getTime();
|
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
output += date.getTime() * 10000 + this.ticksTo1970;
|
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case "'":
|
|
|
|
if (lookAhead("'")) {
|
|
|
|
output += "'";
|
2022-09-06 12:03:37 +00:00
|
|
|
} else {
|
|
|
|
literal = true;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
output += format.charAt(iFormat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return output;
|
|
|
|
},
|
|
|
|
formatTime(date) {
|
|
|
|
if (!date) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
let output = '';
|
|
|
|
let hours = date.getHours();
|
|
|
|
let minutes = date.getMinutes();
|
|
|
|
let seconds = date.getSeconds();
|
|
|
|
|
|
|
|
if (this.hourFormat === '12' && hours > 11 && hours !== 12) {
|
|
|
|
hours -= 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.hourFormat === '12') {
|
2022-09-14 11:26:01 +00:00
|
|
|
output += hours === 0 ? 12 : hours < 10 ? '0' + hours : hours;
|
|
|
|
} else {
|
|
|
|
output += hours < 10 ? '0' + hours : hours;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
output += ':';
|
2022-09-14 11:26:01 +00:00
|
|
|
output += minutes < 10 ? '0' + minutes : minutes;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (this.showSeconds) {
|
|
|
|
output += ':';
|
2022-09-14 11:26:01 +00:00
|
|
|
output += seconds < 10 ? '0' + seconds : seconds;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.hourFormat === '12') {
|
2022-12-08 11:04:25 +00:00
|
|
|
output += date.getHours() > 11 ? ` ${this.$primevue.config.locale.pm}` : ` ${this.$primevue.config.locale.am}`;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
},
|
|
|
|
onTodayButtonClick(event) {
|
|
|
|
let date = new Date();
|
|
|
|
let dateMeta = {
|
|
|
|
day: date.getDate(),
|
|
|
|
month: date.getMonth(),
|
|
|
|
year: date.getFullYear(),
|
|
|
|
otherMonth: date.getMonth() !== this.currentMonth || date.getFullYear() !== this.currentYear,
|
|
|
|
today: true,
|
|
|
|
selectable: true
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onDateSelect(null, dateMeta);
|
|
|
|
this.$emit('today-click', date);
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onClearButtonClick(event) {
|
|
|
|
this.updateModel(null);
|
|
|
|
this.overlayVisible = false;
|
|
|
|
this.$emit('clear-click', event);
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onTimePickerElementMouseDown(event, type, direction) {
|
|
|
|
if (this.isEnabled()) {
|
|
|
|
this.repeat(event, null, type, direction);
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTimePickerElementMouseUp(event) {
|
|
|
|
if (this.isEnabled()) {
|
|
|
|
this.clearTimePickerTimer();
|
|
|
|
this.updateModelTime();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTimePickerElementMouseLeave() {
|
|
|
|
this.clearTimePickerTimer();
|
|
|
|
},
|
|
|
|
repeat(event, interval, type, direction) {
|
2022-09-14 11:26:01 +00:00
|
|
|
let i = interval || 500;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.clearTimePickerTimer();
|
|
|
|
this.timePickerTimer = setTimeout(() => {
|
|
|
|
this.repeat(event, 100, type, direction);
|
|
|
|
}, i);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
switch (type) {
|
2022-09-06 12:03:37 +00:00
|
|
|
case 0:
|
2022-09-14 11:26:01 +00:00
|
|
|
if (direction === 1) this.incrementHour(event);
|
|
|
|
else this.decrementHour(event);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
case 1:
|
2022-09-14 11:26:01 +00:00
|
|
|
if (direction === 1) this.incrementMinute(event);
|
|
|
|
else this.decrementMinute(event);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
case 2:
|
2022-09-14 11:26:01 +00:00
|
|
|
if (direction === 1) this.incrementSecond(event);
|
|
|
|
else this.decrementSecond(event);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
convertTo24Hour(hours, pm) {
|
|
|
|
if (this.hourFormat == '12') {
|
|
|
|
if (hours === 12) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return pm ? 12 : 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
} else {
|
2022-09-14 11:26:01 +00:00
|
|
|
return pm ? hours + 12 : hours;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return hours;
|
|
|
|
},
|
|
|
|
validateTime(hour, minute, second, pm) {
|
|
|
|
let value = this.isComparable() ? this.modelValue : this.viewDate;
|
|
|
|
const convertedHour = this.convertTo24Hour(hour, pm);
|
|
|
|
|
|
|
|
if (this.isRangeSelection()) {
|
|
|
|
value = this.modelValue[1] || this.modelValue[0];
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.isMultipleSelection()) {
|
|
|
|
value = this.modelValue[this.modelValue.length - 1];
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
const valueDateString = value ? value.toDateString() : null;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) {
|
|
|
|
if (this.minDate.getHours() > convertedHour) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.minDate.getHours() === convertedHour) {
|
|
|
|
if (this.minDate.getMinutes() > minute) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.minDate.getMinutes() === minute) {
|
|
|
|
if (this.minDate.getSeconds() > second) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) {
|
|
|
|
if (this.maxDate.getHours() < convertedHour) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.maxDate.getHours() === convertedHour) {
|
|
|
|
if (this.maxDate.getMinutes() < minute) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.maxDate.getMinutes() === minute) {
|
|
|
|
if (this.maxDate.getSeconds() < second) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
incrementHour(event) {
|
|
|
|
let prevHour = this.currentHour;
|
2023-08-18 01:21:51 +00:00
|
|
|
let newHour = this.currentHour + Number(this.stepHour);
|
2022-09-06 12:03:37 +00:00
|
|
|
let newPM = this.pm;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.hourFormat == '24') newHour = newHour >= 24 ? newHour - 24 : newHour;
|
2022-09-06 12:03:37 +00:00
|
|
|
else if (this.hourFormat == '12') {
|
2023-01-23 13:13:09 +00:00
|
|
|
// Before the AM/PM break, now after
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevHour < 12 && newHour > 11) {
|
2022-09-14 11:26:01 +00:00
|
|
|
newPM = !this.pm;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
newHour = newHour >= 13 ? newHour - 12 : newHour;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
|
|
|
|
this.currentHour = newHour;
|
|
|
|
this.pm = newPM;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
decrementHour(event) {
|
|
|
|
let newHour = this.currentHour - this.stepHour;
|
|
|
|
let newPM = this.pm;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.hourFormat == '24') newHour = newHour < 0 ? 24 + newHour : newHour;
|
2022-09-06 12:03:37 +00:00
|
|
|
else if (this.hourFormat == '12') {
|
|
|
|
// If we were at noon/midnight, then switch
|
|
|
|
if (this.currentHour === 12) {
|
|
|
|
newPM = !this.pm;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
newHour = newHour <= 0 ? 12 + newHour : newHour;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
|
|
|
|
this.currentHour = newHour;
|
|
|
|
this.pm = newPM;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
incrementMinute(event) {
|
2023-08-18 01:21:51 +00:00
|
|
|
let newMinute = this.currentMinute + Number(this.stepMinute);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-01-23 13:06:08 +00:00
|
|
|
if (this.validateTime(this.currentHour, newMinute, this.currentSecond, this.pm)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.currentMinute = newMinute > 59 ? newMinute - 60 : newMinute;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
decrementMinute(event) {
|
|
|
|
let newMinute = this.currentMinute - this.stepMinute;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
newMinute = newMinute < 0 ? 60 + newMinute : newMinute;
|
|
|
|
|
2023-01-23 13:06:08 +00:00
|
|
|
if (this.validateTime(this.currentHour, newMinute, this.currentSecond, this.pm)) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentMinute = newMinute;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
incrementSecond(event) {
|
2023-08-18 01:21:51 +00:00
|
|
|
let newSecond = this.currentSecond + Number(this.stepSecond);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-01-23 13:06:08 +00:00
|
|
|
if (this.validateTime(this.currentHour, this.currentMinute, newSecond, this.pm)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.currentSecond = newSecond > 59 ? newSecond - 60 : newSecond;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
decrementSecond(event) {
|
|
|
|
let newSecond = this.currentSecond - this.stepSecond;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
newSecond = newSecond < 0 ? 60 + newSecond : newSecond;
|
|
|
|
|
2023-01-23 13:06:08 +00:00
|
|
|
if (this.validateTime(this.currentHour, this.currentMinute, newSecond, this.pm)) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentSecond = newSecond;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
updateModelTime() {
|
|
|
|
this.timePickerChange = true;
|
|
|
|
let value = this.isComparable() ? this.modelValue : this.viewDate;
|
|
|
|
|
|
|
|
if (this.isRangeSelection()) {
|
|
|
|
value = this.modelValue[1] || this.modelValue[0];
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.isMultipleSelection()) {
|
|
|
|
value = this.modelValue[this.modelValue.length - 1];
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value = value ? new Date(value.getTime()) : new Date();
|
|
|
|
|
|
|
|
if (this.hourFormat == '12') {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.currentHour === 12) value.setHours(this.pm ? 12 : 0);
|
|
|
|
else value.setHours(this.pm ? this.currentHour + 12 : this.currentHour);
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
value.setHours(this.currentHour);
|
|
|
|
}
|
|
|
|
|
|
|
|
value.setMinutes(this.currentMinute);
|
|
|
|
value.setSeconds(this.currentSecond);
|
|
|
|
|
|
|
|
if (this.isRangeSelection()) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.modelValue[1]) value = [this.modelValue[0], value];
|
|
|
|
else value = [value, null];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.isMultipleSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
value = [...this.modelValue.slice(0, -1), value];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateModel(value);
|
|
|
|
this.$emit('date-select', value);
|
2022-09-14 11:26:01 +00:00
|
|
|
setTimeout(() => (this.timePickerChange = false), 0);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
toggleAMPM(event) {
|
2022-12-08 11:04:25 +00:00
|
|
|
const validHour = this.validateTime(this.currentHour, this.currentMinute, this.currentSecond, !this.pm);
|
|
|
|
|
|
|
|
if (!validHour && (this.maxDate || this.minDate)) return;
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.pm = !this.pm;
|
|
|
|
this.updateModelTime();
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
clearTimePickerTimer() {
|
|
|
|
if (this.timePickerTimer) {
|
|
|
|
clearInterval(this.timePickerTimer);
|
|
|
|
}
|
|
|
|
},
|
2023-01-25 08:42:15 +00:00
|
|
|
onMonthSelect(event, { month, index }) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.view === 'month') {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.onDateSelect(event, { year: this.currentYear, month: index, day: 1, selectable: true });
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentMonth = index;
|
|
|
|
this.currentView = 'date';
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('month-change', { month: this.currentMonth + 1, year: this.currentYear });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(this.updateFocus, 0);
|
|
|
|
},
|
|
|
|
onYearSelect(event, year) {
|
|
|
|
if (this.view === 'year') {
|
2023-01-25 08:42:15 +00:00
|
|
|
this.onDateSelect(event, { year: year.value, month: 0, day: 1, selectable: true });
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2023-01-25 08:42:15 +00:00
|
|
|
this.currentYear = year.value;
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentView = 'month';
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('year-change', { month: this.currentMonth + 1, year: this.currentYear });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(this.updateFocus, 0);
|
|
|
|
},
|
|
|
|
updateCurrentMetaData() {
|
|
|
|
const viewDate = this.viewDate;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.currentMonth = viewDate.getMonth();
|
|
|
|
this.currentYear = viewDate.getFullYear();
|
|
|
|
|
|
|
|
if (this.showTime || this.timeOnly) {
|
|
|
|
this.updateCurrentTimeMeta(viewDate);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isValidSelection(value) {
|
|
|
|
if (value == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let isValid = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.isSingleSelection()) {
|
|
|
|
if (!this.isSelectable(value.getDate(), value.getMonth(), value.getFullYear(), false)) {
|
|
|
|
isValid = false;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (value.every((v) => this.isSelectable(v.getDate(), v.getMonth(), v.getFullYear(), false))) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.isRangeSelection()) {
|
|
|
|
isValid = value.length > 1 && value[1] > value[0] ? true : false;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return isValid;
|
|
|
|
},
|
|
|
|
parseValue(text) {
|
|
|
|
if (!text || text.trim().length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let value;
|
|
|
|
|
|
|
|
if (this.isSingleSelection()) {
|
|
|
|
value = this.parseDateTime(text);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isMultipleSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let tokens = text.split(',');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let token of tokens) {
|
|
|
|
value.push(this.parseDateTime(token.trim()));
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isRangeSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let tokens = text.split(' - ');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let i = 0; i < tokens.length; i++) {
|
|
|
|
value[i] = this.parseDateTime(tokens[i].trim());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
parseDateTime(text) {
|
|
|
|
let date;
|
|
|
|
let parts = text.split(' ');
|
|
|
|
|
2023-12-11 10:20:45 +00:00
|
|
|
if (this.timeOnly) {
|
2024-02-16 12:16:55 +00:00
|
|
|
date = new Date();
|
2023-12-11 10:20:45 +00:00
|
|
|
this.populateTime(date, parts[0], parts[1]);
|
2023-11-30 09:43:59 +00:00
|
|
|
} else {
|
2023-12-11 10:20:45 +00:00
|
|
|
const dateFormat = this.datePattern;
|
|
|
|
|
|
|
|
if (this.showTime) {
|
|
|
|
date = this.parseDate(parts[0], dateFormat);
|
|
|
|
this.populateTime(date, parts[1], parts[2]);
|
|
|
|
} else {
|
|
|
|
date = this.parseDate(text, dateFormat);
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return date;
|
|
|
|
},
|
|
|
|
populateTime(value, timeString, ampm) {
|
|
|
|
if (this.hourFormat == '12' && !ampm) {
|
|
|
|
throw 'Invalid Time';
|
|
|
|
}
|
|
|
|
|
2022-12-16 19:09:23 +00:00
|
|
|
this.pm = ampm === this.$primevue.config.locale.pm || ampm === this.$primevue.config.locale.pm.toLowerCase();
|
2022-09-06 12:03:37 +00:00
|
|
|
let time = this.parseTime(timeString);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value.setHours(time.hour);
|
|
|
|
value.setMinutes(time.minute);
|
|
|
|
value.setSeconds(time.second);
|
|
|
|
},
|
|
|
|
parseTime(value) {
|
|
|
|
let tokens = value.split(':');
|
|
|
|
let validTokenLength = this.showSeconds ? 3 : 2;
|
2022-09-14 11:26:01 +00:00
|
|
|
let regex = /^[0-9][0-9]$/;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (tokens.length !== validTokenLength || !tokens[0].match(regex) || !tokens[1].match(regex) || (this.showSeconds && !tokens[2].match(regex))) {
|
2022-09-14 11:26:01 +00:00
|
|
|
throw 'Invalid time';
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let h = parseInt(tokens[0]);
|
|
|
|
let m = parseInt(tokens[1]);
|
|
|
|
let s = this.showSeconds ? parseInt(tokens[2]) : null;
|
|
|
|
|
|
|
|
if (isNaN(h) || isNaN(m) || h > 23 || m > 59 || (this.hourFormat == '12' && h > 12) || (this.showSeconds && (isNaN(s) || s > 59))) {
|
2022-09-14 11:26:01 +00:00
|
|
|
throw 'Invalid time';
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.hourFormat == '12' && h !== 12 && this.pm) {
|
2022-09-14 11:26:01 +00:00
|
|
|
h += 12;
|
2023-10-05 13:08:07 +00:00
|
|
|
} else if (this.hourFormat == '12' && h == 12 && !this.pm) {
|
|
|
|
h = 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
return { hour: h, minute: m, second: s };
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
parseDate(value, format) {
|
|
|
|
if (format == null || value == null) {
|
2022-09-14 11:26:01 +00:00
|
|
|
throw 'Invalid arguments';
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
value = typeof value === 'object' ? value.toString() : value + '';
|
|
|
|
|
|
|
|
if (value === '') {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
let iFormat,
|
|
|
|
dim,
|
|
|
|
extra,
|
|
|
|
iValue = 0,
|
|
|
|
shortYearCutoff = typeof this.shortYearCutoff !== 'string' ? this.shortYearCutoff : (new Date().getFullYear() % 100) + parseInt(this.shortYearCutoff, 10),
|
|
|
|
year = -1,
|
|
|
|
month = -1,
|
|
|
|
day = -1,
|
|
|
|
doy = -1,
|
|
|
|
literal = false,
|
|
|
|
date,
|
|
|
|
lookAhead = (match) => {
|
|
|
|
let matches = iFormat + 1 < format.length && format.charAt(iFormat + 1) === match;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (matches) {
|
|
|
|
iFormat++;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
return matches;
|
|
|
|
},
|
|
|
|
getNumber = (match) => {
|
|
|
|
let isDoubled = lookAhead(match),
|
|
|
|
size = match === '@' ? 14 : match === '!' ? 20 : match === 'y' && isDoubled ? 4 : match === 'o' ? 3 : 2,
|
|
|
|
minSize = match === 'y' ? size : 1,
|
|
|
|
digits = new RegExp('^\\d{' + minSize + ',' + size + '}'),
|
|
|
|
num = value.substring(iValue).match(digits);
|
|
|
|
|
|
|
|
if (!num) {
|
|
|
|
throw 'Missing number at position ' + iValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
iValue += num[0].length;
|
|
|
|
|
|
|
|
return parseInt(num[0], 10);
|
|
|
|
},
|
|
|
|
getName = (match, shortNames, longNames) => {
|
|
|
|
let index = -1;
|
|
|
|
let arr = lookAhead(match) ? longNames : shortNames;
|
|
|
|
let names = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
names.push([i, arr[i]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
names.sort((a, b) => {
|
|
|
|
return -(a[1].length - b[1].length);
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let i = 0; i < names.length; i++) {
|
|
|
|
let name = names[i][1];
|
|
|
|
|
|
|
|
if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) {
|
|
|
|
index = names[i][0];
|
|
|
|
iValue += name.length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
return index + 1;
|
|
|
|
} else {
|
|
|
|
throw 'Unknown name at position ' + iValue;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
checkLiteral = () => {
|
|
|
|
if (value.charAt(iValue) !== format.charAt(iFormat)) {
|
|
|
|
throw 'Unexpected literal at position ' + iValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
iValue++;
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (this.currentView === 'month') {
|
|
|
|
day = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (iFormat = 0; iFormat < format.length; iFormat++) {
|
|
|
|
if (literal) {
|
|
|
|
if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
|
|
|
|
literal = false;
|
|
|
|
} else {
|
|
|
|
checkLiteral();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (format.charAt(iFormat)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
case 'd':
|
|
|
|
day = getNumber('d');
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case 'D':
|
|
|
|
getName('D', this.$primevue.config.locale.dayNamesShort, this.$primevue.config.locale.dayNames);
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case 'o':
|
|
|
|
doy = getNumber('o');
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case 'm':
|
|
|
|
month = getNumber('m');
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case 'M':
|
|
|
|
month = getName('M', this.$primevue.config.locale.monthNamesShort, this.$primevue.config.locale.monthNames);
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case 'y':
|
|
|
|
year = getNumber('y');
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case '@':
|
|
|
|
date = new Date(getNumber('@'));
|
2022-09-06 12:03:37 +00:00
|
|
|
year = date.getFullYear();
|
|
|
|
month = date.getMonth() + 1;
|
|
|
|
day = date.getDate();
|
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
case '!':
|
|
|
|
date = new Date((getNumber('!') - this.ticksTo1970) / 10000);
|
2022-09-06 12:03:37 +00:00
|
|
|
year = date.getFullYear();
|
|
|
|
month = date.getMonth() + 1;
|
|
|
|
day = date.getDate();
|
|
|
|
break;
|
|
|
|
case "'":
|
|
|
|
if (lookAhead("'")) {
|
|
|
|
checkLiteral();
|
|
|
|
} else {
|
|
|
|
literal = true;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
checkLiteral();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iValue < value.length) {
|
|
|
|
extra = value.substr(iValue);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (!/^\s+/.test(extra)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
throw 'Extra/unparsed characters found in date: ' + extra;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (year === -1) {
|
|
|
|
year = new Date().getFullYear();
|
|
|
|
} else if (year < 100) {
|
2022-09-14 11:26:01 +00:00
|
|
|
year += new Date().getFullYear() - (new Date().getFullYear() % 100) + (year <= shortYearCutoff ? 0 : -100);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doy > -1) {
|
|
|
|
month = 1;
|
|
|
|
day = doy;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
do {
|
|
|
|
dim = this.getDaysCountInMonth(year, month - 1);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (day <= dim) {
|
|
|
|
break;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
month++;
|
|
|
|
day -= dim;
|
2022-09-14 11:26:01 +00:00
|
|
|
// eslint-disable-next-line
|
2022-09-06 12:03:37 +00:00
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
date = this.daylightSavingAdjust(new Date(year, month - 1, day));
|
|
|
|
|
|
|
|
if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
|
2022-09-14 11:26:01 +00:00
|
|
|
throw 'Invalid date'; // E.g. 31/02/00
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return date;
|
|
|
|
},
|
|
|
|
getWeekNumber(date) {
|
|
|
|
let checkDate = new Date(date.getTime());
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
|
2022-09-06 12:03:37 +00:00
|
|
|
let time = checkDate.getTime();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
checkDate.setMonth(0);
|
|
|
|
checkDate.setDate(1);
|
|
|
|
|
|
|
|
return Math.floor(Math.round((time - checkDate.getTime()) / 86400000) / 7) + 1;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onDateCellKeydown(event, date, groupIndex) {
|
|
|
|
const cellContent = event.currentTarget;
|
|
|
|
const cell = cellContent.parentElement;
|
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
const cellIndex = DomHandler.index(cell);
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowDown': {
|
|
|
|
cellContent.tabIndex = '-1';
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
let nextRow = cell.parentElement.nextElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextRow) {
|
2022-12-08 11:04:25 +00:00
|
|
|
let tableRowIndex = DomHandler.index(cell.parentElement);
|
|
|
|
const tableRows = Array.from(cell.parentElement.parentElement.children);
|
|
|
|
const nextTableRows = tableRows.slice(tableRowIndex + 1);
|
|
|
|
|
|
|
|
let hasNextFocusableDate = nextTableRows.find((el) => {
|
|
|
|
let focusCell = el.children[cellIndex].children[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
return !DomHandler.getAttribute(focusCell, 'data-p-disabled');
|
2022-12-08 11:04:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (hasNextFocusableDate) {
|
|
|
|
let focusCell = hasNextFocusableDate.children[cellIndex].children[0];
|
|
|
|
|
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
|
|
|
} else {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowUp': {
|
|
|
|
cellContent.tabIndex = '-1';
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-09-20 19:53:39 +00:00
|
|
|
if (event.altKey) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
this.focused = true;
|
|
|
|
} else {
|
|
|
|
let prevRow = cell.parentElement.previousElementSibling;
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2023-09-20 19:53:39 +00:00
|
|
|
if (prevRow) {
|
|
|
|
let tableRowIndex = DomHandler.index(cell.parentElement);
|
|
|
|
const tableRows = Array.from(cell.parentElement.parentElement.children);
|
|
|
|
const prevTableRows = tableRows.slice(0, tableRowIndex).reverse();
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2023-09-20 19:53:39 +00:00
|
|
|
let hasNextFocusableDate = prevTableRows.find((el) => {
|
|
|
|
let focusCell = el.children[cellIndex].children[0];
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2023-09-20 19:53:39 +00:00
|
|
|
return !DomHandler.getAttribute(focusCell, 'data-p-disabled');
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-09-20 19:53:39 +00:00
|
|
|
if (hasNextFocusableDate) {
|
|
|
|
let focusCell = hasNextFocusableDate.children[cellIndex].children[0];
|
|
|
|
|
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: true };
|
|
|
|
this.navBackward(event);
|
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: true };
|
|
|
|
this.navBackward(event);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowLeft': {
|
|
|
|
cellContent.tabIndex = '-1';
|
|
|
|
let prevCell = cell.previousElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevCell) {
|
2022-12-08 11:04:25 +00:00
|
|
|
const cells = Array.from(cell.parentElement.children);
|
|
|
|
const prevCells = cells.slice(0, cellIndex).reverse();
|
|
|
|
|
|
|
|
let hasNextFocusableDate = prevCells.find((el) => {
|
|
|
|
let focusCell = el.children[0];
|
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
return !DomHandler.getAttribute(focusCell, 'data-p-disabled');
|
2022-12-08 11:04:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (hasNextFocusableDate) {
|
|
|
|
let focusCell = hasNextFocusableDate.children[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
2022-12-08 11:04:25 +00:00
|
|
|
} else {
|
|
|
|
this.navigateToMonth(event, true, groupIndex);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navigateToMonth(event, true, groupIndex);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowRight': {
|
|
|
|
cellContent.tabIndex = '-1';
|
|
|
|
let nextCell = cell.nextElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextCell) {
|
2022-12-08 11:04:25 +00:00
|
|
|
const cells = Array.from(cell.parentElement.children);
|
|
|
|
const nextCells = cells.slice(cellIndex + 1);
|
|
|
|
let hasNextFocusableDate = nextCells.find((el) => {
|
|
|
|
let focusCell = el.children[0];
|
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
return !DomHandler.getAttribute(focusCell, 'data-p-disabled');
|
2022-12-08 11:04:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (hasNextFocusableDate) {
|
|
|
|
let focusCell = hasNextFocusableDate.children[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
2022-12-08 11:04:25 +00:00
|
|
|
} else {
|
|
|
|
this.navigateToMonth(event, false, groupIndex);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navigateToMonth(event, false, groupIndex);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Enter':
|
2023-12-20 10:45:43 +00:00
|
|
|
case 'NumpadEnter':
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
case 'Space': {
|
|
|
|
this.onDateSelect(event, date);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Escape': {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Tab': {
|
|
|
|
if (!this.inline) {
|
|
|
|
this.trapFocus(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Home': {
|
|
|
|
cellContent.tabIndex = '-1';
|
|
|
|
let currentRow = cell.parentElement;
|
|
|
|
let focusCell = currentRow.children[0].children[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
if (DomHandler.getAttribute(focusCell, 'data-p-disabled')) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navigateToMonth(event, true, groupIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'End': {
|
|
|
|
cellContent.tabIndex = '-1';
|
|
|
|
let currentRow = cell.parentElement;
|
2022-09-14 11:26:01 +00:00
|
|
|
let focusCell = currentRow.children[currentRow.children.length - 1].children[0];
|
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
if (DomHandler.getAttribute(focusCell, 'data-p-disabled')) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navigateToMonth(event, false, groupIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'PageUp': {
|
|
|
|
cellContent.tabIndex = '-1';
|
|
|
|
if (event.shiftKey) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else this.navigateToMonth(event, true, groupIndex);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'PageDown': {
|
|
|
|
cellContent.tabIndex = '-1';
|
|
|
|
if (event.shiftKey) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else this.navigateToMonth(event, false, groupIndex);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
//no op
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
navigateToMonth(event, prev, groupIndex) {
|
|
|
|
if (prev) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.numberOfMonths === 1 || groupIndex === 0) {
|
|
|
|
this.navigationState = { backward: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let prevMonthContainer = this.overlay.children[groupIndex - 1];
|
2023-05-19 10:32:44 +00:00
|
|
|
let cells = DomHandler.find(prevMonthContainer, 'table td span:not([data-p-disabled="true"]):not([data-p-ink="true"])');
|
2022-09-06 12:03:37 +00:00
|
|
|
let focusCell = cells[cells.length - 1];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
if (this.numberOfMonths === 1 || groupIndex === this.numberOfMonths - 1) {
|
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let nextMonthContainer = this.overlay.children[groupIndex + 1];
|
2023-05-19 10:32:44 +00:00
|
|
|
let focusCell = DomHandler.findSingle(nextMonthContainer, 'table td span:not([data-p-disabled="true"]):not([data-p-ink="true"])');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
focusCell.tabIndex = '0';
|
|
|
|
focusCell.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onMonthCellKeydown(event, index) {
|
|
|
|
const cell = event.currentTarget;
|
|
|
|
|
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowUp':
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
case 'ArrowDown': {
|
|
|
|
cell.tabIndex = '-1';
|
|
|
|
var cells = cell.parentElement.children;
|
|
|
|
var cellIndex = DomHandler.index(cell);
|
2022-09-14 11:26:01 +00:00
|
|
|
let nextCell = cells[event.code === 'ArrowDown' ? cellIndex + 3 : cellIndex - 3];
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextCell) {
|
|
|
|
nextCell.tabIndex = '0';
|
|
|
|
nextCell.focus();
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowLeft': {
|
|
|
|
cell.tabIndex = '-1';
|
|
|
|
let prevCell = cell.previousElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevCell) {
|
|
|
|
prevCell.tabIndex = '0';
|
|
|
|
prevCell.focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowRight': {
|
|
|
|
cell.tabIndex = '-1';
|
|
|
|
let nextCell = cell.nextElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextCell) {
|
|
|
|
nextCell.tabIndex = '0';
|
|
|
|
nextCell.focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'PageUp': {
|
|
|
|
if (event.shiftKey) return;
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'PageDown': {
|
|
|
|
if (event.shiftKey) return;
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Enter':
|
2023-12-20 10:45:43 +00:00
|
|
|
case 'NumpadEnter':
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
case 'Space': {
|
|
|
|
this.onMonthSelect(event, index);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Escape': {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Tab': {
|
|
|
|
this.trapFocus(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
//no op
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onYearCellKeydown(event, index) {
|
|
|
|
const cell = event.currentTarget;
|
|
|
|
|
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowUp':
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
case 'ArrowDown': {
|
2022-09-06 12:03:37 +00:00
|
|
|
cell.tabIndex = '-1';
|
|
|
|
var cells = cell.parentElement.children;
|
|
|
|
var cellIndex = DomHandler.index(cell);
|
|
|
|
let nextCell = cells[event.code === 'ArrowDown' ? cellIndex + 2 : cellIndex - 2];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextCell) {
|
|
|
|
nextCell.tabIndex = '0';
|
|
|
|
nextCell.focus();
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowLeft': {
|
|
|
|
cell.tabIndex = '-1';
|
|
|
|
let prevCell = cell.previousElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevCell) {
|
|
|
|
prevCell.tabIndex = '0';
|
|
|
|
prevCell.focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'ArrowRight': {
|
|
|
|
cell.tabIndex = '-1';
|
|
|
|
let nextCell = cell.nextElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextCell) {
|
|
|
|
nextCell.tabIndex = '0';
|
|
|
|
nextCell.focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'PageUp': {
|
|
|
|
if (event.shiftKey) return;
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: true };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navBackward(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'PageDown': {
|
|
|
|
if (event.shiftKey) return;
|
2022-09-14 11:26:01 +00:00
|
|
|
this.navigationState = { backward: false };
|
2022-09-06 12:03:37 +00:00
|
|
|
this.navForward(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Enter':
|
2023-12-20 10:45:43 +00:00
|
|
|
case 'NumpadEnter':
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
case 'Space': {
|
|
|
|
this.onYearSelect(event, index);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Escape': {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'Tab': {
|
|
|
|
this.trapFocus(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
//no op
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updateFocus() {
|
|
|
|
let cell;
|
|
|
|
|
|
|
|
if (this.navigationState) {
|
|
|
|
if (this.navigationState.button) {
|
|
|
|
this.initFocusableCell();
|
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
if (this.navigationState.backward) this.previousButton.focus();
|
|
|
|
else this.nextButton.focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.navigationState.backward) {
|
|
|
|
let cells;
|
|
|
|
|
|
|
|
if (this.currentView === 'month') {
|
2023-05-19 10:32:44 +00:00
|
|
|
cells = DomHandler.find(this.overlay, '[data-pc-section="monthpicker"] [data-pc-section="month"]:not([data-p-disabled="true"])');
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.currentView === 'year') {
|
2023-05-19 10:32:44 +00:00
|
|
|
cells = DomHandler.find(this.overlay, '[data-pc-section="yearpicker"] [data-pc-section="year"]:not([data-p-disabled="true"])');
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2023-05-19 10:32:44 +00:00
|
|
|
cells = DomHandler.find(this.overlay, 'table td span:not([data-p-disabled="true"]):not([data-p-ink="true"])');
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cells && cells.length > 0) {
|
|
|
|
cell = cells[cells.length - 1];
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.currentView === 'month') {
|
2023-05-19 10:32:44 +00:00
|
|
|
cell = DomHandler.findSingle(this.overlay, '[data-pc-section="monthpicker"] [data-pc-section="month"]:not([data-p-disabled="true"])');
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.currentView === 'year') {
|
2023-05-19 10:32:44 +00:00
|
|
|
cell = DomHandler.findSingle(this.overlay, '[data-pc-section="yearpicker"] [data-pc-section="year"]:not([data-p-disabled="true"])');
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2023-05-19 10:32:44 +00:00
|
|
|
cell = DomHandler.findSingle(this.overlay, 'table td span:not([data-p-disabled="true"]):not([data-p-ink="true"])');
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell) {
|
|
|
|
cell.tabIndex = '0';
|
|
|
|
cell.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.navigationState = null;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.initFocusableCell();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
initFocusableCell() {
|
|
|
|
let cell;
|
|
|
|
|
|
|
|
if (this.currentView === 'month') {
|
2023-05-19 10:32:44 +00:00
|
|
|
let cells = DomHandler.find(this.overlay, '[data-pc-section="monthpicker"] [data-pc-section="month"]');
|
|
|
|
let selectedCell = DomHandler.findSingle(this.overlay, '[data-pc-section="monthpicker"] [data-pc-section="month"][data-p-highlight="true"]');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
cells.forEach((cell) => (cell.tabIndex = -1));
|
2022-09-06 12:03:37 +00:00
|
|
|
cell = selectedCell || cells[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.currentView === 'year') {
|
2023-05-19 10:32:44 +00:00
|
|
|
let cells = DomHandler.find(this.overlay, '[data-pc-section="yearpicker"] [data-pc-section="year"]');
|
|
|
|
let selectedCell = DomHandler.findSingle(this.overlay, '[data-pc-section="yearpicker"] [data-pc-section="year"][data-p-highlight="true"]');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
cells.forEach((cell) => (cell.tabIndex = -1));
|
2022-09-06 12:03:37 +00:00
|
|
|
cell = selectedCell || cells[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2023-05-19 10:32:44 +00:00
|
|
|
cell = DomHandler.findSingle(this.overlay, 'span[data-p-highlight="true"]');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (!cell) {
|
2023-09-18 07:59:33 +00:00
|
|
|
let todayCell = DomHandler.findSingle(this.overlay, 'td.p-datepicker-today span:not([data-p-disabled="true"]):not([data-p-ink="true"])');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
if (todayCell) cell = todayCell;
|
2023-09-18 07:59:33 +00:00
|
|
|
else cell = DomHandler.findSingle(this.overlay, '.p-datepicker-calendar td span:not([data-p-disabled="true"]):not([data-p-ink="true"])');
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell) {
|
|
|
|
cell.tabIndex = '0';
|
|
|
|
|
2022-12-28 13:39:40 +00:00
|
|
|
if (!this.inline && (!this.navigationState || !this.navigationState.button) && !this.timePickerChange) {
|
2023-09-18 07:43:49 +00:00
|
|
|
if (!this.manualInput) cell.focus();
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.preventFocus = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
trapFocus(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
let focusableElements = DomHandler.getFocusableElements(this.overlay);
|
|
|
|
|
|
|
|
if (focusableElements && focusableElements.length > 0) {
|
|
|
|
if (!document.activeElement) {
|
|
|
|
focusableElements[0].focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let focusedIndex = focusableElements.indexOf(document.activeElement);
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (focusedIndex === -1 || focusedIndex === 0) focusableElements[focusableElements.length - 1].focus();
|
|
|
|
else focusableElements[focusedIndex - 1].focus();
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (focusedIndex === -1) {
|
|
|
|
if (this.timeOnly) {
|
|
|
|
focusableElements[0].focus();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let spanIndex = null;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < focusableElements.length; i++) {
|
|
|
|
if (focusableElements[i].tagName === 'SPAN') spanIndex = i;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
focusableElements[spanIndex].focus();
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (focusedIndex === focusableElements.length - 1) focusableElements[0].focus();
|
|
|
|
else focusableElements[focusedIndex + 1].focus();
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onContainerButtonKeydown(event) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'Tab':
|
|
|
|
this.trapFocus(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
case 'Escape':
|
|
|
|
this.overlayVisible = false;
|
|
|
|
event.preventDefault();
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
//Noop
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('keydown', event);
|
|
|
|
},
|
|
|
|
onInput(event) {
|
|
|
|
try {
|
|
|
|
this.selectionStart = this.input.selectionStart;
|
|
|
|
this.selectionEnd = this.input.selectionEnd;
|
|
|
|
|
|
|
|
let value = this.parseValue(event.target.value);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.isValidSelection(value)) {
|
|
|
|
this.typeUpdate = true;
|
|
|
|
this.updateModel(value);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} catch (err) {
|
2022-09-06 12:03:37 +00:00
|
|
|
/* NoOp */
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('input', event);
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onInputClick() {
|
2023-05-09 13:51:50 +00:00
|
|
|
if (this.showOnFocus && this.isEnabled() && !this.overlayVisible) {
|
2022-12-08 11:04:25 +00:00
|
|
|
this.overlayVisible = true;
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
onFocus(event) {
|
|
|
|
if (this.showOnFocus && this.isEnabled()) {
|
|
|
|
this.overlayVisible = true;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.focused = true;
|
|
|
|
this.$emit('focus', event);
|
|
|
|
},
|
|
|
|
onBlur(event) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('blur', { originalEvent: event, value: event.target.value });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.focused = false;
|
|
|
|
event.target.value = this.formatValue(this.modelValue);
|
|
|
|
},
|
|
|
|
onKeyDown(event) {
|
|
|
|
if (event.code === 'ArrowDown' && this.overlay) {
|
|
|
|
this.trapFocus(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (event.code === 'ArrowDown' && !this.overlay) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlayVisible = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (event.code === 'Escape') {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.overlayVisible) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (event.code === 'Tab') {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.overlay) {
|
2022-09-14 11:26:01 +00:00
|
|
|
DomHandler.getFocusableElements(this.overlay).forEach((el) => (el.tabIndex = '-1'));
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.overlayVisible) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
2024-01-11 17:30:42 +00:00
|
|
|
} else if (event.code === 'Enter') {
|
2024-01-11 19:05:51 +00:00
|
|
|
if (this.manualInput && event.target.value !== null && event.target.value?.trim() !== '') {
|
|
|
|
try {
|
|
|
|
let value = this.parseValue(event.target.value);
|
|
|
|
|
|
|
|
if (this.isValidSelection(value)) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
/* NoOp */
|
|
|
|
}
|
2024-01-09 15:31:12 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
overlayRef(el) {
|
|
|
|
this.overlay = el;
|
|
|
|
},
|
|
|
|
inputRef(el) {
|
2024-03-18 10:01:35 +00:00
|
|
|
this.input = el ? el.$el : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-05-19 10:32:44 +00:00
|
|
|
previousButtonRef(el) {
|
2024-04-09 06:05:44 +00:00
|
|
|
this.previousButton = el ? el.$el : undefined;
|
2023-05-19 10:32:44 +00:00
|
|
|
},
|
|
|
|
nextButtonRef(el) {
|
2024-04-09 06:05:44 +00:00
|
|
|
this.nextButton = el ? el.$el : undefined;
|
2023-05-19 10:32:44 +00:00
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
getMonthName(index) {
|
|
|
|
return this.$primevue.config.locale.monthNames[index];
|
|
|
|
},
|
|
|
|
getYear(month) {
|
|
|
|
return this.currentView === 'month' ? this.currentYear : month.year;
|
|
|
|
},
|
|
|
|
onOverlayClick(event) {
|
|
|
|
if (!this.inline) {
|
|
|
|
OverlayEventBus.emit('overlay-click', {
|
|
|
|
originalEvent: event,
|
|
|
|
target: this.$el
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onOverlayKeyDown(event) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'Escape':
|
2023-11-01 18:46:46 +00:00
|
|
|
if (!this.inline) {
|
|
|
|
this.input.focus();
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onOverlayMouseUp(event) {
|
|
|
|
this.onOverlayClick(event);
|
|
|
|
},
|
|
|
|
createResponsiveStyle() {
|
2023-05-19 10:32:44 +00:00
|
|
|
if (this.numberOfMonths > 1 && this.responsiveOptions && !this.isUnstyled) {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (!this.responsiveStyleElement) {
|
|
|
|
this.responsiveStyleElement = document.createElement('style');
|
|
|
|
this.responsiveStyleElement.type = 'text/css';
|
2023-08-11 01:34:02 +00:00
|
|
|
DomHandler.setAttribute(this.responsiveStyleElement, 'nonce', this.$primevue?.config?.csp?.nonce);
|
2022-09-06 12:03:37 +00:00
|
|
|
document.body.appendChild(this.responsiveStyleElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
let innerHTML = '';
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.responsiveOptions) {
|
2023-10-06 02:00:36 +00:00
|
|
|
const comparer = ObjectUtils.localeComparator();
|
2023-08-18 12:52:27 +00:00
|
|
|
let responsiveOptions = [...this.responsiveOptions].filter((o) => !!(o.breakpoint && o.numMonths)).sort((o1, o2) => -1 * comparer(o1.breakpoint, o2.breakpoint));
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < responsiveOptions.length; i++) {
|
|
|
|
let { breakpoint, numMonths } = responsiveOptions[i];
|
|
|
|
let styles = `
|
|
|
|
.p-datepicker[${this.attributeSelector}] .p-datepicker-group:nth-child(${numMonths}) .p-datepicker-next {
|
2023-10-17 19:27:27 +00:00
|
|
|
display: inline-flex;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
for (let j = numMonths; j < this.numberOfMonths; j++) {
|
|
|
|
styles += `
|
|
|
|
.p-datepicker[${this.attributeSelector}] .p-datepicker-group:nth-child(${j + 1}) {
|
2023-10-17 19:27:27 +00:00
|
|
|
display: none;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
`;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
innerHTML += `
|
|
|
|
@media screen and (max-width: ${breakpoint}) {
|
|
|
|
${styles}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
`;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.responsiveStyleElement.innerHTML = innerHTML;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
destroyResponsiveStyleElement() {
|
|
|
|
if (this.responsiveStyleElement) {
|
|
|
|
this.responsiveStyleElement.remove();
|
|
|
|
this.responsiveStyleElement = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
viewDate() {
|
|
|
|
let propValue = this.modelValue;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (propValue && Array.isArray(propValue)) {
|
|
|
|
if (this.isRangeSelection()) {
|
2022-12-08 11:04:25 +00:00
|
|
|
propValue = this.inline ? propValue[0] : propValue[1] || propValue[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isMultipleSelection()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
propValue = propValue[propValue.length - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propValue && typeof propValue !== 'string') {
|
|
|
|
return propValue;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let today = new Date();
|
|
|
|
|
|
|
|
if (this.maxDate && this.maxDate < today) {
|
|
|
|
return this.maxDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minDate && this.minDate > today) {
|
|
|
|
return this.minDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return today;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
inputFieldValue() {
|
|
|
|
return this.formatValue(this.modelValue);
|
|
|
|
},
|
|
|
|
months() {
|
|
|
|
let months = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < this.numberOfMonths; i++) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let month = this.currentMonth + i;
|
|
|
|
let year = this.currentYear;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (month > 11) {
|
2022-09-14 11:26:01 +00:00
|
|
|
month = (month % 11) - 1;
|
2022-09-06 12:03:37 +00:00
|
|
|
year = year + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
let dates = [];
|
|
|
|
let firstDay = this.getFirstDayOfMonthIndex(month, year);
|
|
|
|
let daysLength = this.getDaysCountInMonth(month, year);
|
|
|
|
let prevMonthDaysLength = this.getDaysCountInPrevMonth(month, year);
|
|
|
|
let dayNo = 1;
|
|
|
|
let today = new Date();
|
|
|
|
let weekNumbers = [];
|
|
|
|
let monthRows = Math.ceil((daysLength + firstDay) / 7);
|
|
|
|
|
|
|
|
for (let i = 0; i < monthRows; i++) {
|
|
|
|
let week = [];
|
|
|
|
|
|
|
|
if (i == 0) {
|
2022-09-14 11:26:01 +00:00
|
|
|
for (let j = prevMonthDaysLength - firstDay + 1; j <= prevMonthDaysLength; j++) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let prev = this.getPreviousMonthAndYear(month, year);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
week.push({ day: j, month: prev.month, year: prev.year, otherMonth: true, today: this.isToday(today, j, prev.month, prev.year), selectable: this.isSelectable(j, prev.month, prev.year, true) });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let remainingDaysLength = 7 - week.length;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let j = 0; j < remainingDaysLength; j++) {
|
2022-09-14 11:26:01 +00:00
|
|
|
week.push({ day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year), selectable: this.isSelectable(dayNo, month, year, false) });
|
2022-09-06 12:03:37 +00:00
|
|
|
dayNo++;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let j = 0; j < 7; j++) {
|
|
|
|
if (dayNo > daysLength) {
|
|
|
|
let next = this.getNextMonthAndYear(month, year);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
week.push({
|
|
|
|
day: dayNo - daysLength,
|
|
|
|
month: next.month,
|
|
|
|
year: next.year,
|
|
|
|
otherMonth: true,
|
|
|
|
today: this.isToday(today, dayNo - daysLength, next.month, next.year),
|
|
|
|
selectable: this.isSelectable(dayNo - daysLength, next.month, next.year, true)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
week.push({ day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year), selectable: this.isSelectable(dayNo, month, year, false) });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dayNo++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.showWeek) {
|
|
|
|
weekNumbers.push(this.getWeekNumber(new Date(week[0].year, week[0].month, week[0].day)));
|
|
|
|
}
|
|
|
|
|
|
|
|
dates.push(week);
|
|
|
|
}
|
|
|
|
|
|
|
|
months.push({
|
|
|
|
month: month,
|
|
|
|
year: year,
|
|
|
|
dates: dates,
|
|
|
|
weekNumbers: weekNumbers
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return months;
|
|
|
|
},
|
|
|
|
weekDays() {
|
|
|
|
let weekDays = [];
|
|
|
|
let dayIndex = this.$primevue.config.locale.firstDayOfWeek;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
|
weekDays.push(this.$primevue.config.locale.dayNamesMin[dayIndex]);
|
2022-09-14 11:26:01 +00:00
|
|
|
dayIndex = dayIndex == 6 ? 0 : ++dayIndex;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return weekDays;
|
|
|
|
},
|
|
|
|
ticksTo1970() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return ((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
sundayIndex() {
|
|
|
|
return this.$primevue.config.locale.firstDayOfWeek > 0 ? 7 - this.$primevue.config.locale.firstDayOfWeek : 0;
|
|
|
|
},
|
|
|
|
datePattern() {
|
|
|
|
return this.dateFormat || this.$primevue.config.locale.dateFormat;
|
|
|
|
},
|
|
|
|
yearOptions() {
|
|
|
|
if (this.yearRange) {
|
|
|
|
let $vm = this;
|
|
|
|
const years = this.yearRange.split(':');
|
|
|
|
let yearStart = parseInt(years[0]);
|
|
|
|
let yearEnd = parseInt(years[1]);
|
|
|
|
let yearOptions = [];
|
|
|
|
|
|
|
|
if (this.currentYear < yearStart) {
|
|
|
|
$vm.currentYear = yearEnd;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.currentYear > yearEnd) {
|
2022-09-06 12:03:37 +00:00
|
|
|
$vm.currentYear = yearStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = yearStart; i <= yearEnd; i++) {
|
|
|
|
yearOptions.push(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return yearOptions;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
monthPickerValues() {
|
|
|
|
let monthPickerValues = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-03-09 11:08:26 +00:00
|
|
|
const isSelectableMonth = (baseMonth) => {
|
|
|
|
if (this.minDate) {
|
|
|
|
const minMonth = this.minDate.getMonth();
|
|
|
|
const minYear = this.minDate.getFullYear();
|
2023-01-25 08:42:15 +00:00
|
|
|
|
2023-03-09 11:08:26 +00:00
|
|
|
if (this.currentYear < minYear || (this.currentYear === minYear && baseMonth < minMonth)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 08:42:15 +00:00
|
|
|
|
2023-03-09 11:08:26 +00:00
|
|
|
if (this.maxDate) {
|
|
|
|
const maxMonth = this.maxDate.getMonth();
|
|
|
|
const maxYear = this.maxDate.getFullYear();
|
2023-01-25 08:42:15 +00:00
|
|
|
|
2023-03-09 11:08:26 +00:00
|
|
|
if (this.currentYear > maxYear || (this.currentYear === maxYear && baseMonth > maxMonth)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let i = 0; i <= 11; i++) {
|
|
|
|
monthPickerValues.push({ value: this.$primevue.config.locale.monthNamesShort[i], selectable: isSelectableMonth(i) });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return monthPickerValues;
|
|
|
|
},
|
|
|
|
yearPickerValues() {
|
|
|
|
let yearPickerValues = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
let base = this.currentYear - (this.currentYear % 10);
|
|
|
|
|
2023-03-09 11:08:26 +00:00
|
|
|
const isSelectableYear = (baseYear) => {
|
|
|
|
if (this.minDate) {
|
|
|
|
if (this.minDate.getFullYear() > baseYear) return false;
|
|
|
|
}
|
2023-01-25 08:42:15 +00:00
|
|
|
|
2023-03-09 11:08:26 +00:00
|
|
|
if (this.maxDate) {
|
|
|
|
if (this.maxDate.getFullYear() < baseYear) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
yearPickerValues.push({ value: base + i, selectable: isSelectableYear(base + i) });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return yearPickerValues;
|
|
|
|
},
|
|
|
|
formattedCurrentHour() {
|
|
|
|
return this.currentHour < 10 ? '0' + this.currentHour : this.currentHour;
|
|
|
|
},
|
|
|
|
formattedCurrentMinute() {
|
|
|
|
return this.currentMinute < 10 ? '0' + this.currentMinute : this.currentMinute;
|
|
|
|
},
|
|
|
|
formattedCurrentSecond() {
|
|
|
|
return this.currentSecond < 10 ? '0' + this.currentSecond : this.currentSecond;
|
|
|
|
},
|
|
|
|
todayLabel() {
|
|
|
|
return this.$primevue.config.locale.today;
|
|
|
|
},
|
|
|
|
clearLabel() {
|
|
|
|
return this.$primevue.config.locale.clear;
|
|
|
|
},
|
|
|
|
weekHeaderLabel() {
|
|
|
|
return this.$primevue.config.locale.weekHeader;
|
|
|
|
},
|
|
|
|
monthNames() {
|
|
|
|
return this.$primevue.config.locale.monthNames;
|
|
|
|
},
|
|
|
|
attributeSelector() {
|
|
|
|
return UniqueComponentId();
|
|
|
|
},
|
|
|
|
switchViewButtonDisabled() {
|
|
|
|
return this.numberOfMonths > 1 || this.disabled;
|
|
|
|
},
|
|
|
|
panelId() {
|
2024-02-02 15:46:27 +00:00
|
|
|
return this.d_id + '_panel';
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2024-03-19 14:14:13 +00:00
|
|
|
InputText,
|
2024-04-09 06:05:44 +00:00
|
|
|
Button,
|
2024-03-19 14:14:13 +00:00
|
|
|
Portal,
|
|
|
|
CalendarIcon,
|
|
|
|
ChevronLeftIcon,
|
|
|
|
ChevronRightIcon,
|
|
|
|
ChevronUpIcon,
|
|
|
|
ChevronDownIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|