- md5
- 5f8183974fd732b00d444fce07fa6104
- sha1
- 8e503533e945a19a72ca77b5113cb49e28169273
- sha256
- 9aa4211799fbb497dc6481b992ddf02745aa36634b627819fbda3cfc6c9e3a93
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/
/**
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
((document, Joomla) => {
'use strict';
class EmailTemplateEdit {
constructor(form, options) {
// Set elements
this.form = form;
this.inputSubject = this.form.querySelector('#jform_subject');
this.inputBody = this.form.querySelector('#jform_body');
this.inputHtmlBody = this.form.querySelector('#jform_htmlbody'); // Set options
this.templateData = options && options.templateData ? options.templateData : {}; // Add back reference
this.form.EmailTemplateEdit = this;
}
setBodyValue(value) {
if (this.inputBody.disabled) {
return;
}
if (Joomla.editors.instances[this.inputBody.id]) {
Joomla.editors.instances[this.inputBody.id].setValue(value);
} else {
this.inputBody.value = value;
}
}
setHtmlBodyValue(value) {
if (this.inputHtmlBody.disabled) {
return;
}
if (Joomla.editors.instances[this.inputHtmlBody.id]) {
Joomla.editors.instances[this.inputHtmlBody.id].setValue(value);
} else {
this.inputHtmlBody.value = value;
}
}
insertTag(tag, targetField) {
if (!tag) return false;
let input;
switch (targetField) {
case 'body':
input = this.inputBody;
break;
case 'htmlbody':
input = this.inputHtmlBody;
break;
default:
return false;
}
if (input.disabled) return false;
if (Joomla.editors.instances[input.id]) {
Joomla.editors.instances[input.id].replaceSelection(tag);
} else {
input.value += ` ${tag}`;
}
return true;
}
bindListeners() {
// To enable editing of specific input
const subjectSwitcher = document.querySelectorAll('input[type=radio][name="jform[subject_switcher]"]');
const bodySwitcher = document.querySelectorAll('input[type=radio][name="jform[body_switcher]"]');
const htmlBodySwitcher = document.querySelectorAll('input[type=radio][name="jform[htmlbody_switcher]"]');
const subjectSwitcherChangeHandler = ({
target
}) => {
if (target.value === '0') {
this.inputSubject.disabled = true;
this.inputSubject.value = this.templateData.subject ? this.templateData.subject.master : '';
} else if (target.value === '1') {
this.inputSubject.disabled = false;
this.inputSubject.value = this.templateData.subject ? this.templateData.subject.translated : '';
} else {
// eslint-disable-next-line no-console
console.error('unrecognised value');
}
};
Array.prototype.forEach.call(subjectSwitcher, radio => {
radio.addEventListener('change', subjectSwitcherChangeHandler);
});
const bodySwitcherChangeHandler = ({
target
}) => {
const tagsContainer = this.form.querySelector('.tags-container-body');
if (target.value === '0') {
this.setBodyValue(this.templateData.body ? this.templateData.body.master : '');
this.inputBody.disabled = true;
tagsContainer.classList.add('hidden');
} else if (target.value === '1') {
this.inputBody.disabled = false;
this.inputBody.readOnly = false;
this.setBodyValue(this.templateData.body ? this.templateData.body.translated : '');
tagsContainer.classList.remove('hidden');
} else {
// eslint-disable-next-line no-console
console.error('unrecognised value');
}
};
Array.prototype.forEach.call(bodySwitcher, radio => {
radio.addEventListener('change', bodySwitcherChangeHandler);
});
const htmlBodySwitcherChangeHandler = ({
target
}) => {
const tagsContainer = this.form.querySelector('.tags-container-htmlbody');
if (target.value === '0') {
this.setHtmlBodyValue(this.templateData.htmlbody ? this.templateData.htmlbody.master : '');
this.inputHtmlBody.disabled = true;
Joomla.editors.instances[this.inputHtmlBody.id].disable(true);
tagsContainer.classList.add('hidden');
} else if (target.value === '1') {
Joomla.editors.instances[this.inputHtmlBody.id].disable(false);
this.inputHtmlBody.disabled = false;
this.inputHtmlBody.readOnly = false;
this.setHtmlBodyValue(this.templateData.htmlbody ? this.templateData.htmlbody.translated : '');
tagsContainer.classList.remove('hidden');
} else {
// eslint-disable-next-line no-console
console.error('unrecognised value');
}
};
Array.prototype.forEach.call(htmlBodySwitcher, radio => {
radio.addEventListener('change', htmlBodySwitcherChangeHandler);
}); // Buttons for inserting a tag
this.form.querySelectorAll('.edit-action-add-tag').forEach(button => {
button.addEventListener('click', event => {
event.preventDefault();
const el = event.target;
this.insertTag(el.dataset.tag, el.dataset.target);
});
});
}
}
document.addEventListener('DOMContentLoaded', () => {
const editor = new EmailTemplateEdit(document.getElementById('item-form'), Joomla.getOptions('com_mails'));
editor.bindListeners();
});
})(document, Joomla);
The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.