Added possibility to duplicate a campaign
This commit is contained in:
parent
f2ed0e8ce2
commit
2b11a319b4
3 changed files with 30 additions and 0 deletions
|
@ -365,6 +365,17 @@ module.exports.getLinks = (id, linkId, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.duplicate = (id, callback) => module.exports.get(id, true, (err, campaign) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (!campaign) {
|
||||
return callback(new Error(_('Campaign does not exist')));
|
||||
}
|
||||
campaign.name = campaign.name + ' Copy';
|
||||
return module.exports.create(campaign, false, callback);
|
||||
});
|
||||
|
||||
module.exports.create = (campaign, opts, callback) => {
|
||||
|
||||
campaign = tools.convertKeys(campaign);
|
||||
|
|
|
@ -126,6 +126,19 @@ router.post('/create', passport.parseForm, passport.csrfProtection, (req, res) =
|
|||
});
|
||||
});
|
||||
|
||||
router.post('/duplicate', passport.parseForm, passport.csrfProtection, (req, res) => {
|
||||
campaigns.duplicate(req.body.id, (err, duplicated) => {
|
||||
if (err) {
|
||||
req.flash('danger', err && err.message || err);
|
||||
} else if (duplicated) {
|
||||
req.flash('success', _('Campaign duplicated'));
|
||||
} else {
|
||||
req.flash('info', _('Could not duplicate specified campaign'));
|
||||
}
|
||||
return res.redirect('/campaigns/edit/' + duplicated);
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/edit/:id', passport.csrfProtection, (req, res, next) => {
|
||||
campaigns.get(req.params.id, false, (err, campaign) => {
|
||||
if (err || !campaign) {
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
<input type="hidden" name="id" value="{{id}}" />
|
||||
</form>
|
||||
|
||||
<form method="post" class="duplicate-form" id="campaigns-duplicate" action="/campaigns/duplicate">
|
||||
<input type="hidden" name="_csrf" value="{{csrfToken}}">
|
||||
<input type="hidden" name="id" value="{{id}}" />
|
||||
</form>
|
||||
|
||||
{{#each attachments}}
|
||||
<form method="post" id="attachment-download-{{id}}" action="/campaigns/attachment/download">
|
||||
<input type="hidden" name="_csrf" value="{{../csrfToken}}">
|
||||
|
@ -240,6 +245,7 @@
|
|||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<div class="pull-right">
|
||||
<button type="submit" form="campaigns-duplicate" class="btn btn-default"> {{#translate}}Duplicate{{/translate}}</button>
|
||||
<button type="submit" form="campaigns-delete" class="btn btn-danger"><i class="glyphicon glyphicon-remove"></i> {{#translate}}Delete Campaign{{/translate}}</button>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-ok"></i> {{#translate}}Update{{/translate}}</button>
|
||||
|
|
Loading…
Reference in a new issue