commit
6b6fa8b3ef
6 changed files with 52 additions and 31 deletions
|
@ -82,7 +82,7 @@ export default class CUD extends Component {
|
||||||
];
|
];
|
||||||
|
|
||||||
this.sourceOptions = [];
|
this.sourceOptions = [];
|
||||||
for (const key in sourceLabelsOrder) {
|
for (const key of sourceLabelsOrder) {
|
||||||
this.sourceOptions.push({key, label: this.sourceLabels[key]});
|
this.sourceOptions.push({key, label: this.sourceLabels[key]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +134,9 @@ export default class CUD extends Component {
|
||||||
|
|
||||||
if (key === 'data_sourceCustom_tag_language') {
|
if (key === 'data_sourceCustom_tag_language') {
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
|
const currentType = this.getFormValue('data_sourceCustom_type');
|
||||||
const isEdit = !!this.props.entity;
|
const isEdit = !!this.props.entity;
|
||||||
this.templateTypes[newValue].afterTagLanguageChange(mutStateData, isEdit);
|
this.templateTypes[currentType].afterTagLanguageChange(mutStateData, isEdit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,8 @@ export default class CustomContent extends Component {
|
||||||
|
|
||||||
onTagLanguageChanged(mutStateData, key, oldTagLanguage, tagLanguage) {
|
onTagLanguageChanged(mutStateData, key, oldTagLanguage, tagLanguage) {
|
||||||
if (tagLanguage) {
|
if (tagLanguage) {
|
||||||
const type = mutStateData.getIn(['data_sourceCustom_tag_language', 'value']);
|
const type = mutStateData.getIn(['data_sourceCustom_type', 'value']);
|
||||||
this.tagLanguages[type].afterTagLanguageChange(mutStateData, true);
|
this.templateTypes[type].afterTagLanguageChange(mutStateData, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,13 @@ export default class CUD extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
submitFormValuesMutator(data) {
|
submitFormValuesMutator(data) {
|
||||||
this.templateTypes[data.type].beforeSave(data);
|
if (data.fromExistingEntity) {
|
||||||
|
return filterData(data, ['name', 'description', 'namespace', 'fromExistingEntity', 'existingEntity']);
|
||||||
|
|
||||||
return filterData(data, ['name', 'description', 'type', 'tag_language', 'data', 'html', 'text', 'namespace', 'fromExistingEntity', 'existingEntity']);
|
} else {
|
||||||
|
this.templateTypes[data.type].beforeSave(data);
|
||||||
|
return filterData(data, ['name', 'description', 'type', 'tag_language', 'data', 'html', 'text', 'namespace', 'fromExistingEntity']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPreSubmitFormValuesUpdater() {
|
async getPreSubmitFormValuesUpdater() {
|
||||||
|
@ -151,25 +155,28 @@ export default class CUD extends Component {
|
||||||
state.setIn(['name', 'error'], t('nameMustNotBeEmpty'));
|
state.setIn(['name', 'error'], t('nameMustNotBeEmpty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const typeKey = state.getIn(['type', 'value']);
|
|
||||||
if (!typeKey) {
|
|
||||||
state.setIn(['type', 'error'], t('typeMustBeSelected'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.getIn(['tag_language', 'value'])) {
|
|
||||||
state.setIn(['tag_language', 'error'], t('Tag language must be selected'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.getIn(['fromExistingEntity', 'value']) && !state.getIn(['existingEntity', 'value'])) {
|
|
||||||
state.setIn(['existingEntity', 'error'], t('sourceTemplateMustNotBeEmpty'));
|
|
||||||
} else {
|
|
||||||
state.setIn(['existingEntity', 'error'], null);
|
|
||||||
}
|
|
||||||
|
|
||||||
validateNamespace(t, state);
|
validateNamespace(t, state);
|
||||||
|
|
||||||
if (typeKey) {
|
const fromExistingEntity = state.getIn(['fromExistingEntity', 'value']);
|
||||||
this.templateTypes[typeKey].validate(state);
|
|
||||||
|
if (fromExistingEntity) {
|
||||||
|
if (!state.getIn(['existingEntity', 'value'])) {
|
||||||
|
state.setIn(['existingEntity', 'error'], t('sourceTemplateMustNotBeEmpty'));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const typeKey = state.getIn(['type', 'value']);
|
||||||
|
if (!typeKey) {
|
||||||
|
state.setIn(['type', 'error'], t('typeMustBeSelected'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!state.getIn(['tag_language', 'value'])) {
|
||||||
|
state.setIn(['tag_language', 'error'], t('Tag language must be selected'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeKey) {
|
||||||
|
this.templateTypes[typeKey].validate(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,6 +293,8 @@ class MessageSender {
|
||||||
let subscriptionGrouped, list; // May be undefined
|
let subscriptionGrouped, list; // May be undefined
|
||||||
const campaign = this.campaign; // May be undefined
|
const campaign = this.campaign; // May be undefined
|
||||||
|
|
||||||
|
const sendConfiguration = this.sendConfiguration;
|
||||||
|
|
||||||
let mergeTags = subData.mergeTags;
|
let mergeTags = subData.mergeTags;
|
||||||
|
|
||||||
if (subData.listId) {
|
if (subData.listId) {
|
||||||
|
@ -389,7 +391,6 @@ class MessageSender {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendConfiguration = this.sendConfiguration;
|
|
||||||
const mailer = await mailers.getOrCreateMailer(sendConfiguration.id);
|
const mailer = await mailers.getOrCreateMailer(sendConfiguration.id);
|
||||||
|
|
||||||
await mailer.throttleWait();
|
await mailer.throttleWait();
|
||||||
|
|
|
@ -529,7 +529,6 @@ async function _createTx(tx, context, entity, content) {
|
||||||
|
|
||||||
if (copyFilesFrom) {
|
if (copyFilesFrom) {
|
||||||
await files.copyAllTx(tx, context, copyFilesFrom.entityType, 'file', copyFilesFrom.entityId, 'campaign', 'file', id);
|
await files.copyAllTx(tx, context, copyFilesFrom.entityType, 'file', copyFilesFrom.entityId, 'campaign', 'file', id);
|
||||||
|
|
||||||
convertFileURLs(data.sourceCustom, copyFilesFrom.entityType, copyFilesFrom.entityId, 'campaign', id);
|
convertFileURLs(data.sourceCustom, copyFilesFrom.entityType, copyFilesFrom.entityId, 'campaign', id);
|
||||||
await tx('campaigns')
|
await tx('campaigns')
|
||||||
.update({
|
.update({
|
||||||
|
|
|
@ -67,8 +67,6 @@ async function _validateAndPreprocess(tx, entity) {
|
||||||
enforce(allTagLanguages.includes(entity.tag_language), `Invalid tag language '${entity.tag_language}'`);
|
enforce(allTagLanguages.includes(entity.tag_language), `Invalid tag language '${entity.tag_language}'`);
|
||||||
|
|
||||||
// We don't check contents of the "data" because it is processed solely on the client. The client generates the HTML code we use when sending out campaigns.
|
// We don't check contents of the "data" because it is processed solely on the client. The client generates the HTML code we use when sending out campaigns.
|
||||||
|
|
||||||
entity.data = JSON.stringify(entity.data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function create(context, entity) {
|
async function create(context, entity) {
|
||||||
|
@ -87,7 +85,13 @@ async function create(context, entity) {
|
||||||
|
|
||||||
await _validateAndPreprocess(tx, entity);
|
await _validateAndPreprocess(tx, entity);
|
||||||
|
|
||||||
const ids = await tx('templates').insert(filterObject(entity, allowedKeys));
|
const filteredEntityWithUnstringifiedData = filterObject(entity, allowedKeys);
|
||||||
|
const filteredEntity = {
|
||||||
|
...filteredEntityWithUnstringifiedData,
|
||||||
|
data: JSON.stringify(filteredEntityWithUnstringifiedData.data)
|
||||||
|
};
|
||||||
|
|
||||||
|
const ids = await tx('templates').insert(filteredEntity);
|
||||||
const id = ids[0];
|
const id = ids[0];
|
||||||
|
|
||||||
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'template', entityId: id });
|
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'template', entityId: id });
|
||||||
|
@ -95,8 +99,14 @@ async function create(context, entity) {
|
||||||
if (entity.fromExistingEntity) {
|
if (entity.fromExistingEntity) {
|
||||||
await files.copyAllTx(tx, context, 'template', 'file', entity.existingEntity, 'template', 'file', id);
|
await files.copyAllTx(tx, context, 'template', 'file', entity.existingEntity, 'template', 'file', id);
|
||||||
|
|
||||||
convertFileURLs(entity, 'template', entity.existingEntity, 'template', id);
|
convertFileURLs(filteredEntityWithUnstringifiedData, 'template', entity.existingEntity, 'template', id);
|
||||||
await tx('templates').update(filterObject(entity, allowedKeys)).where('id', id);
|
|
||||||
|
const filteredEntity = {
|
||||||
|
...filteredEntityWithUnstringifiedData,
|
||||||
|
data: JSON.stringify(filteredEntityWithUnstringifiedData.data)
|
||||||
|
};
|
||||||
|
|
||||||
|
await tx('templates').update(filteredEntity).where('id', id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
@ -120,10 +130,13 @@ async function updateWithConsistencyCheck(context, entity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
await _validateAndPreprocess(tx, entity);
|
await _validateAndPreprocess(tx, entity);
|
||||||
|
entity.data = JSON.stringify(entity.data);
|
||||||
|
|
||||||
await namespaceHelpers.validateMove(context, entity, existing, 'template', 'createTemplate', 'delete');
|
await namespaceHelpers.validateMove(context, entity, existing, 'template', 'createTemplate', 'delete');
|
||||||
|
|
||||||
await tx('templates').where('id', entity.id).update(filterObject(entity, allowedKeys));
|
const filteredEntity = filterObject(entity, allowedKeys);
|
||||||
|
|
||||||
|
await tx('templates').where('id', entity.id).update(filteredEntity);
|
||||||
|
|
||||||
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'template', entityId: entity.id });
|
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'template', entityId: entity.id });
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue