Fix campaign section cancel buttons

- Cancel buttons we submitting forms.
- Nothing happened when clicking the DeatilEdit cancel button.

Now both cancel button route to the Campaign index view
This commit is contained in:
David Craig 2016-04-26 14:55:10 +12:00 committed by Ingo Schommer
parent 8af1ad09d0
commit 778ed1257d

View File

@ -25,7 +25,8 @@ class CampaignAdmin extends SilverStripeComponent {
}, },
}); });
this.campaignListCreateFn = this.campaignListCreateFn.bind(this); this.campaignListCreateFn = this.campaignListCreateFn.bind(this);
this.campaignCreationView = this.campaignCreationView.bind(this); this.campaignAddCreateFn = this.campaignAddCreateFn.bind(this);
this.campaignEditCreateFn = this.campaignEditCreateFn.bind(this);
} }
componentDidMount() { componentDidMount() {
@ -139,7 +140,10 @@ class CampaignAdmin extends SilverStripeComponent {
*/ */
renderDetailEditView() { renderDetailEditView() {
const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl; const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl;
const schemaUrl = `${baseSchemaUrl}/ChangeSet/${this.props.campaignId}`; const formBuilderProps = {
createFn: this.campaignEditCreateFn,
schemaUrl: `${baseSchemaUrl}/ChangeSet/${this.props.campaignId}`,
};
return ( return (
<div className="cms-middle no-preview"> <div className="cms-middle no-preview">
@ -149,7 +153,7 @@ class CampaignAdmin extends SilverStripeComponent {
<h2 className="text-truncate toolbar__heading">Campaigns</h2> <h2 className="text-truncate toolbar__heading">Campaigns</h2>
</div> </div>
</Toolbar> </Toolbar>
<FormBuilder schemaUrl={schemaUrl} /> <FormBuilder {...formBuilderProps} />
</div> </div>
</div> </div>
); );
@ -161,7 +165,7 @@ class CampaignAdmin extends SilverStripeComponent {
renderCreateView() { renderCreateView() {
const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl; const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl;
const formBuilderProps = { const formBuilderProps = {
createFn: this.campaignCreationView, createFn: this.campaignAddCreateFn,
schemaUrl: `${baseSchemaUrl}/ChangeSet`, schemaUrl: `${baseSchemaUrl}/ChangeSet`,
}; };
@ -181,6 +185,33 @@ class CampaignAdmin extends SilverStripeComponent {
); );
} }
/**
* Hook to allow customisation of components being constructed
* by the Campaign DetailEdit FormBuilder.
*
* @param {Object} Component - Component constructor.
* @param {Object} props - Props passed from FormBuilder.
*
* @return {Object} - Instanciated React component
*/
campaignEditCreateFn(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: (event) => {
event.preventDefault();
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 * Hook to allow customisation of components being constructed
* by the Campaign creation FormBuilder. * by the Campaign creation FormBuilder.
@ -190,13 +221,14 @@ class CampaignAdmin extends SilverStripeComponent {
* *
* @return {Object} - Instanciated React component * @return {Object} - Instanciated React component
*/ */
campaignCreationView(Component, props) { campaignAddCreateFn(Component, props) {
const indexRoute = this.props.sectionConfig.route; const indexRoute = this.props.sectionConfig.route;
// Route to the Campaigns index view when 'Cancel' is clicked. // Route to the Campaigns index view when 'Cancel' is clicked.
if (props.name === 'action_cancel') { if (props.name === 'action_cancel') {
const extendedProps = Object.assign({}, props, { const extendedProps = Object.assign({}, props, {
handleClick: () => { handleClick: (event) => {
event.preventDefault();
window.ss.router.show(indexRoute); window.ss.router.show(indexRoute);
}, },
}); });