[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 ((customElements, Joomla) => { 2 class JoomlaFieldSendTestMail extends HTMLElement { 3 // attributeChangedCallback(attr, oldValue, newValue) {} 4 constructor() { 5 super(); 6 7 if (!Joomla) { 8 throw new Error('Joomla API is not properly initiated'); 9 } 10 11 if (!this.getAttribute('uri')) { 12 throw new Error('No valid url for validation'); 13 } 14 } 15 16 connectedCallback() { 17 const self = this; 18 const button = document.getElementById('sendtestmail'); 19 20 if (button) { 21 button.addEventListener('click', () => { 22 self.sendTestMail(self); 23 }); 24 } 25 } 26 27 sendTestMail() { 28 const emailData = { 29 smtpauth: document.getElementById('jform_smtpauth1').checked ? 1 : 0, 30 smtpuser: this.querySelector('[name="jform[smtpuser]"]').value, 31 smtphost: this.querySelector('[name="jform[smtphost]"]').value, 32 smtpsecure: this.querySelector('[name="jform[smtpsecure]"]').value, 33 smtpport: this.querySelector('[name="jform[smtpport]"]').value, 34 mailfrom: this.querySelector('[name="jform[mailfrom]"]').value, 35 fromname: this.querySelector('[name="jform[fromname]"]').value, 36 mailer: this.querySelector('[name="jform[mailer]"]').value, 37 mailonline: document.getElementById('jform_mailonline1').checked ? 1 : 0 38 }; 39 const smtppass = this.querySelector('[name="jform[smtppass]"]'); 40 41 if (smtppass.disabled === false) { 42 emailData.smtppass = smtppass.value; 43 } // Remove js messages, if they exist. 44 45 46 Joomla.removeMessages(); 47 Joomla.request({ 48 url: this.getAttribute('uri'), 49 method: 'POST', 50 data: JSON.stringify(emailData), 51 perform: true, 52 headers: { 53 'Content-Type': 'application/json' 54 }, 55 onSuccess: resp => { 56 let response; 57 58 try { 59 response = JSON.parse(resp); 60 } catch (e) { 61 // eslint-disable-next-line no-console 62 console.error(e); 63 } 64 65 if (typeof response.messages === 'object' && response.messages !== null) { 66 Joomla.renderMessages(response.messages); 67 } 68 69 document.body.scrollIntoView({ 70 behavior: 'smooth' 71 }); 72 }, 73 onError: xhr => { 74 Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr)); 75 document.body.scrollIntoView({ 76 behavior: 'smooth' 77 }); 78 } 79 }); 80 } 81 82 } 83 84 customElements.define('joomla-field-send-test-mail', JoomlaFieldSendTestMail); 85 })(customElements, Joomla);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |