mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Adds route for creating new Campaigns
This commit is contained in:
parent
48d01343c3
commit
ae285f3286
@ -26,6 +26,7 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
});
|
||||
this.campaignListCreateFn = this.campaignListCreateFn.bind(this);
|
||||
this.campaignEditCreateFn = this.campaignEditCreateFn.bind(this);
|
||||
this.campaignCreationCreateFn = this.campaignCreationCreateFn.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -68,6 +69,9 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
case 'edit':
|
||||
view = this.renderDetailEditView();
|
||||
break;
|
||||
case 'create':
|
||||
view = this.renderCreateView();
|
||||
break;
|
||||
default:
|
||||
view = this.renderIndexView();
|
||||
}
|
||||
@ -157,6 +161,53 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the view for creating a new Campaign.
|
||||
*/
|
||||
renderCreateView() {
|
||||
const baseSchemaUrl = this.props.sectionConfig.forms.CreateEditForm.schemaUrl;
|
||||
const formBuilderProps = {
|
||||
createFn: this.campaignCreationCreateFn,
|
||||
formId: 'CreateEditForm',
|
||||
schemaUrl: `${baseSchemaUrl}/ChangeSet`,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="cms-middle no-preview">
|
||||
<div className="cms-campaigns collapse in" aria-expanded="true">
|
||||
<NorthHeader>
|
||||
<h2 className="text-truncate north-header__heading">Campaigns</h2>
|
||||
</NorthHeader>
|
||||
<div className="cms-middle__scrollable">
|
||||
<FormBuilder {...formBuilderProps} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
campaignCreationCreateFn(Component, props) {
|
||||
if (props.name === 'action_save') {
|
||||
const extendedProps = Object.assign({}, props, {
|
||||
type: 'submit',
|
||||
label: props.title,
|
||||
icon: 'save',
|
||||
});
|
||||
|
||||
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.
|
||||
@ -254,7 +305,12 @@ class CampaignAdmin extends SilverStripeComponent {
|
||||
}
|
||||
|
||||
addCampaign() {
|
||||
// Add campaign
|
||||
const path = this.props.sectionConfig.campaignViewRoute
|
||||
.replace(/:type\?/, 'set')
|
||||
.replace(/:id\?/, 0)
|
||||
.replace(/:view\?/, 'create');
|
||||
|
||||
window.ss.router.show(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider {
|
||||
'set',
|
||||
'sets',
|
||||
'schema',
|
||||
'CreateEditForm',
|
||||
'DetailEditForm',
|
||||
'readCampaigns',
|
||||
'createCampaign',
|
||||
@ -30,7 +31,6 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider {
|
||||
private static $url_handlers = [
|
||||
'GET sets' => 'readCampaigns',
|
||||
'POST set/$ID/publish' => 'publishCampaign',
|
||||
'POST set/$ID' => 'createCampaign',
|
||||
'GET set/$ID/$Name' => 'readCampaign',
|
||||
'DELETE set/$ID' => 'deleteCampaign',
|
||||
];
|
||||
@ -62,7 +62,10 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider {
|
||||
],
|
||||
'DetailEditForm' => [
|
||||
'schemaUrl' => $this->Link('schema/DetailEditForm')
|
||||
]
|
||||
],
|
||||
'CreateEditForm' => [
|
||||
'schemaUrl' => $this->Link('schema/CreateEditForm')
|
||||
],
|
||||
],
|
||||
'campaignViewRoute' => $this->Link() . ':type?/:id?/:view?',
|
||||
'itemListViewEndpoint' => $this->Link() . 'set/:id/show',
|
||||
@ -188,23 +191,6 @@ JSON;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* REST endpoint to create a campaign.
|
||||
*
|
||||
* @param SS_HTTPRequest $request
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function createCampaign(SS_HTTPRequest $request) {
|
||||
$response = new SS_HTTPResponse();
|
||||
$response->addHeader('Content-Type', 'application/json');
|
||||
$response->setBody(Convert::raw2json(['campaign' => 'create']));
|
||||
|
||||
// TODO Implement permission check and data creation
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* REST endpoint to get a list of campaigns.
|
||||
*
|
||||
@ -489,6 +475,22 @@ JSON;
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Use GridFieldDetailForm once it can handle structured data and form schemas
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function getCreateEditForm() {
|
||||
return Form::create(
|
||||
$this,
|
||||
'CreateEditForm',
|
||||
ChangeSet::singleton()->getCMSFields(),
|
||||
FieldList::create(
|
||||
FormAction::create('save', 'Save')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets user-visible url to edit a specific {@see ChangeSet}
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user