From 0271652aa33eb27003f08739292cd6e39673bd6a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 19 Apr 2011 21:16:56 +1200 Subject: [PATCH] ENHANCEMENT Added default 'delete' action in LeftAndMain->getEditForm() if no other actions are set ('save' action was already present) --- admin/code/LeftAndMain.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index f100f2846..29281d6ce 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -601,6 +601,21 @@ class LeftAndMain extends Controller { return $form->formHtmlContent(); } + + public function delete($data, $form) { + $className = $this->stat('tree_class'); + + $record = DataObject::get_by_id($className, Convert::raw2sql($data['ID'])); + if($record && !$record->canDelete()) return Security::permissionFailure(); + + $record->delete(); + + if($this->isAjax()) { + return $this->EmptyForm()->formHtmlContent(); + } else { + $this->redirectBack(); + } + } /** * Update the position and parent of a tree node. @@ -764,8 +779,13 @@ class LeftAndMain extends Controller { $actions = $record->getCMSActions(); // add default actions if none are defined if(!$actions || !$actions->Count()) { + if($record->hasMethod('canDelete') && $record->canDelete()) { + $actions->push($deleteAction = new FormAction('delete',_t('ModelAdmin.DELETE','Delete'))); + $deleteAction->addExtraClass('ss-ui-action-destructive'); + } if($record->hasMethod('canEdit') && $record->canEdit()) { - $actions->push(new FormAction('save',_t('CMSMain.SAVE','Save'))); + $actions->push($saveAction = new FormAction('save',_t('CMSMain.SAVE','Save'))); + $saveAction->addExtraClass('ss-ui-action-constructive'); } } }