[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/com_mails/js/ -> admin-email-template-edit.js (source)

   1  /**
   2   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   3   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   4   */
   5  ((document, Joomla) => {
   6  
   7    class EmailTemplateEdit {
   8      constructor(form, options) {
   9        // Set elements
  10        this.form = form;
  11        this.inputSubject = this.form.querySelector('#jform_subject');
  12        this.inputBody = this.form.querySelector('#jform_body');
  13        this.inputHtmlBody = this.form.querySelector('#jform_htmlbody'); // Set options
  14  
  15        this.templateData = options && options.templateData ? options.templateData : {}; // Add back reference
  16  
  17        this.form.EmailTemplateEdit = this;
  18      }
  19  
  20      setBodyValue(value) {
  21        if (Joomla.editors.instances[this.inputBody.id]) {
  22          Joomla.editors.instances[this.inputBody.id].setValue(value);
  23        } else {
  24          this.inputBody.value = value;
  25        }
  26      }
  27  
  28      setHtmlBodyValue(value) {
  29        if (Joomla.editors.instances[this.inputHtmlBody.id]) {
  30          Joomla.editors.instances[this.inputHtmlBody.id].setValue(value);
  31        } else {
  32          this.inputHtmlBody.value = value;
  33        }
  34      }
  35  
  36      insertTag(tag, targetField) {
  37        if (!tag) return false;
  38        let input;
  39  
  40        switch (targetField) {
  41          case 'body':
  42            input = this.inputBody;
  43            break;
  44  
  45          case 'htmlbody':
  46            input = this.inputHtmlBody;
  47            break;
  48  
  49          default:
  50            return false;
  51        }
  52  
  53        if (Joomla.editors.instances[input.id]) {
  54          Joomla.editors.instances[input.id].replaceSelection(tag);
  55        } else {
  56          input.value += ` $tag}`;
  57        }
  58  
  59        return true;
  60      }
  61  
  62      bindListeners() {
  63        document.querySelector('#btnResetSubject').addEventListener('click', event => {
  64          event.preventDefault();
  65          this.inputSubject.value = this.templateData.subject ? this.templateData.subject : '';
  66        });
  67        const btnResetBody = document.querySelector('#btnResetBody');
  68  
  69        if (btnResetBody) {
  70          btnResetBody.addEventListener('click', event => {
  71            event.preventDefault();
  72            this.setBodyValue(this.templateData.body ? this.templateData.body : '');
  73          });
  74        }
  75  
  76        const btnResetHtmlBody = document.querySelector('#btnResetHtmlBody');
  77  
  78        if (btnResetHtmlBody) {
  79          btnResetHtmlBody.addEventListener('click', event => {
  80            event.preventDefault();
  81            this.setHtmlBodyValue(this.templateData.htmlbody ? this.templateData.htmlbody : '');
  82          });
  83        } // Buttons for inserting a tag
  84  
  85  
  86        this.form.querySelectorAll('.edit-action-add-tag').forEach(button => {
  87          button.addEventListener('click', event => {
  88            event.preventDefault();
  89            const el = event.target;
  90            this.insertTag(el.dataset.tag, el.dataset.target);
  91          });
  92        });
  93      }
  94  
  95    }
  96  
  97    document.addEventListener('DOMContentLoaded', () => {
  98      const editor = new EmailTemplateEdit(document.getElementById('item-form'), Joomla.getOptions('com_mails'));
  99      editor.bindListeners();
 100    });
 101  })(document, Joomla);


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer