From cc0117a307c5188c00bfd86eba47209c05b88a34 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 11 Aug 2008 00:21:44 +0000 Subject: [PATCH] (merged from branches/roa. use "svn log -c -g " for detailed commit message) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@60289 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 43 ++++++++++++++++++++---- css/ModelAdmin.css | 4 +-- javascript/ModelAdmin.js | 47 +++++++++++++++++++-------- templates/Includes/ModelAdmin_left.ss | 1 - 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index 6ca12606..5cfce970 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -328,7 +328,7 @@ abstract class ModelAdmin extends LeftAndMain { * */ class ModelAdmin_CollectionController extends Controller { - protected $parentController; + public $parentController; protected $modelClass; static $url_handlers = array( @@ -401,12 +401,15 @@ class ModelAdmin_CollectionController extends Controller { $form = new Form($this, "SearchForm", $fields, new FieldSet( - new FormAction('search', _t('MemberTableField.SEARCH')) + new FormAction('search', _t('MemberTableField.SEARCH')), + $clearAction = new ResetFormAction('clearsearch', _t('ModelAdmin.CLEAR_SEARCH','Clear Search')) ) ); $form->setFormAction(Controller::join_links($this->Link(), "search")); $form->setFormMethod('get'); $form->setHTMLID("Form_SearchForm_" . $this->modelClass); + $clearAction->useButtonTag = true; + $clearAction->addExtraClass('minorAction'); return $form; } @@ -420,10 +423,15 @@ class ModelAdmin_CollectionController extends Controller { foreach ($source as $fieldName => $label){ $value[] = $fieldName; } - $checkboxes = new CheckboxSetField("ResultAssembly", "Tick the box if you want it to be shown in the results", $source, $value); + $checkboxes = new CheckboxSetField("ResultAssembly", false, $source, $value); $field = new CompositeField( - new LiteralField("ToggleResultAssemblyLink", "+ choose columns"), + new LiteralField( + "ToggleResultAssemblyLink", + sprintf("%s", + _t('ModelAdmin.CHOOSE_COLUMNS', 'Select result columns...') + ) + ), $checkboxesBlock = new CompositeField( $checkboxes, new LiteralField("ClearDiv", "
"), @@ -583,7 +591,13 @@ class ModelAdmin_RecordController extends Controller { */ function edit($request) { if ($this->currentRecord) { - return $this->EditForm()->forAjaxTemplate(); + if(Director::is_ajax()) { + return $this->EditForm()->forAjaxTemplate(); + } else { + return $this->parentController->parentController->customise(array( + 'EditForm' => $this->EditForm() + ))->renderWith('LeftAndMain'); + } } else { return "I can't find that item"; } @@ -603,6 +617,11 @@ class ModelAdmin_RecordController extends Controller { new FormAction("doSave", "Save") ); + if($this->currentRecord->canDelete(Member::currentUser())) { + $actions->insertFirst($deleteAction = new FormAction('doDelete', 'Delete')); + $deleteAction->addExtraClass('delete'); + } + $form = new Form($this, "EditForm", $fields, $actions, $validator); $form->loadDataFrom($this->currentRecord); @@ -628,7 +647,19 @@ class ModelAdmin_RecordController extends Controller { Director::redirectBack(); } } - + + /** + * Delete the current record + */ + public function doDelete($data, $form, $request) { + if($this->currentRecord->canDelete(Member::currentUser())) { + $this->currentRecord->delete(); + Director::redirect($this->parentController->Link()); + } + else Director::redirectBack(); + return; + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////// /** diff --git a/css/ModelAdmin.css b/css/ModelAdmin.css index 1af4772e..c4ca8b3c 100644 --- a/css/ModelAdmin.css +++ b/css/ModelAdmin.css @@ -4,7 +4,7 @@ } body.ModelAdmin #left { - width: 250px; + width: 260px; } body.ModelAdmin #Form_AddForm fieldset { @@ -32,7 +32,7 @@ body.ModelAdmin #SearchForm_holder { } body.ModelAdmin #SearchForm_holder div.ResultAssemblyBlock{ - margin: 1.5em 0px; + margin-bottom: 1em; } body.ModelAdmin #SearchForm_holder form div.field.hidden{ diff --git a/javascript/ModelAdmin.js b/javascript/ModelAdmin.js index 4d037470..a9933509 100644 --- a/javascript/ModelAdmin.js +++ b/javascript/ModelAdmin.js @@ -48,6 +48,22 @@ jQuery(document).ready(function() { }); } + /** + * POST a hash of form submitted data to the given endpoint + */ + function deleteRecord(uri, data) { + jQuery.post(uri, data, function(result){ + jQuery('#right #ModelAdminPanel').html(result); + + statusMessage("Deleted"); + + // TODO/SAM: It seems a bit of a hack to have to list all the little updaters here. + // Is livequery a solution? + Behaviour.apply(); // refreshes ComplexTableField + jQuery('#right ul.tabstrip').tabs(); + }); + } + /** * Returns a flattened array of data from each field * of the given form @@ -75,13 +91,26 @@ jQuery(document).ready(function() { /** * attach generic action handler to all forms displayed in the #right panel */ - jQuery('#right #form_actions_right .action').livequery('click', function(){ - form = jQuery('#right form'); + jQuery('#right #form_actions_right input[name=action_doSave]').livequery('click', function(){ + var form = jQuery('#right form'); var formAction = form.attr('action') + '?' + jQuery(this).fieldSerialize(); saveRecord(formAction, formData(form)); return false; }); + /** + * attach generic action handler to all forms displayed in the #right panel + */ + jQuery('#right #form_actions_right input[name=action_doDelete]').livequery('click', function(){ + var confirmed = confirm("Do you really want to delete?"); + if(!confirmed) return false; + + var form = jQuery('#right form'); + var formAction = form.attr('action') + '?' + jQuery(this).fieldSerialize(); + deleteRecord(formAction, formData(form)); + return false; + }); + jQuery('#right #ModelAdminPanel tbody td a').livequery('click', function(){ var el = jQuery(this); showRecord(el.attr('href')); @@ -128,22 +157,14 @@ jQuery(document).ready(function() { return false; }); - jQuery('a.form_frontend_function.clear_search').click(function(e) { - //jQuery('#SearchForm_holder .tab form').clearForm(); - var searchform = jQuery(this).parent().get(0); - jQuery(searchform).clearForm(); + jQuery('#SearchForm_holder button[name=action_clearsearch]').click(function(e) { + jQuery(this.form).clearForm(); return false; }); jQuery('a.form_frontend_function.toggle_result_assembly').click(function(){ var toggleElement = jQuery(this).next(); - if(toggleElement.css('display') != 'none'){ - jQuery(this).html('+ choose columns'); - toggleElement.hide(); - }else{ - jQuery(this).html('- hide column choose'); - toggleElement.show(); - } + toggleElement.toggle(); return false; }); diff --git a/templates/Includes/ModelAdmin_left.ss b/templates/Includes/ModelAdmin_left.ss index cc978234..ecee9c7e 100755 --- a/templates/Includes/ModelAdmin_left.ss +++ b/templates/Includes/ModelAdmin_left.ss @@ -9,7 +9,6 @@ <% control SearchForms %>
$Form - Clear Search
<% end_control %>