CoreFiles by mySites.guru
joomla-field-send-test-mail.js65 lines, 1,935 bytes, from Joomla_4.0.0-alpha3-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha2
md5
b860691a5908afceac26add1e291d957
sha1
2e12b6ebbb50c47f87e4abe603359bcead4f8edc
sha256
380188b032ea543f3e6c54b15e376dd6749bfad6e47c995ce48b9efbe347e87c
;((customElements, Joomla) => {

	class JoomlaFieldSendTestMail extends HTMLElement {

	// attributeChangedCallback(attr, oldValue, newValue) {}
	constructor() {
		super();

		if (!Joomla) {
			throw new Error('Joomla API is not properly initiated');
		}

		if (!this.getAttribute('uri')) {
			throw new Error('No valid url for validation')
		}
	}

	connectedCallback() {
		const self = this;
		const button = document.getElementById('sendtestmail');

		if (button) {
			button.addEventListener('click', () => { self.sendTestMail(self); });
		}
	}

	sendTestMail() {
		const email_data = {
			smtpauth: this.querySelector('[name="jform[smtpauth]"]').value,
			smtpuser: this.querySelector('[name="jform[smtpuser]"]').value,
			smtppass: this.querySelector('[name="jform[smtppass]"]').value,
			smtphost: this.querySelector('[name="jform[smtphost]"]').value,
			smtpsecure: this.querySelector('[name="jform[smtpsecure]"]').value,
			smtpport: this.querySelector('[name="jform[smtpport]"]').value,
			mailfrom: this.querySelector('[name="jform[mailfrom]"]').value,
			fromname: this.querySelector('[name="jform[fromname]"]').value,
			mailer: this.querySelector('[name="jform[mailer]"]').value,
			mailonline: this.querySelector('[name="jform[mailonline]"]').value,
		};

		// Remove js messages, if they exist.
		Joomla.removeMessages();

		Joomla.request({
			url: this.getAttribute('uri'),
			method: 'POST',
			data: JSON.stringify(email_data),
			perform: true,
			headers: { 'Content-Type': 'application/json' },
			onSuccess: (response, xhr) => {
				response = JSON.parse(response);
				if (typeof response.messages === 'object' && response.messages !== null) {
					Joomla.renderMessages(response.messages);
				}
			},
			onError: (xhr) => {
				Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr));
			},
		});
	}
}

customElements.define('joomla-field-send-test-mail', JoomlaFieldSendTestMail);

})(customElements, Joomla);

The same content is in 2 releases, Joomla 4.0.0-alpha3 to 4.0.0-alpha5. See them all, or every version of this file.