Copy custom forms added
This commit is contained in:
parent
75138f9728
commit
e9bf4a890c
7 changed files with 67 additions and 6 deletions
|
@ -380,13 +380,18 @@ export default class CUD extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
@withFormErrorHandlers
|
@withFormErrorHandlers
|
||||||
async submitHandler(submitAndLeave) {
|
async submitHandler(submitAndLeave, copy) {
|
||||||
const t = this.props.t;
|
const t = this.props.t;
|
||||||
|
|
||||||
let sendMethod, url;
|
let sendMethod, url;
|
||||||
if (this.props.entity) {
|
if (this.props.entity) {
|
||||||
|
if(copy){
|
||||||
|
sendMethod = FormSendMethod.POST;
|
||||||
|
url = `rest/forms/${this.props.entity.id}`
|
||||||
|
}else{
|
||||||
sendMethod = FormSendMethod.PUT;
|
sendMethod = FormSendMethod.PUT;
|
||||||
url = `rest/forms/${this.props.entity.id}`
|
url = `rest/forms/${this.props.entity.id}`
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sendMethod = FormSendMethod.POST;
|
sendMethod = FormSendMethod.POST;
|
||||||
url = 'rest/forms'
|
url = 'rest/forms'
|
||||||
|
@ -404,15 +409,23 @@ export default class CUD extends Component {
|
||||||
} else {
|
} else {
|
||||||
await this.getFormValuesFromURL(`rest/forms/${this.props.entity.id}`);
|
await this.getFormValuesFromURL(`rest/forms/${this.props.entity.id}`);
|
||||||
this.enableForm();
|
this.enableForm();
|
||||||
|
if(copy){
|
||||||
|
this.navigateToWithFlashMessage(`/lists/forms`, 'success', t('customFormsCopied'));
|
||||||
|
}else{
|
||||||
this.setFormStatusMessage('success', t('customFormsUpdated'));
|
this.setFormStatusMessage('success', t('customFormsUpdated'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (submitAndLeave) {
|
if (submitAndLeave) {
|
||||||
this.navigateToWithFlashMessage('/lists/forms', 'success', t('customFormsCreated'));
|
this.navigateToWithFlashMessage('/lists/forms', 'success', t('customFormsCreated'));
|
||||||
} else {
|
} else {
|
||||||
|
if(copy){
|
||||||
|
this.navigateToWithFlashMessage(`/lists/forms`, 'success', t('customFormsCopied'));
|
||||||
|
}else{
|
||||||
this.navigateToWithFlashMessage(`/lists/forms/${submitResult}/edit`, 'success', t('customFormsCreated'));
|
this.navigateToWithFlashMessage(`/lists/forms/${submitResult}/edit`, 'success', t('customFormsCreated'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.enableForm();
|
this.enableForm();
|
||||||
this.setFormStatusMessage('warning', t('thereAreErrorsInTheFormPleaseFixThemAnd'));
|
this.setFormStatusMessage('warning', t('thereAreErrorsInTheFormPleaseFixThemAnd'));
|
||||||
|
@ -552,7 +565,8 @@ export default class CUD extends Component {
|
||||||
|
|
||||||
<ButtonRow>
|
<ButtonRow>
|
||||||
<Button type="submit" className="btn-primary" icon="check" label={t('save')}/>
|
<Button type="submit" className="btn-primary" icon="check" label={t('save')}/>
|
||||||
<Button type="submit" className="btn-primary" icon="check" label={t('saveAndLeave')} onClickAsync={async () => await this.submitHandler(true)}/>
|
<Button type="submit" className="btn-primary" icon="check" label={t('saveAndLeave')} onClickAsync={async () => await this.submitHandler(true, false)}/>
|
||||||
|
{isEdit && <Button type="submit" className="btn-success" icon="copy" label={t('copy')} onClickAsync={async () => await this.submitHandler(false, true)}/>}
|
||||||
{canDelete && <LinkButton className="btn-danger" icon="trash-alt" label={t('delete')} to={`/lists/forms/${this.props.entity.id}/delete`}/>}
|
{canDelete && <LinkButton className="btn-danger" icon="trash-alt" label={t('delete')} to={`/lists/forms/${this.props.entity.id}/delete`}/>}
|
||||||
</ButtonRow>
|
</ButtonRow>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
"customTemplateEditor": "Custom template editor",
|
"customTemplateEditor": "Custom template editor",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"saveAndLeave": "Save and leave",
|
"saveAndLeave": "Save and leave",
|
||||||
|
"copy": "Copy",
|
||||||
"saveAndGoToStatus": "Save and go to status",
|
"saveAndGoToStatus": "Save and go to status",
|
||||||
"testSend": "Test send",
|
"testSend": "Test send",
|
||||||
"createRegularCampaign": "Create Regular Campaign",
|
"createRegularCampaign": "Create Regular Campaign",
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
"customTemplateEditor": "Custom template editor",
|
"customTemplateEditor": "Custom template editor",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"saveAndLeave": "Save and leave",
|
"saveAndLeave": "Save and leave",
|
||||||
|
"copy": "Copy",
|
||||||
"saveAndGoToStatus": "Save and go to status",
|
"saveAndGoToStatus": "Save and go to status",
|
||||||
"testSend": "Test send",
|
"testSend": "Test send",
|
||||||
"createRegularCampaign": "Create Regular Campaign",
|
"createRegularCampaign": "Create Regular Campaign",
|
||||||
|
|
|
@ -105,6 +105,7 @@
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"saveAndLeave": "Save and leave",
|
"saveAndLeave": "Save and leave",
|
||||||
"saveAndLeave - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and leave",
|
"saveAndLeave - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and leave",
|
||||||
|
"copy": "Copiar",
|
||||||
"saveAndGoToStatus": "Save and go to status",
|
"saveAndGoToStatus": "Save and go to status",
|
||||||
"saveAndGoToStatus - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and go to status",
|
"saveAndGoToStatus - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and go to status",
|
||||||
"testSend": "Test send",
|
"testSend": "Test send",
|
||||||
|
|
|
@ -105,6 +105,7 @@
|
||||||
"save": "Salvar",
|
"save": "Salvar",
|
||||||
"saveAndLeave": "Salvar e sair",
|
"saveAndLeave": "Salvar e sair",
|
||||||
"saveAndLeave - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and leave",
|
"saveAndLeave - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and leave",
|
||||||
|
"copy": "Copy",
|
||||||
"saveAndGoToStatus": "Save and go to status",
|
"saveAndGoToStatus": "Save and go to status",
|
||||||
"saveAndGoToStatus - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and go to status",
|
"saveAndGoToStatus - TODO: update line above and then delete this line to mark that the translation has been fixed": "Save and go to status",
|
||||||
"testSend": "Testar envio",
|
"testSend": "Testar envio",
|
||||||
|
|
|
@ -175,6 +175,41 @@ async function updateWithConsistencyCheck(context, entity) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function copy(context, entity) {
|
||||||
|
await knex.transaction(async tx => {
|
||||||
|
await shares.enforceEntityPermissionTx(tx, context, 'customForm', entity.id, 'edit');
|
||||||
|
|
||||||
|
const existing = await _getById(tx, entity.id);
|
||||||
|
|
||||||
|
const existingHash = hash(existing);
|
||||||
|
if (existingHash !== entity.originalHash) {
|
||||||
|
throw new interoperableErrors.ChangedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
await namespaceHelpers.validateEntity(tx, entity);
|
||||||
|
await namespaceHelpers.validateMove(context, entity, existing, 'customForm', 'createCustomForm', 'delete');
|
||||||
|
|
||||||
|
const form = filterObject(entity, allowedFormKeys);
|
||||||
|
enforce(!Object.keys(checkForMjmlErrors(form)).length, 'Error(s) in form templates');
|
||||||
|
|
||||||
|
entity.name = entity.name + '_COPY';
|
||||||
|
const ids = await tx('custom_forms').insert(filterObject(entity, formAllowedKeys));
|
||||||
|
|
||||||
|
const id = ids[0];
|
||||||
|
|
||||||
|
for (const formKey in form) {
|
||||||
|
await tx('custom_forms_data').insert({
|
||||||
|
form: id,
|
||||||
|
data_key: formKey,
|
||||||
|
data_value: form[formKey]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'customForm', entityId: id });
|
||||||
|
|
||||||
|
return id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function remove(context, id) {
|
async function remove(context, id) {
|
||||||
await knex.transaction(async tx => {
|
await knex.transaction(async tx => {
|
||||||
await shares.enforceEntityPermissionTx(tx, context, 'customForm', id, 'delete');
|
await shares.enforceEntityPermissionTx(tx, context, 'customForm', id, 'delete');
|
||||||
|
@ -285,6 +320,7 @@ module.exports.hash = hash;
|
||||||
module.exports.getById = getById;
|
module.exports.getById = getById;
|
||||||
module.exports.create = create;
|
module.exports.create = create;
|
||||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||||
|
module.exports.copy = copy;
|
||||||
module.exports.remove = remove;
|
module.exports.remove = remove;
|
||||||
module.exports.getDefaultCustomFormValues = getDefaultCustomFormValues;
|
module.exports.getDefaultCustomFormValues = getDefaultCustomFormValues;
|
||||||
module.exports.serverValidate = serverValidate;
|
module.exports.serverValidate = serverValidate;
|
||||||
|
|
|
@ -26,6 +26,13 @@ router.postAsync('/forms', passport.loggedIn, passport.csrfProtection, async (re
|
||||||
return res.json(await forms.create(req.context, req.body));
|
return res.json(await forms.create(req.context, req.body));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.postAsync('/forms/:formId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
||||||
|
const entity = req.body;
|
||||||
|
entity.id = castToInteger(req.params.formId);
|
||||||
|
await forms.copy(req.context, entity);
|
||||||
|
return res.json();
|
||||||
|
});
|
||||||
|
|
||||||
router.putAsync('/forms/:formId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
router.putAsync('/forms/:formId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
||||||
const entity = req.body;
|
const entity = req.body;
|
||||||
entity.id = castToInteger(req.params.formId);
|
entity.id = castToInteger(req.params.formId);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue