CoreFiles by mySites.guru
joomla-field-send-test-mail.js68 lines, 2,205 bytes, from Joomla_4.0.0-beta4-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta3
md5
e6f02717ba779b47d674d639f9fdbb47
sha1
a99dd6d3aea668d9821315d1d0a315a26ad588e5
sha256
535a469b9334cedb47aed08ec891edb44b86580355668dc3a3d7ffcc0b6a5376
"use strict";

((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: document.getElementById('jform_smtpauth1').checked ? 1 : 0,
        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: document.getElementById('jform_mailonline1').checked ? 1 : 0
      }; // 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 => {
          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-beta3 to 4.0.0-beta4. See them all, or every version of this file.