Commit 29d689cb authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Anja Leichsenring
Browse files

[BUGFIX] Fix faulty check for undefined in DateTimePicker

Releases: master
Resolves: #93729
Change-Id: I9dea4a153138e29ae77c9f3e5ae5e202851a09ab
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68374


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: default avatarMartin Kutschker <mkutschker-typo3@yahoo.com>
Reviewed-by: Jonas Eberle's avatarJonas Eberle <flightvision@googlemail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent c104e567
......@@ -61,7 +61,7 @@ class DateTimePicker {
public initialize(element?: string | HTMLElement): void {
let dateTimePickers;
if (element instanceof HTMLElement) {
if (element.dataset.datepickerInitialized !== 'undefined') {
if (typeof element.dataset.datepickerInitialized !== 'undefined') {
return;
}
......
......@@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports","flatpickr/flatpickr.min","TYPO3/CMS/Core/DocumentService","moment","./Storage/Persistent","TYPO3/CMS/Core/Event/ThrottleEvent"],(function(e,t,a,i,n,r,o){"use strict";class l{constructor(e){var t;this.fieldSelector=".t3js-datetimepicker",this.format=(void 0!==(null===(t=null===opener||void 0===opener?void 0:opener.top)||void 0===t?void 0:t.TYPO3)?opener.top:top).TYPO3.settings.DateTimePicker.DateFormat,i.ready().then(()=>{this.initialize(e)})}static formatDateForHiddenField(e,t){return"time"!==t&&"timesec"!==t||e.year(1970).month(0).date(1),e.format()}initialize(t){let a;if(t instanceof HTMLElement){if("undefined"!==t.dataset.datepickerInitialized)return;a=[t]}else console.warn("Initializing all date pickers globally has been marked as deprecated. Please pass a specific element."),a=Array.from(document.querySelectorAll(t||this.fieldSelector)).filter(e=>void 0===e.dataset.datepickerInitialized);if(0===a.length)return;let i=r.get("lang");""===i?i="default":"ch"===i&&(i="zh"),a.forEach(t=>{t.dataset.datepickerInitialized="1",e(["flatpickr/locales"],()=>{this.initializeField(t,i)})})}initializeField(e,t){const i=this.getScrollEvent(),r=this.getDateOptions(e);r.locale=t,r.onOpen=[()=>{i.bindTo(document.querySelector(".t3js-module-body"))}],r.onClose=()=>{i.release()};const o=a(e,r);e.addEventListener("input",()=>{const e=o._input.value,t=o.parseDate(e);e===o.formatDate(t,o.config.dateFormat)&&o.setDate(e)}),e.addEventListener("change",t=>{t.stopImmediatePropagation();const a=t.target,i=e.parentElement.parentElement.querySelector('input[type="hidden"]');if(""!==a.value){const e=a.dataset.dateType,t=n.utc(a.value,a._flatpickr.config.dateFormat);t.isValid()?i.value=l.formatDateForHiddenField(t,e):a.value=l.formatDateForHiddenField(n.utc(i.value),e)}else i.value="";a.dispatchEvent(new Event("formengine.dp.change"))})}getScrollEvent(){return new o("scroll",()=>{const e=document.querySelector(".flatpickr-input.active");if(null===e)return;const t=e.getBoundingClientRect(),a=e._flatpickr.calendarContainer.offsetHeight;let i,n;window.innerHeight-t.bottom<a&&t.top>a?(i=t.y-a-2,n="arrowBottom"):(i=t.y+t.height+2,n="arrowTop"),e._flatpickr.calendarContainer.style.top=i+"px",e._flatpickr.calendarContainer.classList.remove("arrowBottom","arrowTop"),e._flatpickr.calendarContainer.classList.add(n)},15)}getDateOptions(e){const t=this.format,a=e.dataset.dateType,i={allowInput:!0,dateFormat:"",defaultDate:e.value,enableSeconds:!1,enableTime:!1,formatDate:(e,t)=>n(e).format(t),parseDate:(e,t)=>n(e,t,!0).toDate(),maxDate:"",minDate:"",minuteIncrement:1,noCalendar:!1,weekNumbers:!0};switch(a){case"datetime":i.dateFormat=t[1],i.enableTime=!0;break;case"date":i.dateFormat=t[0];break;case"time":i.dateFormat="HH:mm",i.enableTime=!0,i.noCalendar=!0;break;case"timesec":i.dateFormat="HH:mm:ss",i.enableSeconds=!0,i.enableTime=!0,i.noCalendar=!0;break;case"year":i.dateFormat="Y"}return"undefined"!==e.dataset.dateMindate&&(i.minDate=e.dataset.dateMindate),"undefined"!==e.dataset.dateMaxdate&&(i.maxDate=e.dataset.dateMaxdate),i}}return new l}));
\ No newline at end of file
define(["require","exports","flatpickr/flatpickr.min","TYPO3/CMS/Core/DocumentService","moment","./Storage/Persistent","TYPO3/CMS/Core/Event/ThrottleEvent"],(function(e,t,a,i,n,r,o){"use strict";class l{constructor(e){var t;this.fieldSelector=".t3js-datetimepicker",this.format=(void 0!==(null===(t=null===opener||void 0===opener?void 0:opener.top)||void 0===t?void 0:t.TYPO3)?opener.top:top).TYPO3.settings.DateTimePicker.DateFormat,i.ready().then(()=>{this.initialize(e)})}static formatDateForHiddenField(e,t){return"time"!==t&&"timesec"!==t||e.year(1970).month(0).date(1),e.format()}initialize(t){let a;if(t instanceof HTMLElement){if(void 0!==t.dataset.datepickerInitialized)return;a=[t]}else console.warn("Initializing all date pickers globally has been marked as deprecated. Please pass a specific element."),a=Array.from(document.querySelectorAll(t||this.fieldSelector)).filter(e=>void 0===e.dataset.datepickerInitialized);if(0===a.length)return;let i=r.get("lang");""===i?i="default":"ch"===i&&(i="zh"),a.forEach(t=>{t.dataset.datepickerInitialized="1",e(["flatpickr/locales"],()=>{this.initializeField(t,i)})})}initializeField(e,t){const i=this.getScrollEvent(),r=this.getDateOptions(e);r.locale=t,r.onOpen=[()=>{i.bindTo(document.querySelector(".t3js-module-body"))}],r.onClose=()=>{i.release()};const o=a(e,r);e.addEventListener("input",()=>{const e=o._input.value,t=o.parseDate(e);e===o.formatDate(t,o.config.dateFormat)&&o.setDate(e)}),e.addEventListener("change",t=>{t.stopImmediatePropagation();const a=t.target,i=e.parentElement.parentElement.querySelector('input[type="hidden"]');if(""!==a.value){const e=a.dataset.dateType,t=n.utc(a.value,a._flatpickr.config.dateFormat);t.isValid()?i.value=l.formatDateForHiddenField(t,e):a.value=l.formatDateForHiddenField(n.utc(i.value),e)}else i.value="";a.dispatchEvent(new Event("formengine.dp.change"))})}getScrollEvent(){return new o("scroll",()=>{const e=document.querySelector(".flatpickr-input.active");if(null===e)return;const t=e.getBoundingClientRect(),a=e._flatpickr.calendarContainer.offsetHeight;let i,n;window.innerHeight-t.bottom<a&&t.top>a?(i=t.y-a-2,n="arrowBottom"):(i=t.y+t.height+2,n="arrowTop"),e._flatpickr.calendarContainer.style.top=i+"px",e._flatpickr.calendarContainer.classList.remove("arrowBottom","arrowTop"),e._flatpickr.calendarContainer.classList.add(n)},15)}getDateOptions(e){const t=this.format,a=e.dataset.dateType,i={allowInput:!0,dateFormat:"",defaultDate:e.value,enableSeconds:!1,enableTime:!1,formatDate:(e,t)=>n(e).format(t),parseDate:(e,t)=>n(e,t,!0).toDate(),maxDate:"",minDate:"",minuteIncrement:1,noCalendar:!1,weekNumbers:!0};switch(a){case"datetime":i.dateFormat=t[1],i.enableTime=!0;break;case"date":i.dateFormat=t[0];break;case"time":i.dateFormat="HH:mm",i.enableTime=!0,i.noCalendar=!0;break;case"timesec":i.dateFormat="HH:mm:ss",i.enableSeconds=!0,i.enableTime=!0,i.noCalendar=!0;break;case"year":i.dateFormat="Y"}return"undefined"!==e.dataset.dateMindate&&(i.minDate=e.dataset.dateMindate),"undefined"!==e.dataset.dateMaxdate&&(i.maxDate=e.dataset.dateMaxdate),i}}return new l}));
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment