class FrontPage { /** * @param {boolean} callbackActive */ constructor(callbackActive = false) { this.callbackActive = callbackActive; this.initialize(); } initialize() { document.addEventListener("DOMContentLoaded", () => { if (!this.callbackActive) { document.querySelector('.callback-div').classList.add('d-none') } this.callbackTextfield = document.getElementById('callback-tf'); this.callbackMessage = document.getElementById('callback-tfHelp'); this.callbackEnabled = document.getElementById('callback-en'); this.disclaimerOK = false; this.callbackEnabled.checked = false; this.callbackEnabled.addEventListener('change', this.onCallbackEnabled.bind(this)) this.callbackTextfield.readonly = false; this.callbackTextfield.setAttribute('placeholder', ''); this.callbackMessage.style.display = 'none'; document.addEventListener('click', this.onClick.bind(this)); }); } /** * @param {MouseEvent} event */ onClick(event) { let target = event.target; let form = target.closest('form'); if (target.closest('#submit-form')) { if (this.callbackEnabled.checked) { PageNotifier.confirmDangerousAction( __message('data-message-disclaimer'), __message('data-message-disclaimer-notice'), __message('data-message-i-understand'), __('buttons.action.cancel') ).then(result => { if (result) { form.submit(); } }); } else { form.submit(); } } } /** * @param {Event} event */ onCallbackEnabled(event) { if (this.callbackEnabled.checked) { this.callbackTextfield.readonly = false; this.callbackTextfield.setAttribute('placeholder', __message('data-message-input-phone')); this.callbackMessage.style.display = 'block'; } else { this.callbackTextfield.readonly = false; this.callbackTextfield.setAttribute('placeholder', ''); this.callbackMessage.style.display = 'none'; } } }