2016-03-18 14:42:45 +13:00
|
|
|
import React from 'react';
|
2016-03-26 18:41:24 +13:00
|
|
|
import SilverStripeComponent from 'silverstripe-component.js';
|
2016-03-26 11:20:48 +13:00
|
|
|
import GridFieldTable from './table';
|
|
|
|
import GridFieldHeader from './header';
|
|
|
|
import GridFieldHeaderCell from './header-cell';
|
|
|
|
import GridFieldRow from './row';
|
|
|
|
import GridFieldCell from './cell';
|
|
|
|
import GridFieldAction from './action';
|
2016-03-18 14:42:45 +13:00
|
|
|
|
|
|
|
class GridField extends SilverStripeComponent {
|
|
|
|
|
2016-03-24 12:32:38 +13:00
|
|
|
constructor(props) {
|
2016-03-18 14:42:45 +13:00
|
|
|
super(props);
|
2016-03-26 11:20:48 +13:00
|
|
|
|
2016-03-24 12:32:38 +13:00
|
|
|
this.deleteCampaign = this.deleteCampaign.bind(this);
|
|
|
|
this.editCampaign = this.editCampaign.bind(this);
|
2016-03-18 14:42:45 +13:00
|
|
|
|
|
|
|
// TODO: This will be an AJAX call and it's response stored in state.
|
|
|
|
this.mockData = {
|
|
|
|
campaigns: [
|
|
|
|
{
|
|
|
|
title: 'SilverStripe 4.0 release',
|
|
|
|
description: 'All the stuff related to the 4.0 announcement',
|
|
|
|
changes: 20
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'March release',
|
|
|
|
description: 'march release stuff',
|
|
|
|
changes: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'About us',
|
|
|
|
description: 'The team',
|
|
|
|
changes: 1345
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-03-24 12:32:38 +13:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
name: 'title'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'changes',
|
|
|
|
width: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'description',
|
|
|
|
width: 6
|
|
|
|
}
|
|
|
|
];
|
2016-03-18 14:42:45 +13:00
|
|
|
|
2016-03-24 12:32:38 +13:00
|
|
|
const actions = [
|
|
|
|
<GridFieldAction icon={'cog'} handleClick={this.editCampaign} />,
|
|
|
|
<GridFieldAction icon={'cancel'} handleClick={this.deleteCampaign} />
|
|
|
|
];
|
|
|
|
|
|
|
|
// Placeholder to align the headers correctly with the content
|
|
|
|
const actionPlaceholder = <span key={'actionPlaceholder'} style={{width: actions.length * 36 + 12}} />;
|
|
|
|
|
|
|
|
const headerCells = columns.map((column, i) => <GridFieldHeaderCell key={i} width={column.width}>{column.name}</GridFieldHeaderCell>);
|
|
|
|
const header = <GridFieldHeader>{headerCells.concat(actionPlaceholder)}</GridFieldHeader>;
|
2016-03-18 14:42:45 +13:00
|
|
|
|
|
|
|
const rows = this.mockData.campaigns.map((campaign, i) => {
|
2016-03-24 12:32:38 +13:00
|
|
|
var cells = columns.map((column, i) => {
|
|
|
|
return <GridFieldCell key={i} width={column.width}>{campaign[column.name]}</GridFieldCell>
|
2016-03-18 14:42:45 +13:00
|
|
|
});
|
2016-03-24 12:32:38 +13:00
|
|
|
|
|
|
|
var rowActions = actions.map((action, j) => {
|
|
|
|
return Object.assign({}, action, {
|
|
|
|
key: `action-${i}-${j}`
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
return <GridFieldRow key={i}>{cells.concat(rowActions)}</GridFieldRow>;
|
2016-03-18 14:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<GridFieldTable header={header} rows={rows}></GridFieldTable>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-24 12:32:38 +13:00
|
|
|
deleteCampaign(event) {
|
|
|
|
// delete campaign
|
|
|
|
}
|
|
|
|
|
|
|
|
editCampaign(event) {
|
|
|
|
// edit campaign
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:42:45 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
export default GridField;
|