From 55748ac3f54979b4e762d8c6cc3e57a5c994714c Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 21 Sep 2015 17:17:23 -0400 Subject: [PATCH] ability to select what kind of test email to send --- public/src/admin/settings.js | 2 +- src/controllers/admin/settings.js | 36 +++++++++++++++++++++++++++++- src/socket.io/admin.js | 2 +- src/views/admin/settings/email.tpl | 20 +++++++++++++---- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/public/src/admin/settings.js b/public/src/admin/settings.js index 9b04f29423..b7d96ea8e4 100644 --- a/public/src/admin/settings.js +++ b/public/src/admin/settings.js @@ -93,7 +93,7 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) { handleUploads(); $('button[data-action="email.test"]').off('click').on('click', function() { - socket.emit('admin.email.test', function(err) { + socket.emit('admin.email.test', {template: $('#test-email').val()}, function(err) { if (err) { return app.alertError(err.message); } diff --git a/src/controllers/admin/settings.js b/src/controllers/admin/settings.js index cf204a3d7c..d3a850ccbf 100644 --- a/src/controllers/admin/settings.js +++ b/src/controllers/admin/settings.js @@ -1,11 +1,45 @@ 'use strict'; var settingsController = {}; +var async = require('async'); settingsController.get = function(req, res, next) { var term = req.params.term ? req.params.term : 'general'; - res.render('admin/settings/' + term); + switch (req.params.term) { + case 'email': + renderEmail(req, res, next); + break; + + default: + res.render('admin/settings/' + term); + } }; + +function renderEmail(req, res, next) { + var fs = require('fs'), + path = require('path'), + utils = require('../../../public/src/utils'); + + var emailsPath = path.join(__dirname, '../../../public/templates/emails'); + utils.walk(emailsPath, function(err, emails) { + async.map(emails, function(email, next) { + fs.readFile(email, function(err, str) { + next(err, { + path: email.replace(emailsPath, '').substr(1).replace('.tpl', ''), + fullpath: email, + text: str.toString() + }); + }); + }, function(err, emails) { + res.render('admin/settings/email', { + emails: emails.filter(function(email) { + return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1 + }) + }); +; }); + }); +} + module.exports = settingsController; \ No newline at end of file diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 9f12596723..c7cd282697 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -203,7 +203,7 @@ SocketAdmin.settings.clearSitemapCache = function(socket, data, callback) { SocketAdmin.email.test = function(socket, data, callback) { if (plugins.hasListeners('action:email.send')) { - emailer.send('test', socket.uid, { + emailer.send(data.template, socket.uid, { subject: '[NodeBB] Test Email', site_title: meta.config.title || 'NodeBB' }); diff --git a/src/views/admin/settings/email.tpl b/src/views/admin/settings/email.tpl index f5ab913b2d..cb99d5450b 100644 --- a/src/views/admin/settings/email.tpl +++ b/src/views/admin/settings/email.tpl @@ -21,14 +21,26 @@


- -

- The test email will be sent to the currently logged in user's email address. -

+
+
Email Testing
+
+
+
+ +

+ The test email will be sent to the currently logged in user's email address. +

+
+
+
Email Subscriptions