mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: working delete button
This commit is contained in:
parent
550f75408e
commit
3936909980
@ -299,6 +299,23 @@ class Controller extends RequestHandler {
|
||||
return parent::hasAction($action) || $this->hasActionTemplate($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the "action" part of the current URL and returns the result.
|
||||
* If no action parameter is present, returns the full URL
|
||||
* @static
|
||||
* @return String
|
||||
*/
|
||||
public function removeAction($fullURL, $action = null) {
|
||||
if (!$action) $action = $this->getAction(); //default to current action
|
||||
$returnURL = $fullURL;
|
||||
|
||||
if (($pos = strpos($fullURL, $action)) !== false) {
|
||||
$returnURL = substr($fullURL,0,$pos);
|
||||
}
|
||||
|
||||
return $returnURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if this controller has a template that is specifically designed to handle a specific action.
|
||||
*
|
||||
|
@ -183,10 +183,12 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
|
||||
// WARNING: The arguments passed here are a little arbitrary. This API will need cleanup
|
||||
$this->record->getCMSFields($this->popupController, $this->popupFormName),
|
||||
new FieldList(
|
||||
$saveAction = new FormAction('doSave', _t('GridFieldDetailsForm.Save', 'Save'))
|
||||
$saveAction = new FormAction('doSave', _t('GridFieldDetailsForm.Save', 'Save')),
|
||||
$deleteAction = new FormAction('doDelete', _t('GridFieldDetailsForm.Delete', 'Delete'))
|
||||
)
|
||||
);
|
||||
$saveAction->addExtraClass('ss-ui-action-constructive');
|
||||
$deleteAction->addExtraClass('ss-ui-action-destructive');
|
||||
$form->loadDataFrom($this->record);
|
||||
return $form;
|
||||
}
|
||||
@ -201,7 +203,7 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
|
||||
$this->gridField->getList()->add($this->record);
|
||||
} catch(ValidationException $e) {
|
||||
$form->sessionMessage($e->getResult()->message(), 'bad');
|
||||
return Director::redirectBack();
|
||||
return Controller::curr()->redirectBack();
|
||||
}
|
||||
|
||||
// TODO Save this item into the given relationship
|
||||
@ -217,6 +219,34 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
|
||||
return $this->popupController->redirectBack();
|
||||
}
|
||||
|
||||
function doDelete($data, $form) {
|
||||
try {
|
||||
$toDelete = $this->record;
|
||||
if (!$toDelete->canDelete()) {
|
||||
throw new ValidationException(_t('GridFieldDetailsForm.DeletePermissionsFailure',"No delete permissions"),0);
|
||||
}
|
||||
|
||||
$toDelete->delete();
|
||||
} catch(ValidationException $e) {
|
||||
$form->sessionMessage($e->getResult()->message(), 'bad');
|
||||
return Director::redirectBack();
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
_t('ComplexTableField.SUCCESSEDIT2', 'Deleted %s %s'),
|
||||
$this->record->singular_name(),
|
||||
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
|
||||
);
|
||||
|
||||
$form->sessionMessage($message, 'good');
|
||||
|
||||
//when an item is deleted, redirect to the revelant admin section without the action parameter
|
||||
$controller = Controller::curr();
|
||||
$noActionURL = $controller->removeAction($data['url']);
|
||||
|
||||
return Director::redirect($noActionURL, 302); //redirect back to admin section
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user