primo commit
This commit is contained in:
21
media/com_mails/joomla.asset.json
Normal file
21
media/com_mails/joomla.asset.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
|
||||
"name": "com_mails",
|
||||
"version": "4.0.0",
|
||||
"description": "Joomla CMS",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"assets": [
|
||||
{
|
||||
"name": "com_mails.admin-email-template-edit",
|
||||
"type": "script",
|
||||
"uri": "com_mails/admin-email-template-edit.min.js",
|
||||
"dependencies": [
|
||||
"core"
|
||||
],
|
||||
"attributes": {
|
||||
"type": "module"
|
||||
},
|
||||
"version": "0aa579"
|
||||
}
|
||||
]
|
||||
}
|
||||
90
media/com_mails/js/admin-email-template-edit.js
Normal file
90
media/com_mails/js/admin-email-template-edit.js
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
((document, Joomla) => {
|
||||
|
||||
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 (Joomla.editors.instances[this.inputBody.id]) {
|
||||
Joomla.editors.instances[this.inputBody.id].setValue(value);
|
||||
} else {
|
||||
this.inputBody.value = value;
|
||||
}
|
||||
}
|
||||
setHtmlBodyValue(value) {
|
||||
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 (Joomla.editors.instances[input.id]) {
|
||||
Joomla.editors.instances[input.id].replaceSelection(tag);
|
||||
} else {
|
||||
input.value += ` ${tag}`;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bindListeners() {
|
||||
document.querySelector('#btnResetSubject').addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
this.inputSubject.value = this.templateData.subject ? this.templateData.subject : '';
|
||||
});
|
||||
const btnResetBody = document.querySelector('#btnResetBody');
|
||||
if (btnResetBody) {
|
||||
btnResetBody.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
this.setBodyValue(this.templateData.body ? this.templateData.body : '');
|
||||
});
|
||||
}
|
||||
const btnResetHtmlBody = document.querySelector('#btnResetHtmlBody');
|
||||
if (btnResetHtmlBody) {
|
||||
btnResetHtmlBody.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
this.setHtmlBodyValue(this.templateData.htmlbody ? this.templateData.htmlbody : '');
|
||||
});
|
||||
}
|
||||
|
||||
// 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);
|
||||
4
media/com_mails/js/admin-email-template-edit.min.js
vendored
Normal file
4
media/com_mails/js/admin-email-template-edit.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/((a,s)=>{class l{constructor(t,i){this.form=t,this.inputSubject=this.form.querySelector("#jform_subject"),this.inputBody=this.form.querySelector("#jform_body"),this.inputHtmlBody=this.form.querySelector("#jform_htmlbody"),this.templateData=i&&i.templateData?i.templateData:{},this.form.EmailTemplateEdit=this}setBodyValue(t){s.editors.instances[this.inputBody.id]?s.editors.instances[this.inputBody.id].setValue(t):this.inputBody.value=t}setHtmlBodyValue(t){s.editors.instances[this.inputHtmlBody.id]?s.editors.instances[this.inputHtmlBody.id].setValue(t):this.inputHtmlBody.value=t}insertTag(t,i){if(!t)return!1;let e;switch(i){case"body":e=this.inputBody;break;case"htmlbody":e=this.inputHtmlBody;break;default:return!1}return s.editors.instances[e.id]?s.editors.instances[e.id].replaceSelection(t):e.value+=` ${t}`,!0}bindListeners(){a.querySelector("#btnResetSubject").addEventListener("click",e=>{e.preventDefault(),this.inputSubject.value=this.templateData.subject?this.templateData.subject:""});const t=a.querySelector("#btnResetBody");t&&t.addEventListener("click",e=>{e.preventDefault(),this.setBodyValue(this.templateData.body?this.templateData.body:"")});const i=a.querySelector("#btnResetHtmlBody");i&&i.addEventListener("click",e=>{e.preventDefault(),this.setHtmlBodyValue(this.templateData.htmlbody?this.templateData.htmlbody:"")}),this.form.querySelectorAll(".edit-action-add-tag").forEach(e=>{e.addEventListener("click",d=>{d.preventDefault();const r=d.target;this.insertTag(r.dataset.tag,r.dataset.target)})})}}a.addEventListener("DOMContentLoaded",()=>{new l(a.getElementById("item-form"),s.getOptions("com_mails")).bindListeners()})})(document,Joomla);
|
||||
BIN
media/com_mails/js/admin-email-template-edit.min.js.gz
Normal file
BIN
media/com_mails/js/admin-email-template-edit.min.js.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user