Added links to preview delivered messages
This commit is contained in:
parent
cf0042c50a
commit
b6555ffd04
3 changed files with 133 additions and 96 deletions
|
@ -53,58 +53,50 @@ router.get('/:campaign/:list/:subscription', (req, res, next) => {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
campaigns.getMail(campaign.id, list.id, subscription.id, (err, mail) => {
|
let renderHtml = (html, renderTags) => {
|
||||||
if (err) {
|
res.render('archive/view', {
|
||||||
req.flash('danger', err.message || err);
|
layout: 'archive/layout',
|
||||||
return res.redirect('/');
|
message: renderTags ? tools.formatMessage(serviceUrl, campaign, list, subscription, html) : html,
|
||||||
}
|
campaign,
|
||||||
/*
|
list,
|
||||||
if (!mail && !req.user) {
|
subscription
|
||||||
err = new Error('Not Found');
|
});
|
||||||
err.status = 404;
|
};
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
let renderAndShow = (html, renderTags) => {
|
|
||||||
|
|
||||||
// rewrite links to count clicks
|
let renderAndShow = (html, renderTags) => {
|
||||||
links.updateLinks(campaign, list, subscription, serviceUrl, html, (err, html) => {
|
if (req.query.track === 'no') {
|
||||||
if (err) {
|
return renderHtml(html, renderTags);
|
||||||
req.flash('danger', err.message || err);
|
|
||||||
return res.redirect('/');
|
|
||||||
}
|
|
||||||
|
|
||||||
res.render('archive/view', {
|
|
||||||
layout: 'archive/layout',
|
|
||||||
message: renderTags ? tools.formatMessage(serviceUrl, campaign, list, subscription, html) : html,
|
|
||||||
campaign,
|
|
||||||
list,
|
|
||||||
subscription
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (campaign.sourceUrl) {
|
|
||||||
let form = tools.getMessageLinks(serviceUrl, campaign, list, subscription);
|
|
||||||
Object.keys(subscription.mergeTags).forEach(key => {
|
|
||||||
form[key] = subscription.mergeTags[key];
|
|
||||||
});
|
|
||||||
request.post({
|
|
||||||
url: campaign.sourceUrl,
|
|
||||||
form
|
|
||||||
}, (err, httpResponse, body) => {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
if (httpResponse.statusCode !== 200) {
|
|
||||||
return next(new Error('Received status code ' + httpResponse.statusCode + ' from ' + campaign.sourceUrl));
|
|
||||||
}
|
|
||||||
renderAndShow(body && body.toString(), false);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
renderAndShow(campaign.html, true);
|
|
||||||
}
|
}
|
||||||
});
|
// 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);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (campaign.sourceUrl) {
|
||||||
|
let form = tools.getMessageLinks(serviceUrl, campaign, list, subscription);
|
||||||
|
Object.keys(subscription.mergeTags).forEach(key => {
|
||||||
|
form[key] = subscription.mergeTags[key];
|
||||||
|
});
|
||||||
|
request.post({
|
||||||
|
url: campaign.sourceUrl,
|
||||||
|
form
|
||||||
|
}, (err, httpResponse, body) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (httpResponse.statusCode !== 200) {
|
||||||
|
return next(new Error('Received status code ' + httpResponse.statusCode + ' from ' + campaign.sourceUrl));
|
||||||
|
}
|
||||||
|
renderAndShow(body && body.toString(), false);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
renderAndShow(campaign.html, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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');
|
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) => {
|
router.get('/opened/:id', passport.csrfProtection, (req, res) => {
|
||||||
|
@ -564,29 +564,40 @@ router.post('/clicked/ajax/:id/:linkId', (req, res) => {
|
||||||
data: []
|
data: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
lists.get(campaign.list, (err, list) => {
|
||||||
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign_tracker__' + campaign.id + '`.`created', 'count'];
|
|
||||||
campaigns.filterClickedSubscribers(campaign, linkId, req.body, columns, (err, data, total, filteredTotal) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.json({
|
return res.json({
|
||||||
error: err.message || err,
|
error: err && err.message || err,
|
||||||
data: []
|
data: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
let campaignCid = campaign.cid;
|
||||||
draw: req.body.draw,
|
let listCid = list.cid;
|
||||||
recordsTotal: total,
|
|
||||||
recordsFiltered: filteredTotal,
|
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign_tracker__' + campaign.id + '`.`created', 'count'];
|
||||||
data: data.map((row, i) => [
|
campaigns.filterClickedSubscribers(campaign, linkId, req.body, columns, (err, data, total, filteredTotal) => {
|
||||||
(Number(req.body.start) || 0) + 1 + i,
|
if (err) {
|
||||||
htmlescape(row.email || ''),
|
return res.json({
|
||||||
htmlescape(row.firstName || ''),
|
error: err.message || err,
|
||||||
htmlescape(row.lastName || ''),
|
data: []
|
||||||
row.created && row.created.toISOString ? '<span class="datestring" data-date="' + row.created.toISOString() + '" title="' + row.created.toISOString() + '">' + row.created.toISOString() + '</span>' : 'N/A',
|
});
|
||||||
row.count,
|
}
|
||||||
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + campaign.list + '/edit/' + row.cid + '">Edit</a>'
|
|
||||||
])
|
res.json({
|
||||||
|
draw: req.body.draw,
|
||||||
|
recordsTotal: total,
|
||||||
|
recordsFiltered: filteredTotal,
|
||||||
|
data: data.map((row, 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 || ''),
|
||||||
|
row.created && row.created.toISOString ? '<span class="datestring" data-date="' + row.created.toISOString() + '" title="' + row.created.toISOString() + '">' + row.created.toISOString() + '</span>' : 'N/A',
|
||||||
|
row.count,
|
||||||
|
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + campaign.list + '/edit/' + row.cid + '">Edit</a>'
|
||||||
|
])
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -603,28 +614,40 @@ router.post('/status/ajax/:id/:status', (req, res) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign__' + campaign.id + '`.`updated'];
|
lists.get(campaign.list, (err, list) => {
|
||||||
campaigns.filterStatusSubscribers(campaign, status, req.body, columns, (err, data, total, filteredTotal) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.json({
|
return res.json({
|
||||||
error: err.message || err,
|
error: err && err.message || err,
|
||||||
data: []
|
data: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
let campaignCid = campaign.cid;
|
||||||
draw: req.body.draw,
|
let listCid = list.cid;
|
||||||
recordsTotal: total,
|
|
||||||
recordsFiltered: filteredTotal,
|
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign__' + campaign.id + '`.`updated'];
|
||||||
data: data.map((row, i) => [
|
campaigns.filterStatusSubscribers(campaign, status, req.body, columns, (err, data, total, filteredTotal) => {
|
||||||
(Number(req.body.start) || 0) + 1 + i,
|
if (err) {
|
||||||
htmlescape(row.email || ''),
|
return res.json({
|
||||||
htmlescape(row.firstName || ''),
|
error: err.message || err,
|
||||||
htmlescape(row.lastName || ''),
|
data: []
|
||||||
htmlescape(row.response || ''),
|
});
|
||||||
row.updated && row.created.toISOString ? '<span class="datestring" data-date="' + row.updated.toISOString() + '" title="' + row.updated.toISOString() + '">' + row.updated.toISOString() + '</span>' : 'N/A',
|
}
|
||||||
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + campaign.list + '/edit/' + row.cid + '">Edit</a>'
|
|
||||||
])
|
res.json({
|
||||||
|
draw: req.body.draw,
|
||||||
|
recordsTotal: total,
|
||||||
|
recordsFiltered: filteredTotal,
|
||||||
|
data: data.map((row, 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 || ''),
|
||||||
|
htmlescape(row.response || ''),
|
||||||
|
row.updated && row.created.toISOString ? '<span class="datestring" data-date="' + row.updated.toISOString() + '" title="' + row.updated.toISOString() + '">' + row.updated.toISOString() + '</span>' : 'N/A',
|
||||||
|
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + campaign.list + '/edit/' + row.cid + '">Edit</a>'
|
||||||
|
])
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -264,19 +264,41 @@ router.post('/status/ajax/:id', (req, res) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
campaigns.get(trigger.destCampaign, false, (err, campaign) => {
|
||||||
draw: req.body.draw,
|
if (err) {
|
||||||
recordsTotal: total,
|
return res.json({
|
||||||
recordsFiltered: filteredTotal,
|
error: err && err.message || err,
|
||||||
data: data.map((row, i) => [
|
data: []
|
||||||
(Number(req.body.start) || 0) + 1 + i,
|
});
|
||||||
htmlescape(row.email || ''),
|
}
|
||||||
htmlescape(row.firstName || ''),
|
lists.get(trigger.list, (err, list) => {
|
||||||
htmlescape(row.lastName || ''),
|
if (err) {
|
||||||
'<span class="datestring" data-date="' + row.created.toISOString() + '" title="' + row.created.toISOString() + '">' + row.created.toISOString() + '</span>',
|
return res.json({
|
||||||
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + trigger.list + '/edit/' + row.cid + '">Edit</a>'
|
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) => [
|
||||||
|
'<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 || ''),
|
||||||
|
'<span class="datestring" data-date="' + row.created.toISOString() + '" title="' + row.created.toISOString() + '">' + row.created.toISOString() + '</span>',
|
||||||
|
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + trigger.list + '/edit/' + row.cid + '">Edit</a>'
|
||||||
|
])
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue