-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-6398: UDW as standalone as GH package #1010
Changes from all commits
9679015
e7e6628
2852d10
244d9aa
605cf29
ba1b1b8
6853333
c7621ff
a7daee5
960ce41
be0d6b4
5d88471
8a996f9
de1b307
810a364
9fc2db6
af9dd96
15361d5
6c6b840
6b995af
3039dcf
87dcd58
c6ed09e
aced7a8
6dba3df
81d8680
fc4dca9
afdd7ed
d46625f
72a74ad
a86da4b
1b7a7c9
0a70372
e4aba74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,124 @@ | ||
(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 DateTimePicker { | ||
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.actionsWrapper = this.fieldWrapper.querySelector('.ibexa-input-text-wrapper__actions'); | ||
this.calendarBtn = this.actionsWrapper.querySelector('.ibexa-input-text-wrapper__action-btn--calendar'); | ||
this.clearBtn = this.fieldWrapper.querySelector('.ibexa-input-text-wrapper__action-btn--clear'); | ||
this.customOnChange = config.onChange; | ||
|
||
this.init = this.init.bind(this); | ||
this.onChange = this.onChange.bind(this); | ||
this.onInput = this.onInput.bind(this); | ||
this.clear = this.clear.bind(this); | ||
|
||
this.flatpickrConfig = { | ||
...DEFAULT_CONFIG, | ||
inline: this.fieldWrapper.classList.contains('ibexa-date-time-picker--inline-datetime-popup'), | ||
onChange: this.onChange, | ||
ignoredFocusElements: [this.actionsWrapper], | ||
...(config.flatpickrConfig ?? {}), | ||
}; | ||
|
||
ibexa.helpers.objectInstances.setInstance(this.container, this); | ||
} | ||
import { getAdminUiConfig, getFlatpickr } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper'; | ||
import { convertDateToTimezone, formatShortDateTime } from '../helpers/timezone.helper'; | ||
import { setInstance } from '../helpers/object.instances'; | ||
|
||
const { ibexa } = window; | ||
|
||
const DEFAULT_CONFIG = { | ||
enableTime: true, | ||
time_24hr: true, | ||
formatDate: (date) => formatShortDateTime(date, null), | ||
}; | ||
|
||
class DateTimePicker { | ||
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.actionsWrapper = this.fieldWrapper.querySelector('.ibexa-input-text-wrapper__actions'); | ||
this.calendarBtn = this.actionsWrapper.querySelector('.ibexa-input-text-wrapper__action-btn--calendar'); | ||
this.clearBtn = this.fieldWrapper.querySelector('.ibexa-input-text-wrapper__action-btn--clear'); | ||
this.customOnChange = config.onChange; | ||
|
||
this.init = this.init.bind(this); | ||
this.onChange = this.onChange.bind(this); | ||
this.onInput = this.onInput.bind(this); | ||
this.clear = this.clear.bind(this); | ||
|
||
this.flatpickrConfig = { | ||
...DEFAULT_CONFIG, | ||
inline: this.fieldWrapper.classList.contains('ibexa-date-time-picker--inline-datetime-popup'), | ||
onChange: this.onChange, | ||
ignoredFocusElements: [this.actionsWrapper], | ||
...(config.flatpickrConfig ?? {}), | ||
}; | ||
|
||
setInstance(this.container, this); | ||
} | ||
|
||
clear() { | ||
this.flatpickrInstance.clear(); | ||
} | ||
clear() { | ||
this.flatpickrInstance.clear(); | ||
} | ||
|
||
onChange(dates) { | ||
const isDateSelected = !!dates[0]; | ||
const otherArguments = { inputField: this.inputField, dates }; | ||
onChange(dates) { | ||
const isDateSelected = !!dates[0]; | ||
const otherArguments = { inputField: this.inputField, dates }; | ||
|
||
if (!isDateSelected) { | ||
this.inputField.dataset.timestamp = ''; | ||
if (!isDateSelected) { | ||
this.inputField.dataset.timestamp = ''; | ||
|
||
this.customOnChange([''], otherArguments); | ||
this.customOnChange([''], otherArguments); | ||
|
||
return; | ||
} | ||
return; | ||
} | ||
|
||
const timestamps = dates.map((date) => { | ||
const selectedDateWithUserTimezone = convertDateToTimezone(date, userTimezone, true); | ||
const timestamp = Math.floor(selectedDateWithUserTimezone.valueOf() / 1000); | ||
const timestamps = dates.map((date) => { | ||
const { timezone } = getAdminUiConfig(); | ||
const selectedDateWithUserTimezone = convertDateToTimezone(date, timezone, true); | ||
const timestamp = Math.floor(selectedDateWithUserTimezone.valueOf() / 1000); | ||
|
||
return timestamp; | ||
}); | ||
return timestamp; | ||
}); | ||
|
||
[this.inputField.dataset.timestamp] = timestamps; | ||
[this.inputField.dataset.timestamp] = timestamps; | ||
|
||
this.customOnChange(timestamps, otherArguments); | ||
} | ||
this.customOnChange(timestamps, otherArguments); | ||
} | ||
|
||
onInput(event) { | ||
event.preventDefault(); | ||
onInput(event) { | ||
event.preventDefault(); | ||
|
||
if (event.target.value === '' && this.inputField.dataset.timestamp !== '') { | ||
this.clear(); | ||
} | ||
if (event.target.value === '' && this.inputField.dataset.timestamp !== '') { | ||
this.clear(); | ||
} | ||
} | ||
|
||
onKeyUp(isMinute, event) { | ||
const inputValue = event.target.value; | ||
|
||
if (inputValue.length === 0) { | ||
return; | ||
} | ||
onKeyUp(isMinute, event) { | ||
const inputValue = event.target.value; | ||
|
||
const value = parseInt(inputValue, 10); | ||
if (inputValue.length === 0) { | ||
return; | ||
} | ||
|
||
if (typeof value === 'number' && value >= 0) { | ||
const flatpickrDate = this.flatpickrInstance.selectedDates[0]; | ||
const value = parseInt(inputValue, 10); | ||
|
||
if (isMinute) { | ||
flatpickrDate.setMinutes(value); | ||
} else { | ||
flatpickrDate.setHours(value); | ||
} | ||
if (typeof value === 'number' && value >= 0) { | ||
const flatpickrDate = this.flatpickrInstance.selectedDates[0]; | ||
|
||
if (this.flatpickrConfig.minDate.getTime() > flatpickrDate.getTime()) { | ||
return; | ||
} | ||
if (isMinute) { | ||
flatpickrDate.setMinutes(value); | ||
} else { | ||
flatpickrDate.setHours(value); | ||
} | ||
|
||
this.flatpickrInstance.setDate(flatpickrDate, true); | ||
if (this.flatpickrConfig.minDate.getTime() > flatpickrDate.getTime()) { | ||
return; | ||
} | ||
|
||
this.flatpickrInstance.setDate(flatpickrDate, true); | ||
} | ||
} | ||
|
||
init() { | ||
this.flatpickrInstance = flatpickr(this.inputField, this.flatpickrConfig); | ||
|
||
this.inputField.addEventListener('input', this.onInput, false); | ||
this.calendarBtn.addEventListener( | ||
'click', | ||
() => { | ||
this.flatpickrInstance.open(); | ||
}, | ||
false, | ||
); | ||
|
||
if (this.flatpickrInstance.config.enableTime) { | ||
this.flatpickrInstance.minuteElement.addEventListener('keyup', this.onKeyUp.bind(this, true), false); | ||
this.flatpickrInstance.hourElement.addEventListener('keyup', this.onKeyUp.bind(this, false), false); | ||
} | ||
init() { | ||
const flatpickr = getFlatpickr(); | ||
this.flatpickrInstance = flatpickr(this.inputField, this.flatpickrConfig); | ||
|
||
this.inputField.addEventListener('input', this.onInput, false); | ||
this.calendarBtn.addEventListener( | ||
'click', | ||
() => { | ||
this.flatpickrInstance.open(); | ||
}, | ||
false, | ||
); | ||
|
||
if (this.flatpickrInstance.config.enableTime) { | ||
this.flatpickrInstance.minuteElement.addEventListener('keyup', this.onKeyUp.bind(this, true), false); | ||
this.flatpickrInstance.hourElement.addEventListener('keyup', this.onKeyUp.bind(this, false), false); | ||
} | ||
} | ||
} | ||
|
||
ibexa?.addConfig('core.DateTimePicker', DateTimePicker); | ||
|
||
ibexa.addConfig('core.DateTimePicker', DateTimePicker); | ||
})(window, window.document, window.ibexa, window.flatpickr); | ||
export { DateTimePicker }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as contentType from './content.type.helper'; | ||
import * as cookies from './cookies.helper'; | ||
import * as formError from './form.error.helper'; | ||
import * as formValidation from './form.validation.helper'; | ||
import * as highlight from './highlight.helper'; | ||
import * as icon from './icon.helper'; | ||
import * as location from './location.helper'; | ||
import * as middleEllipsis from './middle.ellipsis'; | ||
import * as notification from './notification.helper'; | ||
import * as objectInstances from './object.instances'; | ||
import * as pagination from './pagination.helper'; | ||
import * as request from './request.helper'; | ||
import * as system from './system.helper'; | ||
import * as table from './table.helper'; | ||
import * as tagViewSelect from './tag.view.select.helper'; | ||
import * as text from './text.helper'; | ||
import * as timezone from './timezone.helper'; | ||
import * as tooltips from './tooltips.helper'; | ||
import * as user from './user.helper'; | ||
|
||
(function (ibexa) { | ||
ibexa.addConfig('helpers.contentType', contentType); | ||
ibexa.addConfig('helpers.cookies', cookies); | ||
ibexa.addConfig('helpers.formError', formError); | ||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand, why we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I create |
||
ibexa.addConfig('helpers.formValidation', formValidation); | ||
ibexa.addConfig('helpers.highlight', highlight); | ||
ibexa.addConfig('helpers.icon', icon); | ||
ibexa.addConfig('helpers.location', location); | ||
ibexa.addConfig('helpers.ellipsis.middle', middleEllipsis); | ||
ibexa.addConfig('helpers.notification', notification); | ||
ibexa.addConfig('helpers.objectInstances', objectInstances); | ||
ibexa.addConfig('helpers.pagination', pagination); | ||
ibexa.addConfig('helpers.request', request); | ||
ibexa.addConfig('helpers.system', system); | ||
ibexa.addConfig('helpers.table', table); | ||
ibexa.addConfig('helpers.tagViewSelect', tagViewSelect); | ||
ibexa.addConfig('helpers.text', text); | ||
ibexa.addConfig('helpers.timezone', timezone); | ||
ibexa.addConfig('helpers.tooltips', tooltips); | ||
ibexa.addConfig('helpers.user', user); | ||
})(window.ibexa); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need IIFE? I think given we have modules this is not needed.