From dc4375a383324943ea5a6b0c7477a5abbcee4b32 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 03:15:13 +0000 Subject: [PATCH] API CHANGE Removed LeftAndMain->EditForm(), please use getEditForm() instead API CHANGE Returning LeftAndMain->EmptyForm() as a welcome/placeholder message from LeftAndMain->getEditForm() if no record is found. Removed this placeholder from LeftAndMain_right.ss ENHANCEMENT Allowing optional $id parameter in LeftAndMain->getEditForm() (and subclasses) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92710 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/AssetAdmin.php | 11 ++-- code/CMSMain.php | 17 +++---- code/CommentAdmin.php | 2 +- code/LeftAndMain.php | 68 ++++++++++++++++++------- code/SecurityAdmin.php | 11 ++-- javascript/LeftAndMain.EditForm.js | 5 -- templates/Includes/LeftAndMain_right.ss | 8 --- 7 files changed, 65 insertions(+), 57 deletions(-) diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index b8dbf4a6..a010cf24 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -282,12 +282,14 @@ HTML; /** * Return the form that displays the details of a folder, including a file list and fields for editing the folder name. */ - function getEditForm($id) { + function getEditForm($id = null) { if($id && $id != "root") { $record = DataObject::get_by_id("File", $id); } else { $record = singleton("Folder"); } + + if($record && !$record->canView()) return Security::permissionFailure($this); if($record) { $fields = $record->getCMSFields(); @@ -314,12 +316,7 @@ HTML; $form->makeReadonly(); } } else { - $form = new Form( - $this, - "EditForm", - new FieldSet(), - new FieldSet() - ); + $form = $this->EmptyForm(); } return $form; diff --git a/code/CMSMain.php b/code/CMSMain.php index 4cede842..c9c06216 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -327,8 +327,12 @@ JS; /** * Calls {@link SiteTree->getCMSFields()} */ - public function getEditForm($id) { - $record = $this->getRecord($id); + public function getEditForm($id = null) { + // Include JavaScript to ensure HtmlEditorField works. + HtmlEditorField::include_js(); + + $record = ($id) ? $this->getRecord($id) : null; + if($record && !$record->canView()) return Security::permissionFailure($this); if($record) { if($record->IsDeletedFromStage) $record->Status = _t('CMSMain.REMOVEDFD',"Removed from the draft site"); @@ -401,19 +405,12 @@ JS; $form->loadDataFrom($siteConfig); return $form; } else { - $form = new Form( - $this, - "EditForm", - new FieldSet(), - new FieldSet() - ); + $form = $this->EmptyForm(); } return $form; } - - //------------------------------------------------------------------------------------------// // Data saving handlers diff --git a/code/CommentAdmin.php b/code/CommentAdmin.php index 3e7b4df5..6749026a 100644 --- a/code/CommentAdmin.php +++ b/code/CommentAdmin.php @@ -52,7 +52,7 @@ class CommentAdmin extends LeftAndMain { return $section; } - public function EditForm() { + public function getEditForm($id = null) { $section = $this->Section(); if($section == 'approved') { diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 459801ab..d0ba8ab7 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -339,12 +339,16 @@ class LeftAndMain extends Controller { } public function show($request) { + $form = $this->getEditForm($request->param('ID')); + if(Director::is_ajax()) { SSViewer::setOption('rewriteHashlinks', false); - return $this->EditForm()->formHtmlContent(); + return $form->formHtmlContent(); } else { // Rendering is handled by template, which will call EditForm() eventually - return array(); + return $this->customise(array( + 'EditForm' => $form + ))->renderWith($this->getViewer('show')); } } @@ -358,8 +362,8 @@ class LeftAndMain extends Controller { if($record && !$record->canView()) return Security::permissionFailure($this); } - $form = $this->EditForm(); - if ($form) return $form->formHtmlContent(); + $form = $this->getEditForm(); + if($form) return $form->formHtmlContent(); else return ""; } public function getLastFormIn($html) { @@ -815,21 +819,47 @@ JS; return FormResponse::respond(); } - - public function EditForm() { - // Include JavaScript to ensure HtmlEditorField works. - HtmlEditorField::include_js(); - - if ($this->currentPageID() != 0) { - $record = $this->currentPage(); - if(!$record) return false; - if($record && !$record->canView()) return Security::permissionFailure($this); - } - if ($this->hasMethod('getEditForm')) { - return $this->getEditForm($this->currentPageID()); - } - - return false; + + /** + * Gets the edit form of a specific record. Will usually construct itself + * from {@link DataObject->getCMSFields()} for the specific managed subclass + * defined in {@link LeftAndMain::$tree_class}. + * + * @param int $id ID of a record for {@link LeftAndMain::$tree_class} (Optional) + * @return Form Should return a form regardless wether a record has been found. + * Form might be readonly if the current user doesn't have the permission to edit + * the record. + */ + function getEditForm($id = null) { + die('getEditForm(): Not implemented'); + } + + /** + * Returns a placeholder form, used by {@link getEditForm()} if no record is selected. + * Our javascript logic always requires a form to be present in the CMS interface. + * + * @return Form + */ + function EmptyForm() { + return new Form( + $this, + "EditForm", + new FieldSet( + new HeaderField( + 'WelcomeHeader', + $this->getApplicationName() + ), + new LiteralField( + 'WelcomeText', + sprintf('

%s %s. %s

', + _t('LeftAndMain_right.ss.WELCOMETO','Welcome to'), + $this->getApplicationName(), + _t('CHOOSEPAGE','Please choose an item from the left.') + ) + ) + ), + new FieldSet() + ); } public function myprofile() { diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index 42072e7e..78584a8b 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -48,13 +48,15 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js"); } - public function getEditForm($id) { + public function getEditForm($id = null) { $record = null; if($id && $id != 'root') { $record = DataObject::get_by_id($this->stat('tree_class'), $id); } + if($record && !$record->canView()) return Security::permissionFailure($this); + if($record) { $fields = $record->getCMSFields(); @@ -71,12 +73,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { $form->setFields($readonlyFields); } } else { - $form = new Form( - $this, - "EditForm", - new FieldSet(), - new FieldSet() - ); + $form = $this->EmptyForm(); } return $form; diff --git a/javascript/LeftAndMain.EditForm.js b/javascript/LeftAndMain.EditForm.js index d4b7ae52..acb7692f 100644 --- a/javascript/LeftAndMain.EditForm.js +++ b/javascript/LeftAndMain.EditForm.js @@ -35,11 +35,6 @@ // Can't bind this through jQuery window.onbeforeunload = function(e) {return self._checkChangeTracker(false);}; - // set default placeholder if form has no children - this.setPlaceholderHtml(jQuery('.ss-cmsForm-welcomeMessage').html()); - jQuery('.ss-cmsForm-welcomeMessage').remove(); - if(!self.find('*').length) self.removeForm(); - $._super(); }, diff --git a/templates/Includes/LeftAndMain_right.ss b/templates/Includes/LeftAndMain_right.ss index fabc7dab..362c4cc7 100755 --- a/templates/Includes/LeftAndMain_right.ss +++ b/templates/Includes/LeftAndMain_right.ss @@ -1,11 +1,3 @@ -
-

$ApplicationName

-

- <% _t('WELCOMETO','Welcome to') %> $ApplicationName! - <% _t('CHOOSEPAGE','Please choose an item from the left.') %> -

-
- $EditForm
\ No newline at end of file