2015-09-17 16:25:15 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-10-31 13:52:26 +03:00
|
|
|
var async = require('async');
|
2017-01-14 22:36:10 -07:00
|
|
|
var nconf = require('nconf');
|
2017-08-30 14:26:41 -06:00
|
|
|
var fs = require('fs');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
|
2016-10-31 13:52:26 +03:00
|
|
|
var meta = require('../../meta');
|
2017-08-30 14:26:41 -06:00
|
|
|
var file = require('../../file');
|
|
|
|
|
var emailer = require('../../emailer');
|
2016-10-31 13:52:26 +03:00
|
|
|
|
|
|
|
|
var settingsController = module.exports;
|
2015-09-17 16:25:15 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
settingsController.get = function (req, res, next) {
|
2015-09-17 16:25:15 -04:00
|
|
|
var term = req.params.term ? req.params.term : 'general';
|
|
|
|
|
|
2015-09-21 17:17:23 -04:00
|
|
|
switch (req.params.term) {
|
2017-02-18 02:38:03 -07:00
|
|
|
case 'email':
|
|
|
|
|
renderEmail(req, res, next);
|
|
|
|
|
break;
|
2015-09-21 17:17:23 -04:00
|
|
|
|
2017-02-18 02:38:03 -07:00
|
|
|
default:
|
|
|
|
|
res.render('admin/settings/' + term);
|
2015-09-21 17:17:23 -04:00
|
|
|
}
|
2015-09-17 16:25:15 -04:00
|
|
|
};
|
|
|
|
|
|
2015-09-21 17:17:23 -04:00
|
|
|
|
|
|
|
|
function renderEmail(req, res, next) {
|
2017-01-14 22:36:10 -07:00
|
|
|
var emailsPath = path.join(nconf.get('views_dir'), 'emails');
|
2016-08-16 19:46:59 +02:00
|
|
|
|
2017-08-30 14:26:41 -06:00
|
|
|
async.parallel({
|
|
|
|
|
emails: function (cb) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
file.walk(emailsPath, next);
|
|
|
|
|
},
|
|
|
|
|
function (emails, next) {
|
2017-09-23 12:51:20 -06:00
|
|
|
// exclude .js files
|
2017-08-30 14:26:41 -06:00
|
|
|
emails = emails.filter(function (email) {
|
2017-09-23 12:51:20 -06:00
|
|
|
return !email.endsWith('.js');
|
2017-08-30 14:26:41 -06:00
|
|
|
});
|
2015-09-21 17:44:06 -04:00
|
|
|
|
2017-08-30 14:26:41 -06:00
|
|
|
async.map(emails, function (email, next) {
|
|
|
|
|
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
|
2016-08-16 19:46:59 +02:00
|
|
|
|
2017-08-30 14:26:41 -06:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
2017-11-16 15:43:52 -07:00
|
|
|
fs.readFile(email, 'utf8', next);
|
2017-08-30 14:26:41 -06:00
|
|
|
},
|
|
|
|
|
function (original, next) {
|
2017-11-16 15:43:52 -07:00
|
|
|
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original;
|
2017-08-30 14:26:41 -06:00
|
|
|
|
|
|
|
|
next(null, {
|
|
|
|
|
path: path,
|
|
|
|
|
fullpath: email,
|
|
|
|
|
text: text,
|
2017-11-16 15:43:52 -07:00
|
|
|
original: original,
|
2017-08-30 14:26:41 -06:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
], cb);
|
2017-06-22 19:03:49 -04:00
|
|
|
},
|
2017-08-30 14:26:41 -06:00
|
|
|
services: emailer.listServices,
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.render('admin/settings/email', {
|
|
|
|
|
emails: results.emails,
|
|
|
|
|
sendable: results.emails.filter(function (email) {
|
|
|
|
|
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
|
|
|
|
|
}),
|
|
|
|
|
services: results.services,
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-09-21 17:17:23 -04:00
|
|
|
}
|