mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FEATURE "Add" for gridfield
This commit is contained in:
parent
38bce79fc6
commit
0acaf39664
@ -56,10 +56,16 @@ class GridFieldPopupForms implements GridField_URLHandler {
|
||||
* @return GridFieldPopupForm_ItemRequest
|
||||
*/
|
||||
public function handleItem($gridField, $request) {
|
||||
if(is_numeric($request->param('ID'))) {
|
||||
$record = $gridField->getList()->byId($request->param("ID"));
|
||||
} else {
|
||||
$record = Object::create($gridField->getModelClass());
|
||||
}
|
||||
|
||||
$handler = new GridFieldPopupForm_ItemRequest($gridField, $this, $record, $this->popupController, $this->popupFormName);
|
||||
$handler->setTemplate($this->template);
|
||||
return $handler;
|
||||
|
||||
return $handler->handleRequest($request, $gridField);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +143,7 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
|
||||
}
|
||||
|
||||
public function Link($action = null) {
|
||||
return Controller::join_links($this->gridField->Link('item'), $this->record->ID, $action);
|
||||
return Controller::join_links($this->gridField->Link('item'), $this->record->ID ? $this->record->ID : 'new', $action);
|
||||
}
|
||||
|
||||
function edit($request) {
|
||||
@ -186,9 +192,13 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
|
||||
}
|
||||
|
||||
function doSave($data, $form) {
|
||||
$new_record = $this->record->ID == 0;
|
||||
|
||||
try {
|
||||
$form->saveInto($this->record);
|
||||
$this->record->write();
|
||||
if($new_record)
|
||||
$this->gridField->getList()->add($this->record);
|
||||
} catch(ValidationException $e) {
|
||||
$form->sessionMessage($e->getResult()->message(), 'bad');
|
||||
return Director::redirectBack();
|
||||
|
@ -3,7 +3,9 @@
|
||||
class GridFieldTitle implements GridField_HTMLProvider {
|
||||
function getHTMLFragments($gridField) {
|
||||
return array(
|
||||
'header' => $gridField->renderWith('GridFieldTitle')
|
||||
'header' => $gridField->customise(array(
|
||||
'NewLink' => Controller::join_links($gridField->Link('item'), 'new')
|
||||
))->renderWith('GridFieldTitle')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
<tr class="title">
|
||||
<th colspan="$ColumnCount">$Title</th>
|
||||
<th colspan="$ColumnCount">$Title <a href="$NewLink">new</a></th>
|
||||
</tr>
|
Loading…
Reference in New Issue
Block a user