Merge tag reference abstraction/partial
Perhaps helpers.js would be a more suitable place for getDefaultMergeTags() and getListMergeTags() … ?
This commit is contained in:
parent
9f191bd7da
commit
633463108e
8 changed files with 149 additions and 238 deletions
72
lib/tools.js
72
lib/tools.js
|
@ -20,6 +20,8 @@ module.exports = {
|
||||||
formatMessage,
|
formatMessage,
|
||||||
getMessageLinks,
|
getMessageLinks,
|
||||||
prepareHtml,
|
prepareHtml,
|
||||||
|
getDefaultMergeTags,
|
||||||
|
getListMergeTags,
|
||||||
workers: new Set()
|
workers: new Set()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -222,3 +224,73 @@ function prepareHtml(html, callback) {
|
||||||
return callback(null, juice(preparedHtml));
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -184,76 +184,25 @@ router.get('/edit/:id', passport.csrfProtection, (req, res, next) => {
|
||||||
view = 'campaigns/edit';
|
view = 'campaigns/edit';
|
||||||
}
|
}
|
||||||
|
|
||||||
let getList = (listId, callback) => {
|
tools.getDefaultMergeTags((err, defaultMergeTags) => {
|
||||||
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) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
req.flash('danger', err.message || err);
|
req.flash('danger', err.message || err);
|
||||||
return res.redirect('/');
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -111,12 +111,21 @@ router.get('/edit/:id', passport.csrfProtection, (req, res, next) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
template.csrfToken = req.csrfToken();
|
|
||||||
template.useEditor = true;
|
tools.getDefaultMergeTags((err, defaultMergeTags) => {
|
||||||
template.editorName = template.editorName || 'summernote';
|
if (err) {
|
||||||
template.editorConfig = config[template.editorName];
|
req.flash('danger', err.message || err);
|
||||||
template.disableWysiwyg = configItems.disableWysiwyg;
|
return res.redirect('/templates');
|
||||||
res.render('templates/edit', template);
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -71,51 +71,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
{{> merge_tag_reference}}
|
||||||
<div class="col-sm-offset-2 col-sm-10">
|
|
||||||
<a class="btn btn-default" role="button" data-toggle="collapse" href="#mergeReference" aria-expanded="false" aria-controls="mergeReference">Merge tag reference</a>
|
|
||||||
<div class="collapse" id="mergeReference">
|
|
||||||
<p>
|
|
||||||
Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: <code>[TAG_NAME]</code> or <code>[TAG_NAME/fallback]</code> where <code>fallback</code> is an optional text value
|
|
||||||
used when <code>TAG_NAME</code> is empty.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table class="table table-bordered table-condensed table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
Merge tag
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Description
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
[RSS_ENTRY]
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
content from an RSS entry
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
{{#each mergeTags}}
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
[{{key}}]
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
{{value}}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{/each}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="template" class="col-sm-2 control-label">RSS Feed Url</label>
|
<label for="template" class="col-sm-2 control-label">RSS Feed Url</label>
|
||||||
|
|
|
@ -129,43 +129,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
||||||
|
{{> merge_tag_reference}}
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-offset-2 col-sm-10">
|
|
||||||
<a class="btn btn-default" role="button" data-toggle="collapse" href="#mergeReference" aria-expanded="false" aria-controls="mergeReference">Merge tag reference</a>
|
|
||||||
<div class="collapse" id="mergeReference">
|
|
||||||
<p>
|
|
||||||
Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: <code>[TAG_NAME]</code> or <code>[TAG_NAME/fallback]</code> where <code>fallback</code> is an optional
|
|
||||||
text value used when <code>TAG_NAME</code> is empty.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table class="table table-bordered table-condensed table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
Merge tag
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Description
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{{#each mergeTags}}
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
[{{key}}]
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
{{value}}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{/each}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{> plaintext}}
|
{{> plaintext}}
|
||||||
|
|
||||||
|
|
|
@ -145,43 +145,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
||||||
|
{{> merge_tag_reference}}
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-offset-2 col-sm-10">
|
|
||||||
<a class="btn btn-default" role="button" data-toggle="collapse" href="#mergeReference" aria-expanded="false" aria-controls="mergeReference">Merge tag reference</a>
|
|
||||||
<div class="collapse" id="mergeReference">
|
|
||||||
<p>
|
|
||||||
Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: <code>[TAG_NAME]</code> or <code>[TAG_NAME/fallback]</code> where <code>fallback</code> is an optional
|
|
||||||
text value used when <code>TAG_NAME</code> is empty.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table class="table table-bordered table-condensed table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
Merge tag
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Description
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{{#each mergeTags}}
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
[{{key}}]
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
{{value}}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{/each}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{> plaintext}}
|
{{> plaintext}}
|
||||||
|
|
||||||
|
|
43
views/partials/merge-tag-reference.hbs
Normal file
43
views/partials/merge-tag-reference.hbs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{{#if mergeTags}}
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
|
<a class="btn btn-default" role="button" data-toggle="collapse" href="#mergeReference" aria-expanded="false" aria-controls="mergeReference">Merge tag reference</a>
|
||||||
|
<div class="collapse" id="mergeReference">
|
||||||
|
<p style="margin-top: .8em;">
|
||||||
|
Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: <code>[TAG_NAME]</code> or <code>[TAG_NAME/fallback]</code> where <code>fallback</code> is an optional text value
|
||||||
|
used when <code>TAG_NAME</code> is empty.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table table-bordered table-condensed table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Merge tag
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{#each mergeTags}}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
[{{key}}]
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{value}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/each}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{{#if mergeTagReferenceFooterText}}
|
||||||
|
<p>{{mergeTagReferenceFooterText}}</p>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
|
@ -24,53 +24,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
{{> merge_tag_reference mergeTagReferenceFooterText='In addition to that any custom field can have its own merge tag.'}}
|
||||||
<div class="col-sm-offset-2 col-sm-10">
|
|
||||||
<a class="btn btn-default" role="button" data-toggle="collapse" href="#mergeReference" aria-expanded="false" aria-controls="mergeReference">Merge tag reference</a>
|
|
||||||
<div class="collapse" id="mergeReference">
|
|
||||||
<p>
|
|
||||||
Merge tags are tags that are replaced before sending out the message. The format of the merge tag is the following: <code>[TAG_NAME]</code> or <code>[TAG_NAME/fallback]</code> where <code>fallback</code> is an optional text value used
|
|
||||||
when <code>TAG_NAME</code> is empty.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<code>[EMAIL]</code> – email address of the subscriber
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[FIRST_NAME]</code> – first name of the subscriber
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[LAST_NAME]</code> – last name of the subscriber
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[FULL_NAME]</code> – first and last names of the subscriber joined
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[LINK_UNSUBSCRIBE]</code> – URL that points to the preferences page of the subscriber
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[LINK_PREFERENCES]</code> – URL that points to the unsubscribe page
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[LINK_BROWSER]</code> – URL to preview the message in a browser
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[SUBSCRIPTION_ID]</code> – Unique ID that identifies the recipient
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[LIST_ID]</code> – Unique ID that identifies the list used for this campaign
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<code>[CAMPAIGN_ID]</code> – Unique ID that identifies current campaign
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
In addition to that any custom field can have its own merge tag.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{> plaintext}}
|
{{> plaintext}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue