Adds duplicate button to Template edit form.
Adds duplicate model function for Template that gets a Template by id and creates a new Template with the same data.
This commit is contained in:
parent
b30a9f2e41
commit
0cbec006b4
3 changed files with 36 additions and 5 deletions
|
@ -61,15 +61,17 @@ module.exports.create = (template, callback) => {
|
|||
let values = [name];
|
||||
|
||||
Object.keys(template).forEach(key => {
|
||||
let value = template[key].trim();
|
||||
let value = template[key];
|
||||
key = tools.toDbKey(key);
|
||||
if (!allowedKeys.includes(key)) {
|
||||
return;
|
||||
}
|
||||
value = value.trim();
|
||||
if (key === 'description') {
|
||||
value = tools.purifyHTML(value);
|
||||
}
|
||||
if (allowedKeys.indexOf(key) >= 0) {
|
||||
keys.push(key);
|
||||
values.push(value);
|
||||
}
|
||||
keys.push(key);
|
||||
values.push(value);
|
||||
});
|
||||
|
||||
db.getConnection((err, connection) => {
|
||||
|
@ -137,6 +139,16 @@ module.exports.update = (id, updates, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.duplicate = (id, callback) => {
|
||||
return this.get(id, (err, template) => {
|
||||
if (!template) {
|
||||
return callback(new Error(_('Template does not exist')));
|
||||
}
|
||||
template.name = template.name + ' Copy';
|
||||
return this.create(template, callback);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.delete = (id, callback) => {
|
||||
id = Number(id) || 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue