ability to edit and save custom email templates
parent
46d6be57a8
commit
109fe895b3
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
/* global define, socket, app, ajaxify, ace */
|
||||
|
||||
define('admin/settings/email', ['admin/settings'], function(settings) {
|
||||
var module = {},
|
||||
emailEditor;
|
||||
|
||||
module.init = function() {
|
||||
configureEmailTester();
|
||||
configureEmailEditor();
|
||||
};
|
||||
|
||||
function configureEmailTester() {
|
||||
$('button[data-action="email.test"]').off('click').on('click', function() {
|
||||
socket.emit('admin.email.test', {template: $('#test-email').val()}, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
app.alertSuccess('Test Email Sent');
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function configureEmailEditor() {
|
||||
$('#email-editor-selector').on('change', updateEmailEditor);
|
||||
|
||||
emailEditor = ace.edit("email-editor");
|
||||
emailEditor.setTheme("ace/theme/twilight");
|
||||
emailEditor.getSession().setMode("ace/mode/html");
|
||||
|
||||
emailEditor.on('change', function(e) {
|
||||
$('#email-editor-holder').val(emailEditor.getValue());
|
||||
});
|
||||
|
||||
updateEmailEditor();
|
||||
}
|
||||
|
||||
function updateEmailEditor() {
|
||||
ajaxify.data.emails.forEach(function(email) {
|
||||
if (email.path === $('#email-editor-selector').val()) {
|
||||
emailEditor.getSession().setValue(email.text);
|
||||
$('#email-editor-holder')
|
||||
.val(email.text)
|
||||
.attr('data-field', 'email:custom:' + email.path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return module;
|
||||
});
|
Loading…
Reference in New Issue