Merge pull request #556 from ateuber/duplicate_campaign
Duplicate campaign
This commit is contained in:
commit
de78c587f5
4 changed files with 32 additions and 1 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);
|
||||
|
|
|
@ -574,11 +574,12 @@ module.exports.getQuery = (id, prefix, callback) => {
|
|||
|
||||
segment.rules.forEach(rule => {
|
||||
switch (rule.columnType.type) {
|
||||
case 'string':
|
||||
case 'string': {
|
||||
let condition = rule.value.negate ? 'NOT LIKE' : 'LIKE';
|
||||
query.push(prefix + '`' + rule.columnType.column + '` ' + condition + ' ?');
|
||||
values.push(rule.value.value);
|
||||
break;
|
||||
}
|
||||
case 'boolean':
|
||||
query.push(prefix + '`' + rule.columnType.column + '` = ?');
|
||||
values.push(rule.value.value);
|
||||
|
|
|
@ -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