- md5
- 33841009e1c80b8e937f409fef8e4dfc
- sha1
- c06dc6cb1454572c77caeb0e1214c1ce304d7942
- sha256
- 55626acd7e8e8ea3d047606a5014e84eb2b5c8122c86347de617d2c6c34a9b76
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
(function (document, Joomla) {
'use strict';
var EmailTemplateEdit = /*#__PURE__*/function () {
function EmailTemplateEdit(form, options) {
_classCallCheck(this, EmailTemplateEdit);
// 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;
}
_createClass(EmailTemplateEdit, [{
key: "setBodyValue",
value: function 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;
}
}
}, {
key: "setHtmlBodyValue",
value: function 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;
}
}
}, {
key: "insertTag",
value: function insertTag(tag, targetField) {
if (!tag) return false;
var 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;
}
}, {
key: "bindListeners",
value: function bindListeners() {
var _this = this;
// To enable editing of specific input
var subjectSwitcher = document.querySelectorAll('input[type=radio][name="jform[subject_switcher]"]');
var bodySwitcher = document.querySelectorAll('input[type=radio][name="jform[body_switcher]"]');
var htmlBodySwitcher = document.querySelectorAll('input[type=radio][name="jform[htmlbody_switcher]"]');
var subjectSwitcherChangeHandler = function subjectSwitcherChangeHandler(_ref) {
var target = _ref.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, function (radio) {
radio.addEventListener('change', subjectSwitcherChangeHandler);
});
var bodySwitcherChangeHandler = function bodySwitcherChangeHandler(_ref2) {
var target = _ref2.target;
var 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, function (radio) {
radio.addEventListener('change', bodySwitcherChangeHandler);
});
var htmlBodySwitcherChangeHandler = function htmlBodySwitcherChangeHandler(_ref3) {
var target = _ref3.target;
var 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, function (radio) {
radio.addEventListener('change', htmlBodySwitcherChangeHandler);
}); // Buttons for inserting a tag
this.form.querySelectorAll('.edit-action-add-tag').forEach(function (button) {
button.addEventListener('click', function (event) {
event.preventDefault();
var el = event.target;
_this.insertTag(el.dataset.tag, el.dataset.target);
});
});
}
}]);
return EmailTemplateEdit;
}();
document.addEventListener('DOMContentLoaded', function () {
var editor = new EmailTemplateEdit(document.getElementById('item-form'), Joomla.getOptions('com_mails'));
editor.bindListeners();
});
})(document, Joomla);
The same content is in 2 releases, Joomla 4.0.0-beta6 to 4.0.0-beta7. See them all, or every version of this file.