diff --git a/lib/tools.js b/lib/tools.js index 41c8b782..b1aecb72 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -20,6 +20,8 @@ module.exports = { formatMessage, getMessageLinks, prepareHtml, + getDefaultMergeTags, + getListMergeTags, workers: new Set() }; @@ -222,3 +224,73 @@ function prepareHtml(html, callback) { return callback(null, juice(preparedHtml)); }); } + +function getDefaultMergeTags(callback) { + // Using a callback for the sake of future-proofness + callback(null, [ + { + key: 'LINK_UNSUBSCRIBE', + value: 'URL that points to the unsubscribe page' + }, { + key: 'LINK_PREFERENCES', + value: 'URL that points to the preferences page of the subscriber' + }, { + key: 'LINK_BROWSER', + value: 'URL to preview the message in a browser' + }, { + key: 'EMAIL', + value: 'Email address' + }, { + key: 'FIRST_NAME', + value: 'First name' + }, { + key: 'LAST_NAME', + value: 'Last name' + }, { + key: 'FULL_NAME', + value: 'Full name (first and last name combined)' + }, { + key: 'SUBSCRIPTION_ID', + value: 'Unique ID that identifies the recipient' + }, { + key: 'LIST_ID', + value: 'Unique ID that identifies the list used for this campaign' + }, { + key: 'CAMPAIGN_ID', + value: 'Unique ID that identifies current campaign' + } + ]); +} + +function getListMergeTags(listId, callback) { + let lists = require('./models/lists'); + let fields = require('./models/fields'); + + lists.get(listId, (err, list) => { + if (err) { + return callback(err); + } + if (!list) { + list = { + id: listId + }; + } + + fields.list(list.id, (err, fieldList) => { + if (err && !fieldList) { + fieldList = []; + } + + let mergeTags = []; + + fieldList.forEach(field => { + mergeTags.push({ + key: field.key, + value: field.name + }); + }); + + return callback(null, mergeTags); + }); + }); +} diff --git a/routes/campaigns.js b/routes/campaigns.js index e5d715a9..4a653cf6 100644 --- a/routes/campaigns.js +++ b/routes/campaigns.js @@ -184,76 +184,25 @@ router.get('/edit/:id', passport.csrfProtection, (req, res, next) => { view = 'campaigns/edit'; } - let getList = (listId, callback) => { - lists.get(listId, (err, list) => { - if (err) { - return callback(err); - } - if (!list) { - list = { - id: listId - }; - } - - fields.list(list.id, (err, fieldList) => { - if (err && !fieldList) { - fieldList = []; - } - - let mergeTags = [ - // keep indentation - { - key: 'LINK_UNSUBSCRIBE', - value: 'URL that points to the preferences page of the subscriber' - }, { - key: 'LINK_PREFERENCES', - value: 'URL that points to the unsubscribe page' - }, { - key: 'LINK_BROWSER', - value: 'URL to preview the message in a browser' - }, { - key: 'EMAIL', - value: 'Email address' - }, { - key: 'FIRST_NAME', - value: 'First name' - }, { - key: 'LAST_NAME', - value: 'Last name' - }, { - key: 'FULL_NAME', - value: 'Full name (first and last name combined)' - }, { - key: 'SUBSCRIPTION_ID', - value: 'Unique ID that identifies the recipient' - }, { - key: 'LIST_ID', - value: 'Unique ID that identifies the list used for this campaign' - }, { - key: 'CAMPAIGN_ID', - value: 'Unique ID that identifies current campaign' - } - ]; - - fieldList.forEach(field => { - mergeTags.push({ - key: field.key, - value: field.name - }); - }); - - return callback(null, list, mergeTags); - }); - }); - }; - - getList(campaign.list, (err, list, mergeTags) => { + tools.getDefaultMergeTags((err, defaultMergeTags) => { if (err) { req.flash('danger', err.message || err); return res.redirect('/'); } - campaign.mergeTags = mergeTags; - res.render(view, campaign); + + tools.getListMergeTags(campaign.list, (err, listMergeTags) => { + if (err) { + req.flash('danger', err.message || err); + return res.redirect('/'); + } + + campaign.mergeTags = defaultMergeTags.concat(listMergeTags); + campaign.type === 2 && campaign.mergeTags.push({ + key: 'RSS_ENTRY', + value: 'content from an RSS entry' + }); + res.render(view, campaign); + }); }); }); }); diff --git a/routes/templates.js b/routes/templates.js index 576d446a..778f4cb4 100644 --- a/routes/templates.js +++ b/routes/templates.js @@ -111,12 +111,21 @@ router.get('/edit/:id', passport.csrfProtection, (req, res, next) => { if (err) { return next(err); } - template.csrfToken = req.csrfToken(); - template.useEditor = true; - template.editorName = template.editorName || 'summernote'; - template.editorConfig = config[template.editorName]; - template.disableWysiwyg = configItems.disableWysiwyg; - res.render('templates/edit', template); + + tools.getDefaultMergeTags((err, defaultMergeTags) => { + if (err) { + req.flash('danger', err.message || err); + return res.redirect('/templates'); + } + + template.mergeTags = defaultMergeTags; + template.csrfToken = req.csrfToken(); + template.useEditor = true; + template.editorName = template.editorName || 'summernote'; + template.editorConfig = config[template.editorName]; + template.disableWysiwyg = configItems.disableWysiwyg; + res.render('templates/edit', template); + }); }); }); }); diff --git a/views/campaigns/edit-rss.hbs b/views/campaigns/edit-rss.hbs index 466fb021..c8efcc2b 100644 --- a/views/campaigns/edit-rss.hbs +++ b/views/campaigns/edit-rss.hbs @@ -71,51 +71,7 @@ -
- Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: [TAG_NAME]
or [TAG_NAME/fallback]
where fallback
is an optional text value
- used when TAG_NAME
is empty.
-
- Merge tag - | -- Description - | -
---|---|
- [RSS_ENTRY] - | -- content from an RSS entry - | -
- [{{key}}] - | -- {{value}} - | -
- Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: [TAG_NAME]
or [TAG_NAME/fallback]
where fallback
is an optional
- text value used when TAG_NAME
is empty.
-
- Merge tag - | -- Description - | -
---|---|
- [{{key}}] - | -- {{value}} - | -
- Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: [TAG_NAME]
or [TAG_NAME/fallback]
where fallback
is an optional
- text value used when TAG_NAME
is empty.
-
- Merge tag - | -- Description - | -
---|---|
- [{{key}}] - | -- {{value}} - | -
+ Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: [TAG_NAME]
or [TAG_NAME/fallback]
where fallback
is an optional text value
+ used when TAG_NAME
is empty.
+
+ Merge tag + | ++ Description + | +
---|---|
+ [{{key}}] + | ++ {{value}} + | +
{{mergeTagReferenceFooterText}}
+ {{/if}} + +
- Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: [TAG_NAME]
or [TAG_NAME/fallback]
where fallback
is an optional text value used
- when TAG_NAME
is empty.
-
[EMAIL]
– email address of the subscriber
- [FIRST_NAME]
– first name of the subscriber
- [LAST_NAME]
– last name of the subscriber
- [FULL_NAME]
– first and last names of the subscriber joined
- [LINK_UNSUBSCRIBE]
– URL that points to the preferences page of the subscriber
- [LINK_PREFERENCES]
– URL that points to the unsubscribe page
- [LINK_BROWSER]
– URL to preview the message in a browser
- [SUBSCRIPTION_ID]
– Unique ID that identifies the recipient
- [LIST_ID]
– Unique ID that identifies the list used for this campaign
- [CAMPAIGN_ID]
– Unique ID that identifies current campaign
- - In addition to that any custom field can have its own merge tag. -
-