Mail templates for monitoring mails

This commit is contained in:
baldo 2016-06-11 15:13:06 +02:00
parent 71690b7d5c
commit eb3e0d96be
14 changed files with 250 additions and 100 deletions
server/services

View file

@ -8,9 +8,64 @@ angular.module('ffffng')
async,
deepExtend,
fs,
moment,
Logger
) {
var templateBasePath = __dirname + '/../mailTemplates';
var snippetsBasePath = templateBasePath + '/snippets';
var templateFunctions = {};
function renderSnippet(name, data) {
var snippetFile = snippetsBasePath + '/' + name + '.html';
return _.template(fs.readFileSync(snippetFile).toString())(deepExtend(
{},
this, // parent data
data,
templateFunctions
));
}
function snippet(name) {
return function (data) {
return renderSnippet.bind(this)(name, data);
}
}
function renderLink(href, text) {
return _.template(
'<a href="<%- href %>" style="color: #E5287A;"><%- text %></a>'
)({
href: href,
text: text || href
});
}
function renderHR() {
return '<hr style="border-top: 1px solid #333333; border-left: 0; border-right: 0; border-bottom: 0;" />';
}
function formatDateTime(unix) {
return moment.unix(unix).locale('de').local().format('DD.MM.YYYY HH:mm');
}
function formatFromNow(unix) {
return moment.unix(unix).locale('de').fromNow();
}
templateFunctions.header = snippet('header');
templateFunctions.footer = snippet('footer');
templateFunctions.monitoringFooter = snippet('monitoring-footer');
templateFunctions.snippet = renderSnippet;
templateFunctions.link = renderLink;
templateFunctions.hr = renderHR;
templateFunctions.formatDateTime = formatDateTime;
templateFunctions.formatFromNow = formatFromNow;
return {
configureTransporter: function (transporter) {
@ -38,7 +93,8 @@ angular.module('ffffng')
{
community: config.client.community,
editNodeUrl: UrlBuilder.editNodeUrl()
}
},
templateFunctions
);
function render(field) {