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.
*/
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;

View File

@ -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

View File

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

View File

@ -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('<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() {

View File

@ -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;

View File

@ -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();
},

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
<div class="notice-wrap"></div>