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
This commit is contained in:
Ingo Schommer 2009-11-21 03:15:13 +00:00
parent fef2f77b09
commit dc4375a383
7 changed files with 65 additions and 57 deletions

View File

@ -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. * 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") { if($id && $id != "root") {
$record = DataObject::get_by_id("File", $id); $record = DataObject::get_by_id("File", $id);
} else { } else {
$record = singleton("Folder"); $record = singleton("Folder");
} }
if($record && !$record->canView()) return Security::permissionFailure($this);
if($record) { if($record) {
$fields = $record->getCMSFields(); $fields = $record->getCMSFields();
@ -314,12 +316,7 @@ HTML;
$form->makeReadonly(); $form->makeReadonly();
} }
} else { } else {
$form = new Form( $form = $this->EmptyForm();
$this,
"EditForm",
new FieldSet(),
new FieldSet()
);
} }
return $form; return $form;

View File

@ -327,8 +327,12 @@ JS;
/** /**
* Calls {@link SiteTree->getCMSFields()} * Calls {@link SiteTree->getCMSFields()}
*/ */
public function getEditForm($id) { public function getEditForm($id = null) {
$record = $this->getRecord($id); // 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) {
if($record->IsDeletedFromStage) $record->Status = _t('CMSMain.REMOVEDFD',"Removed from the draft site"); if($record->IsDeletedFromStage) $record->Status = _t('CMSMain.REMOVEDFD',"Removed from the draft site");
@ -401,19 +405,12 @@ JS;
$form->loadDataFrom($siteConfig); $form->loadDataFrom($siteConfig);
return $form; return $form;
} else { } else {
$form = new Form( $form = $this->EmptyForm();
$this,
"EditForm",
new FieldSet(),
new FieldSet()
);
} }
return $form; return $form;
} }
//------------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------------//
// Data saving handlers // Data saving handlers

View File

@ -52,7 +52,7 @@ class CommentAdmin extends LeftAndMain {
return $section; return $section;
} }
public function EditForm() { public function getEditForm($id = null) {
$section = $this->Section(); $section = $this->Section();
if($section == 'approved') { if($section == 'approved') {

View File

@ -339,12 +339,16 @@ class LeftAndMain extends Controller {
} }
public function show($request) { public function show($request) {
$form = $this->getEditForm($request->param('ID'));
if(Director::is_ajax()) { if(Director::is_ajax()) {
SSViewer::setOption('rewriteHashlinks', false); SSViewer::setOption('rewriteHashlinks', false);
return $this->EditForm()->formHtmlContent(); return $form->formHtmlContent();
} else { } else {
// Rendering is handled by template, which will call EditForm() eventually // 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); if($record && !$record->canView()) return Security::permissionFailure($this);
} }
$form = $this->EditForm(); $form = $this->getEditForm();
if ($form) return $form->formHtmlContent(); if($form) return $form->formHtmlContent();
else return ""; else return "";
} }
public function getLastFormIn($html) { public function getLastFormIn($html) {
@ -815,21 +819,47 @@ JS;
return FormResponse::respond(); return FormResponse::respond();
} }
public function EditForm() { /**
// Include JavaScript to ensure HtmlEditorField works. * Gets the edit form of a specific record. Will usually construct itself
HtmlEditorField::include_js(); * from {@link DataObject->getCMSFields()} for the specific managed subclass
* defined in {@link LeftAndMain::$tree_class}.
if ($this->currentPageID() != 0) { *
$record = $this->currentPage(); * @param int $id ID of a record for {@link LeftAndMain::$tree_class} (Optional)
if(!$record) return false; * @return Form Should return a form regardless wether a record has been found.
if($record && !$record->canView()) return Security::permissionFailure($this); * Form might be readonly if the current user doesn't have the permission to edit
} * the record.
if ($this->hasMethod('getEditForm')) { */
return $this->getEditForm($this->currentPageID()); function getEditForm($id = null) {
} die('getEditForm(): Not implemented');
}
return false;
/**
* 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('<p>%s %s. %s</p>',
_t('LeftAndMain_right.ss.WELCOMETO','Welcome to'),
$this->getApplicationName(),
_t('CHOOSEPAGE','Please choose an item from the left.')
)
)
),
new FieldSet()
);
} }
public function myprofile() { public function myprofile() {

View File

@ -48,13 +48,15 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js"); Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
} }
public function getEditForm($id) { public function getEditForm($id = null) {
$record = null; $record = null;
if($id && $id != 'root') { if($id && $id != 'root') {
$record = DataObject::get_by_id($this->stat('tree_class'), $id); $record = DataObject::get_by_id($this->stat('tree_class'), $id);
} }
if($record && !$record->canView()) return Security::permissionFailure($this);
if($record) { if($record) {
$fields = $record->getCMSFields(); $fields = $record->getCMSFields();
@ -71,12 +73,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
$form->setFields($readonlyFields); $form->setFields($readonlyFields);
} }
} else { } else {
$form = new Form( $form = $this->EmptyForm();
$this,
"EditForm",
new FieldSet(),
new FieldSet()
);
} }
return $form; return $form;

View File

@ -35,11 +35,6 @@
// Can't bind this through jQuery // Can't bind this through jQuery
window.onbeforeunload = function(e) {return self._checkChangeTracker(false);}; 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(); $._super();
}, },

View File

@ -1,11 +1,3 @@
<div class='ss-cmsForm-welcomeMessage'>
<h1>$ApplicationName</h1>
<p>
<% _t('WELCOMETO','Welcome to') %> $ApplicationName!
<% _t('CHOOSEPAGE','Please choose an item from the left.') %>
</p>
</div>
$EditForm $EditForm
<div class="notice-wrap"></div> <div class="notice-wrap"></div>