Add 'Cancel' button to Campaign creation form

This commit is contained in:
David Craig 2016-04-20 16:51:00 +12:00 committed by Ingo Schommer
parent 5cc6171f77
commit 2b8ef99d5e
3 changed files with 50 additions and 10 deletions

View File

@ -295,17 +295,28 @@ export class FormBuilderComponent extends SilverStripeComponent {
return actions.map((action, i) => {
let props = deepFreeze(action);
if (typeof createFn === 'function') {
return createFn(FormActionComponent, props);
// Add sensible defaults for common actions.
switch (props.name) {
case 'action_save':
props = deepFreeze(Object.assign({}, props, {
type: 'submit',
label: props.title,
icon: 'save',
}));
break;
case 'action_cancel':
props = deepFreeze(Object.assign({}, props, {
type: 'button',
label: props.title,
icon: 'cancel',
}));
break;
default:
break;
}
// Add sensible defaults for common actions.
if (props.name === 'action_save') {
props = deepFreeze(Object.assign({}, props, {
type: 'submit',
label: props.title,
icon: 'save',
}));
if (typeof createFn === 'function') {
return createFn(FormActionComponent, props);
}
return <FormActionComponent key={i} {...props} />;

View File

@ -25,6 +25,7 @@ class CampaignAdmin extends SilverStripeComponent {
},
});
this.campaignListCreateFn = this.campaignListCreateFn.bind(this);
this.campaignCreationView = this.campaignCreationView.bind(this);
}
componentDidMount() {
@ -164,6 +165,7 @@ class CampaignAdmin extends SilverStripeComponent {
renderCreateView() {
const baseSchemaUrl = this.props.sectionConfig.forms.CreateEditForm.schemaUrl;
const formBuilderProps = {
createFn: this.campaignCreationView,
formId: 'CreateEditForm',
schemaUrl: `${baseSchemaUrl}/ChangeSet`,
};
@ -182,6 +184,32 @@ class CampaignAdmin extends SilverStripeComponent {
);
}
/**
* Hook to allow customisation of components being constructed
* by the Campaign creation FormBuilder.
*
* @param {Object} Component - Component constructor.
* @param {Object} props - Props passed from FormBuilder.
*
* @return {Object} - Instanciated React component
*/
campaignCreationView(Component, props) {
const indexRoute = this.props.sectionConfig.route;
// Route to the Campaigns index view when 'Cancel' is clicked.
if (props.name === 'action_cancel') {
const extendedProps = Object.assign({}, props, {
handleClick: () => {
window.ss.router.show(indexRoute);
},
});
return <Component key={props.name} {...extendedProps} />;
}
return <Component key={props.name} {...props} />;
}
/**
* Hook to allow customisation of components being constructed
* by the Campaign list FormBuilder.

View File

@ -486,7 +486,8 @@ JSON;
'CreateEditForm',
ChangeSet::singleton()->getCMSFields(),
FieldList::create(
FormAction::create('save', 'Save')
FormAction::create('save', 'Save'),
FormAction::create('cancel', 'Cancel')
)
);
}