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');
|
2016-10-31 13:52:26 +03:00
|
|
|
var meta = require('../../meta');
|
|
|
|
|
|
|
|
|
|
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) {
|
2016-09-01 15:32:47 +03:00
|
|
|
var fs = require('fs');
|
|
|
|
|
var path = require('path');
|
2017-04-08 20:22:21 -06:00
|
|
|
var file = require('../../file');
|
2015-09-21 17:17:23 -04:00
|
|
|
|
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
|
|
|
|
2016-10-31 13:52:26 +03:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
2017-04-08 20:22:21 -06:00
|
|
|
file.walk(emailsPath, next);
|
2016-10-31 13:52:26 +03:00
|
|
|
},
|
|
|
|
|
function (emails, next) {
|
|
|
|
|
async.map(emails, function (email, next) {
|
|
|
|
|
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
|
2015-09-21 17:44:06 -04:00
|
|
|
|
2017-06-22 19:03:49 -04:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
fs.readFile(email, next);
|
|
|
|
|
},
|
|
|
|
|
function (original, next) {
|
|
|
|
|
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
|
2016-08-16 19:46:59 +02:00
|
|
|
|
2017-06-22 19:03:49 -04:00
|
|
|
next(null, {
|
|
|
|
|
path: path,
|
|
|
|
|
fullpath: email,
|
|
|
|
|
text: text,
|
|
|
|
|
original: original.toString(),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
2016-10-31 13:52:26 +03:00
|
|
|
}, next);
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2017-06-22 19:03:49 -04:00
|
|
|
function (emails) {
|
|
|
|
|
res.render('admin/settings/email', {
|
|
|
|
|
emails: emails,
|
|
|
|
|
sendable: emails.filter(function (email) {
|
|
|
|
|
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
2015-09-21 17:17:23 -04:00
|
|
|
}
|