- md5
- 549a81b122b1ea8f2539055c15f0f139
- sha1
- 196884f19926bccfab3237748cf59701d7cb8138
- sha256
- 8c3ca596f139fa93d84814ecefb023cb44ac44aa01653a2bd854599844a6a817
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
/**
* 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 - 2019 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 += " ".concat(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 = event => {
if (event.target.value === '0') {
this.inputSubject.disabled = true;
this.inputSubject.value = this.templateData.subject ? this.templateData.subject.master : '';
} else if (event.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 = event => {
const tagsContainer = this.form.querySelector('.tags-container-body');
if (event.target.value === '0') {
this.setBodyValue(this.templateData.body ? this.templateData.body.master : '');
this.inputBody.disabled = true;
tagsContainer.classList.add('hidden');
} else if (event.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 = event => {
const tagsContainer = this.form.querySelector('.tags-container-htmlbody');
if (event.target.value === '0') {
this.setHtmlBodyValue(this.templateData.htmlbody ? this.templateData.htmlbody.master : '');
Joomla.editors.instances[this.inputHtmlBody.id].disable(true);
tagsContainer.classList.add('hidden');
} else if (event.target.value === '1') {
Joomla.editors.instances[this.inputHtmlBody.id].disable(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);
No other release has this exact content. See every version of this file.