Work in progress on confirmation dialogs displayed when one navigates from a page with unsaved changes.

Optimized imports.
This commit is contained in:
Tomas Bures 2019-05-12 00:00:09 +02:00
parent 3921a6b2cb
commit 008fd21b51
30 changed files with 324 additions and 231 deletions

View file

@ -37,8 +37,6 @@ export default class Account extends Component {
this.state = {}; this.state = {};
this.initForm({ this.initForm({
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator,
serverValidation: { serverValidation: {
url: 'rest/account-validate', url: 'rest/account-validate',
changed: ['email', 'currentPassword'] changed: ['email', 'currentPassword']

View file

@ -28,6 +28,7 @@ export default class List extends Component {
tableRestActionDialogInit(this); tableRestActionDialogInit(this);
this.initForm({ this.initForm({
leaveConfirmation: false,
serverValidation: { serverValidation: {
url: 'rest/blacklist-validate', url: 'rest/blacklist-validate',
changed: ['email'] changed: ['email']

View file

@ -92,8 +92,6 @@ export default class CUD extends Component {
this.nextListEntryId = 0; this.nextListEntryId = 0;
this.initForm({ this.initForm({
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator,
onChange: { onChange: {
send_configuration: ::this.onSendConfigurationChanged send_configuration: ::this.onSendConfigurationChanged
}, },

View file

@ -55,8 +55,6 @@ export default class CustomContent extends Component {
}; };
this.initForm({ this.initForm({
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator,
getPreSubmitUpdater: ::this.getPreSubmitFormValuesUpdater, getPreSubmitUpdater: ::this.getPreSubmitFormValuesUpdater,
}); });

View file

@ -28,7 +28,9 @@ import {withComponentMixins} from "../lib/decorator-helpers";
class TestUser extends Component { class TestUser extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
static propTypes = { static propTypes = {
@ -94,7 +96,9 @@ class TestUser extends Component {
class SendControls extends Component { class SendControls extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
static propTypes = { static propTypes = {

View file

@ -26,7 +26,9 @@ export class TestSendModalDialog extends Component {
this.mailerTypes = getMailerTypes(props.t); this.mailerTypes = getMailerTypes(props.t);
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
static propTypes = { static propTypes = {

View file

@ -10,6 +10,7 @@ import {
ButtonRow, ButtonRow,
CheckBox, CheckBox,
Dropdown, Dropdown,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
@ -42,7 +43,6 @@ export default class CUD extends Component {
this.campaignTypeLabels = getCampaignLabels(props.t); this.campaignTypeLabels = getCampaignLabels(props.t);
const {entityLabels, eventLabels} = getTriggerTypes(props.t); const {entityLabels, eventLabels} = getTriggerTypes(props.t);
this.entityLabels = entityLabels;
this.entityOptions = [ this.entityOptions = [
{key: Entity.SUBSCRIPTION, label: entityLabels[Entity.SUBSCRIPTION]}, {key: Entity.SUBSCRIPTION, label: entityLabels[Entity.SUBSCRIPTION]},
@ -92,6 +92,10 @@ export default class CUD extends Component {
} }
} }
submitFormValuesMutator(data) {
return filterData(data, ['name', 'description', 'entity', 'event', 'seconds', 'enabled', 'source_campaign']);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator); this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator);

View file

@ -1096,7 +1096,7 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
data.originalHash = data.hash; data.originalHash = data.hash;
delete data.hash; delete data.hash;
const mutator = settings.loadMutator; const mutator = this.getFormValuesMutator;
if (mutator) { if (mutator) {
mutator(data); mutator(data);
} }
@ -1123,7 +1123,7 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
data.originalHash = data.hash; data.originalHash = data.hash;
delete data.hash; delete data.hash;
const mutator = settings.loadMutator; const mutator = this.getFormValuesMutator;
if (mutator) { if (mutator) {
const newData = mutator(data); const newData = mutator(data);
@ -1154,7 +1154,7 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
let data = this.getFormValues(); let data = this.getFormValues();
const mutator = settings.submitMutator; const mutator = this.submitFormValuesMutator;
if (mutator) { if (mutator) {
const newData = mutator(data); const newData = mutator(data);
if (newData !== undefined) { if (newData !== undefined) {
@ -1321,8 +1321,8 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
const settings = self.state.formSettings; const settings = self.state.formSettings;
const mutateData = data => { const mutateData = data => {
if (settings.submitMutator) { if (self.submitFormValuesMutator) {
const newData = settings.submitMutator(data); const newData = self.submitFormValuesMutator(data);
if (newData !== undefined) { if (newData !== undefined) {
data = newData; data = newData;
} }

View file

@ -42,10 +42,7 @@ export default class CUD extends Component {
this.state = {}; this.state = {};
this.initForm({ this.initForm();
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator
});
this.mailerTypes = getMailerTypes(props.t); this.mailerTypes = getMailerTypes(props.t);
} }

View file

@ -12,12 +12,14 @@ import {
CheckBox, CheckBox,
Dropdown, Dropdown,
Fieldset, Fieldset,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
StaticField, StaticField,
TableSelect, TableSelect,
withForm withForm,
withFormErrorHandlers
} from '../../lib/form'; } from '../../lib/form';
import {withErrorHandling} from '../../lib/error-handling'; import {withErrorHandling} from '../../lib/error-handling';
import {DeleteModalDialog} from "../../lib/modals"; import {DeleteModalDialog} from "../../lib/modals";
@ -117,9 +119,58 @@ export default class CUD extends Component {
data.orderManageBefore = data.orderManageBefore.toString(); data.orderManageBefore = data.orderManageBefore.toString();
} }
submitFormValuesMutator(data) {
if (data.default_value.trim() === '') {
data.default_value = null;
}
if (!data.isInGroup) {
data.group = null;
}
data.settings = {};
switch (data.type) {
case 'checkbox-grouped':
case 'radio-grouped':
case 'dropdown-grouped':
case 'json':
data.settings.renderTemplate = data.renderTemplate;
break;
case 'radio-enum':
case 'dropdown-enum':
data.settings.options = this.parseEnumOptions(data.enumOptions).options;
data.settings.renderTemplate = data.renderTemplate;
break;
case 'date':
case 'birthday':
data.settings.dateFormat = data.dateFormat;
break;
case 'option':
if (!data.isInGroup) {
data.settings.checkedLabel = data.checkedLabel;
data.settings.uncheckedLabel = data.uncheckedLabel;
}
break;
}
if (data.group !== null) {
data.orderListBefore = data.orderSubscribeBefore = data.orderManageBefore = 'none';
} else {
data.orderListBefore = Number.parseInt(data.orderListBefore) || data.orderListBefore;
data.orderSubscribeBefore = Number.parseInt(data.orderSubscribeBefore) || data.orderSubscribeBefore;
data.orderManageBefore = Number.parseInt(data.orderManageBefore) || data.orderManageBefore;
}
return filterData(data, ['name', 'key', 'default_value', 'type', 'group', 'settings',
'orderListBefore', 'orderSubscribeBefore', 'orderManageBefore']);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator); this.getFormValuesFromEntity(this.props.entity);
} else { } else {
this.populateFormValues({ this.populateFormValues({
@ -237,6 +288,7 @@ export default class CUD extends Component {
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;
@ -253,65 +305,14 @@ export default class CUD extends Component {
this.disableForm(); this.disableForm();
this.setFormStatusMessage('info', t('saving')); this.setFormStatusMessage('info', t('saving'));
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url, data => { const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url);
if (data.default_value.trim() === '') {
data.default_value = null;
}
if (!data.isInGroup) {
data.group = null;
}
data.settings = {};
switch (data.type) {
case 'checkbox-grouped':
case 'radio-grouped':
case 'dropdown-grouped':
case 'json':
data.settings.renderTemplate = data.renderTemplate;
break;
case 'radio-enum':
case 'dropdown-enum':
data.settings.options = this.parseEnumOptions(data.enumOptions).options;
data.settings.renderTemplate = data.renderTemplate;
break;
case 'date':
case 'birthday':
data.settings.dateFormat = data.dateFormat;
break;
case 'option':
if (!data.isInGroup) {
data.settings.checkedLabel = data.checkedLabel;
data.settings.uncheckedLabel = data.uncheckedLabel;
}
break;
}
delete data.renderTemplate;
delete data.enumOptions;
delete data.dateFormat;
delete data.checkedLabel;
delete data.uncheckedLabel;
delete data.isInGroup;
if (data.group !== null) {
data.orderListBefore = data.orderSubscribeBefore = data.orderManageBefore = 'none';
} else {
data.orderListBefore = Number.parseInt(data.orderListBefore) || data.orderListBefore;
data.orderSubscribeBefore = Number.parseInt(data.orderSubscribeBefore) || data.orderSubscribeBefore;
data.orderManageBefore = Number.parseInt(data.orderManageBefore) || data.orderManageBefore;
}
});
if (submitResult) { if (submitResult) {
if (this.props.entity) { if (this.props.entity) {
if (submitAndLeave) { if (submitAndLeave) {
this.navigateToWithFlashMessage(`/lists/${this.props.list.id}/fields`, 'success', t('Field updated')); this.navigateToWithFlashMessage(`/lists/${this.props.list.id}/fields`, 'success', t('Field updated'));
} else { } else {
await this.getFormValuesFromURL(`rest/fields/${this.props.list.id}/${this.props.entity.id}`, ::this.getFormValuesMutator); await this.getFormValuesFromURL(`rest/fields/${this.props.list.id}/${this.props.entity.id}`);
this.enableForm(); this.enableForm();
this.setFormStatusMessage('success', t('Field updated')); this.setFormStatusMessage('success', t('Field updated'));
} }

View file

@ -12,12 +12,14 @@ import {
ButtonRow, ButtonRow,
Dropdown, Dropdown,
Fieldset, Fieldset,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
TableSelect, TableSelect,
TextArea, TextArea,
withForm withForm,
withFormErrorHandlers
} from '../../lib/form'; } from '../../lib/form';
import {withErrorHandling} from '../../lib/error-handling'; import {withErrorHandling} from '../../lib/error-handling';
import {NamespaceSelect, validateNamespace} from '../../lib/namespace'; import {NamespaceSelect, validateNamespace} from '../../lib/namespace';
@ -293,14 +295,38 @@ export default class CUD extends Component {
getFormValuesMutator(data) { getFormValuesMutator(data) {
this.supplyDefaults(data); this.supplyDefaults(data);
data.selectedTemplate = data.selectedTemplate || 'layout';
}
submitFormValuesMutator(data) {
return filterData(data, ['name', 'description', 'layout', 'form_input_style', 'namespace',
'web_subscribe',
'web_confirm_subscription_notice',
'mail_confirm_subscription_html',
'mail_confirm_subscription_text',
'mail_already_subscribed_html',
'mail_already_subscribed_text',
'web_subscribed_notice',
'mail_subscription_confirmed_html',
'mail_subscription_confirmed_text',
'web_manage',
'web_manage_address',
'web_updated_notice',
'web_unsubscribe',
'web_confirm_unsubscription_notice',
'mail_confirm_unsubscription_html',
'mail_confirm_unsubscription_text',
'mail_confirm_address_change_html',
'mail_confirm_address_change_text',
'web_unsubscribed_notice',
'mail_unsubscription_confirmed_html',
'mail_unsubscription_confirmed_text', 'web_manual_unsubscribe_notice', 'web_privacy_policy_notice'
]);
} }
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, data => { this.getFormValuesFromEntity(this.props.entity);
this.getFormValuesMutator(data);
data.selectedTemplate = 'layout';
});
} else { } else {
const data = { const data = {
@ -355,6 +381,7 @@ export default class CUD extends Component {
} }
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;
@ -370,17 +397,14 @@ export default class CUD extends Component {
this.disableForm(); this.disableForm();
this.setFormStatusMessage('info', t('saving')); this.setFormStatusMessage('info', t('saving'));
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url, data => { const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url);
delete data.selectedTemplate;
delete data.previewList;
});
if (submitResult) { if (submitResult) {
if (this.props.entity) { if (this.props.entity) {
if (submitAndLeave) { if (submitAndLeave) {
this.navigateToWithFlashMessage('/lists/forms', 'success', t('Custom forms updated')); this.navigateToWithFlashMessage('/lists/forms', 'success', t('Custom forms updated'));
} else { } else {
await this.getFormValuesFromURL(`rest/forms/${this.props.entity.id}`, ::this.getFormValuesMutator); await this.getFormValuesFromURL(`rest/forms/${this.props.entity.id}`);
this.enableForm(); this.enableForm();
this.setFormStatusMessage('success', t('Custom forms updated')); this.setFormStatusMessage('success', t('Custom forms updated'));
} }

View file

@ -11,12 +11,14 @@ import {
CheckBox, CheckBox,
Dropdown, Dropdown,
Fieldset, Fieldset,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
StaticField, StaticField,
TextArea, TextArea,
withForm withForm,
withFormErrorHandlers
} from '../../lib/form'; } from '../../lib/form';
import {withAsyncErrorHandler, withErrorHandling} from '../../lib/error-handling'; import {withAsyncErrorHandler, withErrorHandling} from '../../lib/error-handling';
import {DeleteModalDialog} from "../../lib/modals"; import {DeleteModalDialog} from "../../lib/modals";
@ -81,8 +83,7 @@ export default class CUD extends Component {
entity: PropTypes.object entity: PropTypes.object
} }
initFromEntity(entity) { getFormValuesMutator(data) {
this.getFormValuesFromEntity(entity, data => {
data.settings = data.settings || {}; data.settings = data.settings || {};
const mapping = data.mapping || {}; const mapping = data.mapping || {};
@ -110,7 +111,73 @@ export default class CUD extends Component {
const emailMapping = mappingFlds.email || {}; const emailMapping = mappingFlds.email || {};
data.mapping_fields_email_column = emailMapping.column || ''; data.mapping_fields_email_column = emailMapping.column || '';
}); }
submitFormValuesMutator(data) {
const isEdit = !!this.props.entity;
data.source = Number.parseInt(data.source);
data.settings = {};
const formData = new FormData();
if (!isEdit) {
if (data.source === ImportSource.CSV_FILE) {
data.settings.csv = {};
formData.append('csvFile', this.csvFile.files[0]);
data.settings.csv.delimiter = data.csvDelimiter.trim();
}
} else {
data.mapping_type = Number.parseInt(data.mapping_type);
const mapping = {
fields: {},
settings: {}
};
if (data.mapping_type === MappingType.BASIC_SUBSCRIBE) {
mapping.settings.checkEmails = data.mapping_settings_checkEmails;
for (const field of this.props.fieldsGrouped) {
if (field.column) {
const colMapping = data['mapping_fields_' + field.column + '_column'];
if (colMapping) {
mapping.fields[field.column] = {
column: colMapping
};
}
} else {
for (const option of field.settings.options) {
const col = field.groupedOptions[option.key].column;
const colMapping = data['mapping_fields_' + col + '_column'];
if (colMapping) {
mapping.fields[col] = {
column: colMapping
};
}
}
}
}
}
if (data.mapping_type === MappingType.BASIC_SUBSCRIBE || data.mapping_type === MappingType.BASIC_UNSUBSCRIBE) {
mapping.fields.email = {
column: data.mapping_fields_email_column
};
}
data.mapping = mapping;
}
formData.append('entity', JSON.stringify(
filterData(data, ['name', 'description', 'source', 'settings', 'mapping_type', 'mapping'])
));
return formData;
}
initFromEntity(entity) {
this.getFormValuesFromEntity(entity);
if (inProgress(entity.status)) { if (inProgress(entity.status)) {
this.refreshTimeoutId = setTimeout(this.refreshTimeoutHandler, 1000); this.refreshTimeoutId = setTimeout(this.refreshTimeoutHandler, 1000);
@ -179,6 +246,7 @@ export default class CUD extends Component {
await this.save(); await this.save();
} }
@withFormErrorHandlers
async save(runAfterSave) { async save(runAfterSave) {
const t = this.props.t; const t = this.props.t;
const isEdit = !!this.props.entity; const isEdit = !!this.props.entity;
@ -197,74 +265,7 @@ export default class CUD extends Component {
this.disableForm(); this.disableForm();
this.setFormStatusMessage('info', t('saving')); this.setFormStatusMessage('info', t('saving'));
const submitResponse = await this.validateAndSendFormValuesToURL(sendMethod, url, data => { const submitResponse = await this.validateAndSendFormValuesToURL(sendMethod, url);
data.source = Number.parseInt(data.source);
data.settings = {};
const formData = new FormData();
if (!isEdit) {
if (data.source === ImportSource.CSV_FILE) {
data.settings.csv = {};
formData.append('csvFile', this.csvFile.files[0]);
data.settings.csv.delimiter = data.csvDelimiter.trim();
}
} else {
data.mapping_type = Number.parseInt(data.mapping_type);
const mapping = {
fields: {},
settings: {}
};
if (data.mapping_type === MappingType.BASIC_SUBSCRIBE) {
mapping.settings.checkEmails = data.mapping_settings_checkEmails;
for (const field of this.props.fieldsGrouped) {
if (field.column) {
const colMapping = data['mapping_fields_' + field.column + '_column'];
if (colMapping) {
mapping.fields[field.column] = {
column: colMapping
};
}
} else {
for (const option of field.settings.options) {
const col = field.groupedOptions[option.key].column;
const colMapping = data['mapping_fields_' + col + '_column'];
if (colMapping) {
mapping.fields[col] = {
column: colMapping
};
}
}
}
}
}
if (data.mapping_type === MappingType.BASIC_SUBSCRIBE || data.mapping_type === MappingType.BASIC_UNSUBSCRIBE) {
mapping.fields.email = {
column: data.mapping_fields_email_column
};
}
data.mapping = mapping;
}
for (const key in data) {
if (key.startsWith('mapping_fields') || key.startsWith('mapping_settings')) {
delete data[key];
}
}
delete data.csvFile;
delete data.csvDelimiter;
delete data.sampleRow;
formData.append('entity', JSON.stringify(data));
return formData;
});
if (submitResponse) { if (submitResponse) {
if (!isEdit) { if (!isEdit) {

View file

@ -4,7 +4,16 @@ import React, {Component} from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import {withTranslation} from '../../lib/i18n'; import {withTranslation} from '../../lib/i18n';
import {LinkButton, requiresAuthenticatedUser, Title, Toolbar, withPageHelpers} from "../../lib/page"; import {LinkButton, requiresAuthenticatedUser, Title, Toolbar, withPageHelpers} from "../../lib/page";
import {ButtonRow, Dropdown, Form, FormSendMethod, InputField, withForm} from "../../lib/form"; import {
ButtonRow,
Dropdown,
filterData,
Form,
FormSendMethod,
InputField,
withForm,
withFormErrorHandlers
} from "../../lib/form";
import {withErrorHandling} from "../../lib/error-handling"; import {withErrorHandling} from "../../lib/error-handling";
import {DeleteModalDialog} from "../../lib/modals"; import {DeleteModalDialog} from "../../lib/modals";
@ -104,9 +113,14 @@ export default class CUD extends Component {
}); });
} }
submitFormValuesMutator(data) {
data.settings.rootRule.type = data.rootRuleType;
return filterData(data, ['name', 'settings']);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator); this.getFormValuesFromEntity(this.props.entity);
} else { } else {
this.populateFormValues({ this.populateFormValues({
@ -137,6 +151,7 @@ export default class CUD extends Component {
} }
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;
@ -153,21 +168,14 @@ export default class CUD extends Component {
this.disableForm(); this.disableForm();
this.setFormStatusMessage('info', t('saving')); this.setFormStatusMessage('info', t('saving'));
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url, data => { const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url);
const keep = ['name', 'settings', 'originalHash'];
data.settings.rootRule.type = data.rootRuleType;
delete data.rootRuleType;
delete data.selectedRule;
});
if (submitResult) { if (submitResult) {
if (this.props.entity) { if (this.props.entity) {
if (submitAndLeave) { if (submitAndLeave) {
this.navigateToWithFlashMessage(`/lists/${this.props.list.id}/segments`, 'success', t('Segment updated')); this.navigateToWithFlashMessage(`/lists/${this.props.list.id}/segments`, 'success', t('Segment updated'));
} else { } else {
await this.getFormValuesFromURL(`rest/segments/${this.props.list.id}/${this.props.entity.id}`, ::this.getFormValuesMutator); await this.getFormValuesFromURL(`rest/segments/${this.props.list.id}/${this.props.entity.id}`);
this.enableForm(); this.enableForm();
this.setFormStatusMessage('success', t('Segment updated')); this.setFormStatusMessage('success', t('Segment updated'));

View file

@ -30,6 +30,7 @@ export default class RuleSettingsPane extends PureComponent {
this.state = {}; this.state = {};
this.initForm({ this.initForm({
leaveConfirmation: false,
onChangeBeforeValidation: ::this.populateRuleDefaults, onChangeBeforeValidation: ::this.populateRuleDefaults,
onChange: ::this.onFormChange onChange: ::this.onFormChange
}); });

View file

@ -11,15 +11,17 @@ import {
ButtonRow, ButtonRow,
CheckBox, CheckBox,
Dropdown, Dropdown,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
withForm withForm,
withFormErrorHandlers
} from '../../lib/form'; } from '../../lib/form';
import {withErrorHandling} from '../../lib/error-handling'; import {withErrorHandling} from '../../lib/error-handling';
import {RestActionModalDialog} from "../../lib/modals"; import {RestActionModalDialog} from "../../lib/modals";
import interoperableErrors from '../../../../shared/interoperable-errors'; import interoperableErrors from '../../../../shared/interoperable-errors';
import {SubscriptionStatus} from '../../../../shared/lists'; import {getFieldColumn, SubscriptionStatus} from '../../../../shared/lists';
import {getFieldTypes, getSubscriptionStatusLabels} from './helpers'; import {getFieldTypes, getSubscriptionStatusLabels} from './helpers';
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import {withComponentMixins} from "../../lib/decorator-helpers"; import {withComponentMixins} from "../../lib/decorator-helpers";
@ -67,9 +69,23 @@ export default class CUD extends Component {
} }
} }
submitFormValuesMutator(data) {
data.status = parseInt(data.status);
data.tz = data.tz || null;
const allowedCols = ['email', 'tz', 'is_test', 'status'];
for (const fld of this.props.fieldsGrouped) {
this.fieldTypes[fld.type].assignEntity(fld, data);
allowedCols.push(getFieldColumn(fld));
}
return filterData(data, allowedCols);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator); this.getFormValuesFromEntity(this.props.entity);
} else { } else {
const data = { const data = {
@ -106,6 +122,7 @@ export default class CUD extends Component {
} }
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;
@ -122,21 +139,14 @@ export default class CUD extends Component {
this.disableForm(); this.disableForm();
this.setFormStatusMessage('info', t('saving')); this.setFormStatusMessage('info', t('saving'));
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url, data => { const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url);
data.status = parseInt(data.status);
data.tz = data.tz || null;
for (const fld of this.props.fieldsGrouped) {
this.fieldTypes[fld.type].assignEntity(fld, data);
}
});
if (submitResult) { if (submitResult) {
if (this.props.entity) { if (this.props.entity) {
if (submitAndLeave) { if (submitAndLeave) {
this.navigateToWithFlashMessage(`/lists/${this.props.list.id}/subscriptions`, 'success', t('Subscription updated')); this.navigateToWithFlashMessage(`/lists/${this.props.list.id}/subscriptions`, 'success', t('Subscription updated'));
} else { } else {
await this.getFormValuesFromURL(`rest/subscriptions/${this.props.list.id}/${this.props.entity.id}`, ::this.getFormValuesMutator); await this.getFormValuesFromURL(`rest/subscriptions/${this.props.list.id}/${this.props.entity.id}`);
this.enableForm(); this.enableForm();
this.setFormStatusMessage('success', t('Subscription updated')); this.setFormStatusMessage('success', t('Subscription updated'));
} }

View file

@ -42,6 +42,7 @@ export default class List extends Component {
this.fieldTypes = getFieldTypes(t); this.fieldTypes = getFieldTypes(t);
this.initForm({ this.initForm({
leaveConfirmation: false,
onChange: { onChange: {
segment: (newState, key, oldValue, value) => { segment: (newState, key, oldValue, value) => {
this.navigateTo(`/lists/${this.props.list.id}/subscriptions` + (value ? '?segment=' + value : '')); this.navigateTo(`/lists/${this.props.list.id}/subscriptions` + (value ? '?segment=' + value : ''));

View file

@ -19,7 +19,9 @@ export default class Forget extends Component {
this.state = {}; this.state = {};
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
componentDidMount() { componentDidMount() {

View file

@ -33,7 +33,9 @@ export default class Login extends Component {
this.state = {}; this.state = {};
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
componentDidMount() { componentDidMount() {

View file

@ -34,7 +34,9 @@ export default class Account extends Component {
resetTokenValidationState: ResetTokenValidationState.PENDING resetTokenValidationState: ResetTokenValidationState.PENDING
}; };
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
@withAsyncErrorHandler @withAsyncErrorHandler

View file

@ -4,7 +4,18 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {withTranslation} from '../lib/i18n'; import {withTranslation} from '../lib/i18n';
import {LinkButton, requiresAuthenticatedUser, Title, withPageHelpers} from '../lib/page'; import {LinkButton, requiresAuthenticatedUser, Title, withPageHelpers} from '../lib/page';
import {Button, ButtonRow, Form, FormSendMethod, InputField, TextArea, TreeTableSelect, withForm} from '../lib/form'; import {
Button,
ButtonRow,
filterData,
Form,
FormSendMethod,
InputField,
TextArea,
TreeTableSelect,
withForm,
withFormErrorHandlers
} from '../lib/form';
import axios from '../lib/axios'; import axios from '../lib/axios';
import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling'; import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling';
import interoperableErrors from '../../../shared/interoperable-errors'; import interoperableErrors from '../../../shared/interoperable-errors';
@ -35,6 +46,10 @@ export default class CUD extends Component {
entity: PropTypes.object entity: PropTypes.object
} }
submitFormValuesMutator(data) {
return filterData(data, ['name', 'description', 'namespace']);
}
isEditGlobal() { isEditGlobal() {
return this.props.entity && this.props.entity.id === getGlobalNamespaceId(); return this.props.entity && this.props.entity.id === getGlobalNamespaceId();
} }
@ -106,6 +121,7 @@ export default class CUD extends Component {
} }
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;

View file

@ -8,13 +8,15 @@ import {
Button, Button,
ButtonRow, ButtonRow,
Fieldset, Fieldset,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
TableSelect, TableSelect,
TableSelectMode, TableSelectMode,
TextArea, TextArea,
withForm withForm,
withFormErrorHandlers
} from '../lib/form'; } from '../lib/form';
import axios from '../lib/axios'; import axios from '../lib/axios';
import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling'; import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling';
@ -73,9 +75,22 @@ export default class CUD extends Component {
} }
} }
submitFormValuesMutator(data) {
const params = {};
for (const spec of data.user_fields) {
const fldId = `param_${spec.id}`;
params[spec.id] = data[fldId];
}
data.params = params;
return filterData(data, ['name', 'description', 'report_template', 'params', 'namespace']);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator); this.getFormValuesFromEntity(this.props.entity);
} else { } else {
this.populateFormValues({ this.populateFormValues({
@ -133,6 +148,7 @@ export default class CUD extends Component {
validateNamespace(t, state); validateNamespace(t, state);
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;
@ -153,25 +169,14 @@ export default class CUD extends Component {
this.disableForm(); this.disableForm();
this.setFormStatusMessage('info', t('saving')); this.setFormStatusMessage('info', t('saving'));
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url, data => { const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url);
const params = {};
for (const spec of data.user_fields) {
const fldId = `param_${spec.id}`;
params[spec.id] = data[fldId];
delete data[fldId];
}
delete data.user_fields;
data.params = params;
});
if (submitResult) { if (submitResult) {
if (this.props.entity) { if (this.props.entity) {
if (submitAndLeave) { if (submitAndLeave) {
this.navigateToWithFlashMessage('/reports', 'success', t('Report updated')); this.navigateToWithFlashMessage('/reports', 'success', t('Report updated'));
} else { } else {
await this.getFormValuesFromURL(`rest/reports/${this.props.entity.id}`, ::this.getFormValuesMutator); await this.getFormValuesFromURL(`rest/reports/${this.props.entity.id}`);
this.enableForm(); this.enableForm();
this.setFormStatusMessage('success', t('Report updated')); this.setFormStatusMessage('success', t('Report updated'));
} }

View file

@ -10,11 +10,13 @@ import {
Button, Button,
ButtonRow, ButtonRow,
Dropdown, Dropdown,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
TextArea, TextArea,
withForm withForm,
withFormErrorHandlers
} from '../../lib/form'; } from '../../lib/form';
import {withErrorHandling} from '../../lib/error-handling'; import {withErrorHandling} from '../../lib/error-handling';
import {NamespaceSelect, validateNamespace} from '../../lib/namespace'; import {NamespaceSelect, validateNamespace} from '../../lib/namespace';
@ -47,6 +49,10 @@ export default class CUD extends Component {
entity: PropTypes.object entity: PropTypes.object
} }
submitFormValuesMutator(data) {
return filterData(data, ['name', 'description', 'mime_type', 'user_fields', 'js', 'hbs', 'namespace']);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity); this.getFormValuesFromEntity(this.props.entity);
@ -246,6 +252,7 @@ export default class CUD extends Component {
validateNamespace(t, state); validateNamespace(t, state);
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;

View file

@ -10,12 +10,14 @@ import {
ButtonRow, ButtonRow,
CheckBox, CheckBox,
Fieldset, Fieldset,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
StaticField, StaticField,
TextArea, TextArea,
withForm withForm,
withFormErrorHandlers
} from '../lib/form'; } from '../lib/form';
import {withErrorHandling} from '../lib/error-handling'; import {withErrorHandling} from '../lib/error-handling';
import {NamespaceSelect, validateNamespace} from '../lib/namespace'; import {NamespaceSelect, validateNamespace} from '../lib/namespace';
@ -75,9 +77,15 @@ export default class CUD extends Component {
data.verp_disable_sender_header = data.verpEnabled ? !!data.verp_disable_sender_header : false; data.verp_disable_sender_header = data.verpEnabled ? !!data.verp_disable_sender_header : false;
} }
submitFormValuesMutator(data) {
return filterData(data, ['name', 'description', 'from_email', 'from_email_overridable', 'from_name',
'from_name_overridable', 'reply_to', 'reply_to_overridable', 'subject', 'subject_overridable', 'x_mailer',
'verp_hostname', 'verp_disable_sender_header', 'mailer_type', 'mailer_settings', 'namespace']);
}
componentDidMount() { componentDidMount() {
if (this.props.entity) { if (this.props.entity) {
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator); this.getFormValuesFromEntity(this.props.entity);
} else { } else {
this.populateFormValues({ this.populateFormValues({
name: '', name: '',
@ -131,6 +139,7 @@ export default class CUD extends Component {
} }
} }
@withFormErrorHandlers
async submitHandler(submitAndLeave) { async submitHandler(submitAndLeave) {
const t = this.props.t; const t = this.props.t;
@ -159,7 +168,7 @@ export default class CUD extends Component {
if (submitAndLeave) { if (submitAndLeave) {
this.navigateToWithFlashMessage('/send-configurations', 'success', t('Send configuration updated')); this.navigateToWithFlashMessage('/send-configurations', 'success', t('Send configuration updated'));
} else { } else {
await this.getFormValuesFromURL(`rest/send-configurations-private/${this.props.entity.id}`, ::this.getFormValuesMutator); await this.getFormValuesFromURL(`rest/send-configurations-private/${this.props.entity.id}`);
this.enableForm(); this.enableForm();
this.setFormStatusMessage('success', t('Send configuration updated')); this.setFormStatusMessage('success', t('Send configuration updated'));
} }

View file

@ -9,6 +9,7 @@ import {
Button, Button,
ButtonRow, ButtonRow,
Fieldset, Fieldset,
filterData,
Form, Form,
FormSendMethod, FormSendMethod,
InputField, InputField,
@ -39,6 +40,10 @@ export default class Update extends Component {
entity: PropTypes.object entity: PropTypes.object
} }
submitFormValuesMutator(data) {
return filterData(data, ['adminEmail', 'uaCode', 'mapsApiKey', 'shoutout', 'pgpPassphrase', 'pgpPrivateKey', 'defaultHomepage']);
}
componentDidMount() { componentDidMount() {
this.getFormValuesFromEntity(this.props.entity); this.getFormValuesFromEntity(this.props.entity);
} }

View file

@ -23,7 +23,9 @@ export default class Share extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
static propTypes = { static propTypes = {

View file

@ -55,8 +55,6 @@ export default class CUD extends Component {
}; };
this.initForm({ this.initForm({
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator,
getPreSubmitUpdater: ::this.getPreSubmitFormValuesUpdater, getPreSubmitUpdater: ::this.getPreSubmitFormValuesUpdater,
onChangeBeforeValidation: { onChangeBeforeValidation: {
type: ::this.onTypeChanged type: ::this.onTypeChanged

View file

@ -27,7 +27,9 @@ export class TestSendModalDialog extends Component {
this.mailerTypes = getMailerTypes(props.t); this.mailerTypes = getMailerTypes(props.t);
this.initForm(); this.initForm({
leaveConfirmation: false
});
} }
static propTypes = { static propTypes = {

View file

@ -49,10 +49,7 @@ export default class CUD extends Component {
this.state = {}; this.state = {};
this.initForm({ this.initForm();
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator
});
} }
static propTypes = { static propTypes = {

View file

@ -39,8 +39,6 @@ export default class CUD extends Component {
this.state = {}; this.state = {};
this.initForm({ this.initForm({
loadMutator: ::this.getFormValuesMutator,
submitMutator: ::this.submitFormValuesMutator,
serverValidation: { serverValidation: {
url: 'rest/users-validate', url: 'rest/users-validate',
changed: mailtrainConfig.isAuthMethodLocal ? ['username', 'email'] : ['username'], changed: mailtrainConfig.isAuthMethodLocal ? ['username', 'email'] : ['username'],

@ -1 +1 @@
Subproject commit 885ee383bd508eb7a872afb5208259d694a7c255 Subproject commit ec89af43120f95dcf7f14dc92a2b3811bf50d7e8