Merge branch 'pull/637' into integration-637
# Conflicts: # client/src/lists/forms/CUD.js
This commit is contained in:
commit
6eeef7a991
7 changed files with 126 additions and 54 deletions
|
@ -10,6 +10,7 @@ import {
|
|||
AlignedRow,
|
||||
Button,
|
||||
ButtonRow,
|
||||
CheckBox,
|
||||
Dropdown,
|
||||
Fieldset,
|
||||
filterData,
|
||||
|
@ -45,7 +46,9 @@ export default class CUD extends Component {
|
|||
|
||||
this.state = {
|
||||
previewContents: null,
|
||||
previewFullscreen: false
|
||||
previewFullscreen: false,
|
||||
fromSourceCustomForms: false,
|
||||
sourceCustomForms: null,
|
||||
};
|
||||
|
||||
this.serverValidatedFields = [
|
||||
|
@ -330,6 +333,8 @@ export default class CUD extends Component {
|
|||
const data = {
|
||||
name: '',
|
||||
description: '',
|
||||
fromSourceCustomForms: false,
|
||||
sourceCustomForms: null,
|
||||
selectedTemplate: 'layout',
|
||||
namespace: mailtrainConfig.user.namespace
|
||||
};
|
||||
|
@ -350,6 +355,12 @@ export default class CUD extends Component {
|
|||
|
||||
validateNamespace(t, state);
|
||||
|
||||
if (state.getIn(['fromSourceCustomForms', 'value']) && !state.getIn(['sourceCustomForms', 'value'])) {
|
||||
state.setIn(['sourceCustomForms', 'error'], t('sourceCustomFormsMustNotBeEmpty'));
|
||||
} else {
|
||||
state.setIn(['sourceCustomForms', 'error'], null);
|
||||
}
|
||||
|
||||
let formsServerValidationRunning = false;
|
||||
const formsErrors = [];
|
||||
|
||||
|
@ -386,10 +397,14 @@ export default class CUD extends Component {
|
|||
let sendMethod, url;
|
||||
if (this.props.entity) {
|
||||
sendMethod = FormSendMethod.PUT;
|
||||
url = `rest/forms/${this.props.entity.id}`
|
||||
url = `rest/forms/${this.props.entity.id}`;
|
||||
} else {
|
||||
sendMethod = FormSendMethod.POST;
|
||||
url = 'rest/forms'
|
||||
if (this.getFormValue('sourceCustomForms') !== null) {
|
||||
url = `rest/forms/${this.getFormValue('sourceCustomForms')}`;
|
||||
} else {
|
||||
url = 'rest/forms';
|
||||
}
|
||||
}
|
||||
|
||||
this.disableForm();
|
||||
|
@ -456,6 +471,12 @@ export default class CUD extends Component {
|
|||
});
|
||||
}
|
||||
|
||||
const customFormsColumns = [
|
||||
{ data: 1, title: t('name') },
|
||||
{ data: 2, title: t('description') },
|
||||
{ data: 3, title: t('namespace') }
|
||||
];
|
||||
|
||||
const listsColumns = [
|
||||
{ data: 0, title: "#" },
|
||||
{ data: 1, title: t('name') },
|
||||
|
@ -488,60 +509,70 @@ export default class CUD extends Component {
|
|||
|
||||
<NamespaceSelect/>
|
||||
|
||||
<Fieldset label={t('formsPreview')}>
|
||||
<TableSelect id="previewList" label={t('listToPreviewOn')} withHeader dropdown dataUrl='rest/lists-table' columns={listsColumns} selectionLabelIndex={1} help={t('selectListWhoseFieldsWillBeUsedToPreview')}/>
|
||||
{!isEdit &&
|
||||
<CheckBox id="fromSourceCustomForms" label={t('customForms')} text={t('cloneFromAnExistingCustomForms')}/>
|
||||
}
|
||||
|
||||
{ previewListId &&
|
||||
<div>
|
||||
<AlignedRow>
|
||||
<div>
|
||||
<small>
|
||||
{t('noteTheseLinksAreSolelyForAQuickPreview')}
|
||||
</small>
|
||||
</div>
|
||||
<p>
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_subscribe')}>Subscribe</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_confirm_subscription_notice')}>Confirm Subscription Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_confirm_unsubscription_notice')}>Confirm Unsubscription Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_subscribed_notice')}>Subscribed Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_updated_notice')}>Updated Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_unsubscribed_notice')}>Unsubscribed Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_manual_unsubscribe_notice')}>Manual Unsubscribe Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_unsubscribe')}>Unsubscribe</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_manage')}>Manage</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_manage_address')}>Manage Address</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_privacy_policy_notice')}>Privacy Policy</ActionLink>
|
||||
</p>
|
||||
</AlignedRow>
|
||||
{this.state.previewContents &&
|
||||
<div className={this.state.previewFullscreen ? formsStyles.editorFullscreen : formsStyles.editor}>
|
||||
<div className={formsStyles.navbar}>
|
||||
<div className={formsStyles.navbarLeft}>
|
||||
{this.state.fullscreen && <img className={formsStyles.logo} src={getTrustedUrl('static/mailtrain-notext.png')}/>}
|
||||
<div className={formsStyles.title}>{t('formPreview') + ' ' + this.state.previewLabel}</div>
|
||||
{this.getFormValue('fromSourceCustomForms') &&
|
||||
<TableSelect key="sourceCustomFormsKey" id="sourceCustomForms" withHeader dropdown dataUrl='rest/forms-table' columns={customFormsColumns} selectionLabelIndex={1} />
|
||||
}
|
||||
|
||||
{!this.getFormValue('fromSourceCustomForms') &&
|
||||
<Fieldset label={t('formsPreview')}>
|
||||
<TableSelect id="previewList" label={t('listToPreviewOn')} withHeader dropdown dataUrl='rest/lists-table' columns={listsColumns} selectionLabelIndex={1} help={t('selectListWhoseFieldsWillBeUsedToPreview')}/>
|
||||
|
||||
{ previewListId &&
|
||||
<div>
|
||||
<AlignedRow>
|
||||
<div>
|
||||
<small>
|
||||
{t('noteTheseLinksAreSolelyForAQuickPreview')}
|
||||
</small>
|
||||
</div>
|
||||
<div className={formsStyles.navbarRight}>
|
||||
<a className={formsStyles.btn} onClick={() => this.preview(this.state.previewKey)} title={t('refresh')}><Icon icon="sync-alt"/></a>
|
||||
<a className={formsStyles.btn} onClick={() => this.setState({previewFullscreen: !this.state.previewFullscreen})} title={t('maximizeEditor')}><Icon icon="window-maximize"/></a>
|
||||
<a className={formsStyles.btn} onClick={() => this.setState({previewContents: null, previewFullscreen: false})} title={t('closePreview')}><Icon icon="window-close"/></a>
|
||||
<p>
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_subscribe')}>Subscribe</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_confirm_subscription_notice')}>Confirm Subscription Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_confirm_unsubscription_notice')}>Confirm Unsubscription Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_subscribed_notice')}>Subscribed Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_updated_notice')}>Updated Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_unsubscribed_notice')}>Unsubscribed Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_manual_unsubscribe_notice')}>Manual Unsubscribe Notice</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_unsubscribe')}>Unsubscribe</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_manage')}>Manage</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_manage_address')}>Manage Address</ActionLink>
|
||||
{' | '}
|
||||
<ActionLink onClickAsync={async () => await this.preview('web_privacy_policy_notice')}>Privacy Policy</ActionLink>
|
||||
</p>
|
||||
</AlignedRow>
|
||||
{this.state.previewContents &&
|
||||
<div className={this.state.previewFullscreen ? formsStyles.editorFullscreen : formsStyles.editor}>
|
||||
<div className={formsStyles.navbar}>
|
||||
<div className={formsStyles.navbarLeft}>
|
||||
{this.state.fullscreen && <img className={formsStyles.logo} src={getTrustedUrl('static/mailtrain-notext.png')}/>}
|
||||
<div className={formsStyles.title}>{t('formPreview') + ' ' + this.state.previewLabel}</div>
|
||||
</div>
|
||||
<div className={formsStyles.navbarRight}>
|
||||
<a className={formsStyles.btn} onClick={() => this.preview(this.state.previewKey)} title={t('refresh')}><Icon icon="sync-alt"/></a>
|
||||
<a className={formsStyles.btn} onClick={() => this.setState({previewFullscreen: !this.state.previewFullscreen})} title={t('maximizeEditor')}><Icon icon="window-maximize"/></a>
|
||||
<a className={formsStyles.btn} onClick={() => this.setState({previewContents: null, previewFullscreen: false})} title={t('closePreview')}><Icon icon="window-close"/></a>
|
||||
</div>
|
||||
</div>
|
||||
<iframe className={formsStyles.host} src={"data:text/html;charset=utf-8," + encodeURIComponent(this.state.previewContents)}></iframe>
|
||||
</div>
|
||||
<iframe className={formsStyles.host} src={"data:text/html;charset=utf-8," + encodeURIComponent(this.state.previewContents)}></iframe>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</Fieldset>
|
||||
}
|
||||
</Fieldset>
|
||||
}
|
||||
|
||||
{ selectedTemplate &&
|
||||
<Fieldset label={t('templates')}>
|
||||
|
|
|
@ -100,6 +100,7 @@
|
|||
"customTemplateEditor": "Custom template editor",
|
||||
"save": "Save",
|
||||
"saveAndLeave": "Save and leave",
|
||||
"copy": "Copy",
|
||||
"saveAndGoToStatus": "Save and go to status",
|
||||
"testSend": "Test send",
|
||||
"createRegularCampaign": "Create Regular Campaign",
|
||||
|
@ -923,6 +924,7 @@
|
|||
"editTemplate": "Edit Template",
|
||||
"createTemplate": "Create Template",
|
||||
"cloneFromAnExistingTemplate": "Clone from an existing template",
|
||||
"cloneFromAnExistingCustomForms": "Clone from an existing custom forms",
|
||||
"mosaico": "Mosaico",
|
||||
"templateContentHtml": "Template content (HTML)",
|
||||
"mosaicoTemplateDesigner": "Mosaico Template Designer",
|
||||
|
|
|
@ -100,6 +100,7 @@
|
|||
"customTemplateEditor": "Custom template editor",
|
||||
"save": "Save",
|
||||
"saveAndLeave": "Save and leave",
|
||||
"copy": "Copy",
|
||||
"saveAndGoToStatus": "Save and go to status",
|
||||
"testSend": "Test send",
|
||||
"createRegularCampaign": "Create Regular Campaign",
|
||||
|
@ -923,6 +924,7 @@
|
|||
"editTemplate": "Edit Template",
|
||||
"createTemplate": "Create Template",
|
||||
"cloneFromAnExistingTemplate": "Clone from an existing template",
|
||||
"cloneFromAnExistingCustomForms": "Clone from an existing custom forms",
|
||||
"mosaico": "Mosaico",
|
||||
"templateContentHtml": "Template content (HTML)",
|
||||
"mosaicoTemplateDesigner": "Mosaico Template Designer",
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
"save": "Save",
|
||||
"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",
|
||||
"copy": "Copiar",
|
||||
"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",
|
||||
"testSend": "Test send",
|
||||
|
@ -992,8 +993,8 @@
|
|||
"templateDeleted": "Template deleted",
|
||||
"editTemplate": "Edit Template",
|
||||
"createTemplate": "Create Template",
|
||||
"cloneFromAnExistingTemplate": "Clone from an existing template",
|
||||
"cloneFromAnExistingTemplate - TODO: update line above and then delete this line to mark that the translation has been fixed": "Clone from an existing template",
|
||||
"cloneFromAnExistingTemplate": "Clonar a partir de templates ya existentes",
|
||||
"cloneFromAnExistingCustomForms": "Clonar a partir de formularios personalizados ya existentes",
|
||||
"mosaico": "Mosaico",
|
||||
"templateContentHtml": "Template content (HTML)",
|
||||
"mosaicoTemplateDesigner": "Mosaico Template Designer",
|
||||
|
|
|
@ -105,6 +105,8 @@
|
|||
"save": "Salvar",
|
||||
"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",
|
||||
"copy": "Copia",
|
||||
"copy - TODO: update line above and then delete this line to mark that the translation has been fixed": "Copy",
|
||||
"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",
|
||||
"testSend": "Testar envio",
|
||||
|
@ -994,6 +996,8 @@
|
|||
"createTemplate": "Criar modelo",
|
||||
"cloneFromAnExistingTemplate": "Clone from an existing template",
|
||||
"cloneFromAnExistingTemplate - TODO: update line above and then delete this line to mark that the translation has been fixed": "Clone from an existing template",
|
||||
"cloneFromAnExistingCustomForms": "Clone from an existing custom forms",
|
||||
"cloneFromAnExistingCustomForms - TODO: update line above and then delete this line to mark that the translation has been fixed": "Clone from an existing custom forms",
|
||||
"mosaico": "Mosaico",
|
||||
"templateContentHtml": "Conteúdo do modelo (HTML)",
|
||||
"mosaicoTemplateDesigner": "Editor do Modelo Mosaico",
|
||||
|
|
|
@ -175,6 +175,31 @@ async function updateWithConsistencyCheck(context, entity) {
|
|||
});
|
||||
}
|
||||
|
||||
async function copy(context, entity, formId) {
|
||||
return await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'namespace', entity.namespace, 'createCustomForm');
|
||||
const existing = await _getById(tx, formId);
|
||||
await namespaceHelpers.validateEntity(tx, entity);
|
||||
|
||||
const form = filterObject(existing, allowedFormKeys);
|
||||
enforce(!Object.keys(checkForMjmlErrors(form)).length, 'Error(s) in form templates');
|
||||
|
||||
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) {
|
||||
await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'customForm', id, 'delete');
|
||||
|
@ -285,6 +310,7 @@ module.exports.hash = hash;
|
|||
module.exports.getById = getById;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.copy = copy;
|
||||
module.exports.remove = remove;
|
||||
module.exports.getDefaultCustomFormValues = getDefaultCustomFormValues;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
|
|
|
@ -26,6 +26,12 @@ router.postAsync('/forms', passport.loggedIn, passport.csrfProtection, async (re
|
|||
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;
|
||||
const formId= castToInteger(req.params.formId);
|
||||
return res.json(await forms.copy(req.context, entity, formId));
|
||||
});
|
||||
|
||||
router.putAsync('/forms/:formId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
||||
const entity = req.body;
|
||||
entity.id = castToInteger(req.params.formId);
|
||||
|
|
Loading…
Reference in a new issue