ability to select what kind of test email to send

v1.18.x
psychobunny 9 years ago
parent fa8a2c5c1b
commit 55748ac3f5

@ -93,7 +93,7 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) {
handleUploads(); handleUploads();
$('button[data-action="email.test"]').off('click').on('click', function() { $('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) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }

@ -1,11 +1,45 @@
'use strict'; 'use strict';
var settingsController = {}; var settingsController = {};
var async = require('async');
settingsController.get = function(req, res, next) { settingsController.get = function(req, res, next) {
var term = req.params.term ? req.params.term : 'general'; 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; module.exports = settingsController;

@ -203,7 +203,7 @@ SocketAdmin.settings.clearSitemapCache = function(socket, data, callback) {
SocketAdmin.email.test = function(socket, data, callback) { SocketAdmin.email.test = function(socket, data, callback) {
if (plugins.hasListeners('action:email.send')) { if (plugins.hasListeners('action:email.send')) {
emailer.send('test', socket.uid, { emailer.send(data.template, socket.uid, {
subject: '[NodeBB] Test Email', subject: '[NodeBB] Test Email',
site_title: meta.config.title || 'NodeBB' site_title: meta.config.title || 'NodeBB'
}); });

@ -21,14 +21,26 @@
</p> </p>
<input type="text" class="form-control input-lg" id="email:from_name" data-field="email:from_name" placeholder="NodeBB" /><br /> <input type="text" class="form-control input-lg" id="email:from_name" data-field="email:from_name" placeholder="NodeBB" /><br />
</div> </div>
<button class="btn btn-primary" type="button" data-action="email.test">Send Test Email</button>
<p class="help-block">
The test email will be sent to the currently logged in user's email address.
</p>
</form> </form>
</div> </div>
</div> </div>
<div class="row">
<div class="col-sm-2 col-xs-12 settings-header">Email Testing</div>
<div class="col-sm-10 col-xs-12">
<label>Select Email Template</label><br />
<select id="test-email" class="form-control">
<!-- BEGIN emails -->
<option value="{emails.path}">{emails.path}</option>
<!-- END emails -->
</select><br />
<button class="btn btn-primary" type="button" data-action="email.test">Send Test Email</button>
<p class="help-block">
The test email will be sent to the currently logged in user's email address.
</p>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-2 col-xs-12 settings-header">Email Subscriptions</div> <div class="col-sm-2 col-xs-12 settings-header">Email Subscriptions</div>
<div class="col-sm-10 col-xs-12"> <div class="col-sm-10 col-xs-12">

Loading…
Cancel
Save