Added links to preview delivered messages

This commit is contained in:
Andris Reinman 2016-07-06 20:10:34 +03:00
parent cf0042c50a
commit b6555ffd04
3 changed files with 133 additions and 96 deletions

View file

@ -53,27 +53,7 @@ router.get('/:campaign/:list/:subscription', (req, res, next) => {
return next(err);
}
campaigns.getMail(campaign.id, list.id, subscription.id, (err, mail) => {
if (err) {
req.flash('danger', err.message || err);
return res.redirect('/');
}
/*
if (!mail && !req.user) {
err = new Error('Not Found');
err.status = 404;
return next(err);
}
*/
let renderAndShow = (html, renderTags) => {
// rewrite links to count clicks
links.updateLinks(campaign, list, subscription, serviceUrl, html, (err, html) => {
if (err) {
req.flash('danger', err.message || err);
return res.redirect('/');
}
let renderHtml = (html, renderTags) => {
res.render('archive/view', {
layout: 'archive/layout',
message: renderTags ? tools.formatMessage(serviceUrl, campaign, list, subscription, html) : html,
@ -81,6 +61,19 @@ router.get('/:campaign/:list/:subscription', (req, res, next) => {
list,
subscription
});
};
let renderAndShow = (html, renderTags) => {
if (req.query.track === 'no') {
return renderHtml(html, renderTags);
}
// rewrite links to count clicks
links.updateLinks(campaign, list, subscription, serviceUrl, html, (err, html) => {
if (err) {
req.flash('danger', err.message || err);
return res.redirect('/');
}
renderHtml(html, renderTags);
});
};
@ -109,6 +102,5 @@ router.get('/:campaign/:list/:subscription', (req, res, next) => {
});
});
});
});
module.exports = router;

View file

@ -407,7 +407,7 @@ router.post('/preview/:id', passport.parseForm, passport.csrfProtection, (req, r
return res.redirect('/lists/subscription/' + encodeURIComponent(listId) + '/add/?is-test=true');
}
res.redirect('/archive/' + encodeURIComponent(campaign) + '/' + encodeURIComponent(list) + '/' + encodeURIComponent(subscription));
res.redirect('/archive/' + encodeURIComponent(campaign) + '/' + encodeURIComponent(list) + '/' + encodeURIComponent(subscription) + '?track=no');
});
router.get('/opened/:id', passport.csrfProtection, (req, res) => {
@ -564,6 +564,16 @@ router.post('/clicked/ajax/:id/:linkId', (req, res) => {
data: []
});
}
lists.get(campaign.list, (err, list) => {
if (err) {
return res.json({
error: err && err.message || err,
data: []
});
}
let campaignCid = campaign.cid;
let listCid = list.cid;
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign_tracker__' + campaign.id + '`.`created', 'count'];
campaigns.filterClickedSubscribers(campaign, linkId, req.body, columns, (err, data, total, filteredTotal) => {
@ -579,7 +589,7 @@ router.post('/clicked/ajax/:id/:linkId', (req, res) => {
recordsTotal: total,
recordsFiltered: filteredTotal,
data: data.map((row, i) => [
(Number(req.body.start) || 0) + 1 + i,
'<a href="/archive/' + encodeURIComponent(campaignCid) + '/' + encodeURIComponent(listCid) + '/' + encodeURIComponent(row.cid) + '?track=no">' + ((Number(req.body.start) || 0) + 1 + i) + '</a>',
htmlescape(row.email || ''),
htmlescape(row.firstName || ''),
htmlescape(row.lastName || ''),
@ -591,6 +601,7 @@ router.post('/clicked/ajax/:id/:linkId', (req, res) => {
});
});
});
});
router.post('/status/ajax/:id/:status', (req, res) => {
let status = Number(req.params.status) || 0;
@ -603,6 +614,17 @@ router.post('/status/ajax/:id/:status', (req, res) => {
});
}
lists.get(campaign.list, (err, list) => {
if (err) {
return res.json({
error: err && err.message || err,
data: []
});
}
let campaignCid = campaign.cid;
let listCid = list.cid;
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign__' + campaign.id + '`.`updated'];
campaigns.filterStatusSubscribers(campaign, status, req.body, columns, (err, data, total, filteredTotal) => {
if (err) {
@ -617,7 +639,7 @@ router.post('/status/ajax/:id/:status', (req, res) => {
recordsTotal: total,
recordsFiltered: filteredTotal,
data: data.map((row, i) => [
(Number(req.body.start) || 0) + 1 + i,
'<a href="/archive/' + encodeURIComponent(campaignCid) + '/' + encodeURIComponent(listCid) + '/' + encodeURIComponent(row.cid) + '?track=no">' + ((Number(req.body.start) || 0) + 1 + i) + '</a>',
htmlescape(row.email || ''),
htmlescape(row.firstName || ''),
htmlescape(row.lastName || ''),
@ -629,6 +651,7 @@ router.post('/status/ajax/:id/:status', (req, res) => {
});
});
});
});
router.post('/delete', passport.parseForm, passport.csrfProtection, (req, res) => {
campaigns.delete(req.body.id, (err, deleted) => {

View file

@ -264,12 +264,30 @@ router.post('/status/ajax/:id', (req, res) => {
});
}
campaigns.get(trigger.destCampaign, false, (err, campaign) => {
if (err) {
return res.json({
error: err && err.message || err,
data: []
});
}
lists.get(trigger.list, (err, list) => {
if (err) {
return res.json({
error: err && err.message || err,
data: []
});
}
let campaignCid = campaign && campaign.cid;
let listCid = list && list.cid;
res.json({
draw: req.body.draw,
recordsTotal: total,
recordsFiltered: filteredTotal,
data: data.map((row, i) => [
(Number(req.body.start) || 0) + 1 + i,
'<a href="/archive/' + encodeURIComponent(campaignCid) + '/' + encodeURIComponent(listCid) + '/' + encodeURIComponent(row.cid) + '?track=no">' + ((Number(req.body.start) || 0) + 1 + i) + '</a>',
htmlescape(row.email || ''),
htmlescape(row.firstName || ''),
htmlescape(row.lastName || ''),
@ -279,6 +297,10 @@ router.post('/status/ajax/:id', (req, res) => {
});
});
});
});
});
});
module.exports = router;