-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
484c1f9
commit 2474f60
Showing
6 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/bundle/Resources/public/js/scripts/core/date.and.time.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
(function(global, doc, ibexa, flatpickr) { | ||
const { convertDateToTimezone, formatShortDateTime } = ibexa.helpers.timezone; | ||
const userTimezone = ibexa.adminUiConfig.timezone; | ||
|
||
const DEFAULT_CONFIG = { | ||
enableTime: true, | ||
time_24hr: true, | ||
formatDate: (date) => formatShortDateTime(date, null), | ||
|
||
} | ||
class DateAndTime { | ||
constructor(config) { | ||
this.container = config.container; | ||
this.fieldWrapper = this.container.querySelector('.ibexa-date-time-picker'); | ||
this.inputField = this.fieldWrapper.querySelector('.ibexa-date-time-picker__input'); | ||
this.customOnChange = config.onChange; | ||
console.log(this.fieldWrapper.classList); | ||
this.flatpickrConfig = { | ||
...DEFAULT_CONFIG, | ||
inline: this.fieldWrapper.classList.contains('ibexa-date-time-picker--inline-flatpickr'), | ||
onChange: this.onChange, | ||
...(config.flatpickrConfig ?? {}) | ||
} | ||
|
||
this.init = this.init.bind(this); | ||
this.onChange = this.onChange.bind(this); | ||
this.onInputBtn = this.onInputBtn.bind(this); | ||
} | ||
|
||
onChange = (dates) => { | ||
const isDateSelected = !!dates[0]; | ||
|
||
if (!isDateSelected) { | ||
this.inputField.dataset.timestamp = ''; | ||
|
||
this.customOnChange(this.inputField, ''); | ||
|
||
return; | ||
} | ||
|
||
const selectedDate = dates[0]; | ||
const selectedDateWithUserTimezone = convertDateToTimezone(selectedDate, userTimezone, true); | ||
const timestamp = Math.floor(selectedDateWithUserTimezone.valueOf() / 1000); | ||
|
||
this.inputField.dataset.timestamp = timestamp; | ||
|
||
this.customOnChange(this.inputField, timestamp); | ||
}; | ||
|
||
onInputBtn(event) { | ||
if (event.target.value === '' && this.inputField.dataset.timestamp !== '') { | ||
this.flatpickrInstance.setDate(null, true); | ||
} | ||
} | ||
|
||
init() { | ||
this.flatpickrInstance = flatpickr(this.inputField, this.flatpickrConfig); | ||
|
||
this.inputField.addEventListener('input', this.onInputBtn, false); | ||
} | ||
} | ||
|
||
ibexa.addConfig('core.DateAndTime', DateAndTime); | ||
})(window, window.document, window.ibexa, window.flatpickr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.ibexa-date-time-picker { | ||
max-width: 30ch; | ||
position: relative; | ||
|
||
&__input { | ||
&[readonly] { | ||
background-color: $ibexa-color-white; | ||
} | ||
} | ||
|
||
.ibexa-input-text-wrapper__actions { | ||
top: calculateRem(16px); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,4 @@ | |
@import 'location-swap-form'; | ||
@import 'selection-table'; | ||
@import 'assign'; | ||
@import 'date-and-time'; |
27 changes: 27 additions & 0 deletions
27
src/bundle/Resources/views/themes/admin/ui/component/input_date_and_time.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% set wrapper_attr = wrapper_attr|default({})|merge({ | ||
class: (wrapper_attr.class|default('') | ||
~ ' ibexa-date-time-picker' | ||
~ (inline_flatpickr ? ' ibexa-date-time-picker--inline-flatpickr') | ||
)|trim | ||
}) %} | ||
|
||
{% embed '@ibexadesign/ui/component/input_text.html.twig' with { has_search: false } %} | ||
{% block content %} | ||
<input | ||
class=" | ||
ibexa-input ibexa-input--text form-control ibexa-date-time-picker__input flatpickr flatpickr-date-input | ||
{{ is_small|default(false) ? 'ibexa-input--small' }} | ||
" | ||
readonly="readonly" | ||
type="text" | ||
/> | ||
{% endblock %} | ||
{% block actions %} | ||
{{ parent() }} | ||
<div class="ibexa-input-text-wrapper__action-btn"> | ||
<svg class="ibexa-icon ibexa-icon--small"> | ||
<use xlink:href="{{ ibexa_icon_path('date') }}"></use> | ||
</svg> | ||
</div> | ||
{% endblock %} | ||
{% endembed %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters