(merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@59969 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-08-06 06:54:59 +00:00
parent aeab0115a0
commit 0365bc113f
8 changed files with 84 additions and 20 deletions

View File

@ -2147,4 +2147,3 @@ class DataObject extends ViewableData implements DataObjectInterface {
} }
?> ?>

View File

@ -404,6 +404,13 @@ class Form extends ViewableData {
return $this->class . '_' . str_replace('.', '', $this->name); return $this->class . '_' . str_replace('.', '', $this->name);
} }
/**
* Returns this form's controller
*/
function Controller() {
return $this->controller;
}
/** /**
* @return string * @return string
*/ */
@ -412,12 +419,12 @@ class Form extends ViewableData {
} }
/** /**
* Returns the field referenced by $_GET[fieldName]. * Returns an object where there is a method with the same name as each data field on the form.
* Used for embedding entire extra helper forms inside complex field types (such as ComplexTableField) * That method will return the field itself.
* @return FormField The field referenced by $_GET[fieldName] * It means that you can execute $firstNameField = $form->FieldMap()->FirstName(), which can be handy
*/ */
function ReferencedField() { function FieldMap() {
return $this->dataFieldByName($_GET['fieldName']); return new Form_FieldMap($this);
} }
/** /**
@ -854,3 +861,16 @@ class Form extends ViewableData {
return $this->testSubmission($action, $data); return $this->testSubmission($action, $data);
} }
} }
class Form_FieldMap extends Object {
protected $form;
function __construct($form) {
$this->form = $form;
parent::__construct();
}
function __call($method, $args = null) {
return $this->form->dataFieldByName($method);
}
}

View File

@ -7,6 +7,7 @@
*/ */
class FormAction extends FormField { class FormAction extends FormField {
protected $extraData; protected $extraData;
protected $action;
/** /**
* Create a new action button. * Create a new action button.
@ -20,7 +21,8 @@ class FormAction extends FormField {
function __construct($action, $title = "", $form = null, $extraData = null, $extraClass = '') { function __construct($action, $title = "", $form = null, $extraData = null, $extraClass = '') {
$this->extraData = $extraData; $this->extraData = $extraData;
$this->extraClass = ' '.$extraClass; $this->extraClass = ' '.$extraClass;
parent::__construct("action_$action", $title, null, $form); $this->action = "action_$action";
parent::__construct($this->action, $title, null, $form);
} }
static function create($action, $title = "", $extraData = null, $extraClass = null) { static function create($action, $title = "", $extraData = null, $extraClass = null) {
return new FormAction($action, $title, null, $extraData, $extraClass); return new FormAction($action, $title, null, $extraData, $extraClass);
@ -30,13 +32,21 @@ class FormAction extends FormField {
return substr($this->name,7); return substr($this->name,7);
} }
/**
* Set the full action name, including action_
* This provides an opportunity to replace it with something else
*/
function setFullAction($fullAction) {
$this->action = $fullAction;
}
function extraData() { function extraData() {
return $this->extraData; return $this->extraData;
} }
function Field() { function Field() {
$titleAttr = $this->description ? "title=\"" . Convert::raw2att($this->description) . "\"" : ''; $titleAttr = $this->description ? "title=\"" . Convert::raw2att($this->description) . "\"" : '';
return "<input class=\"action " . $this->extraClass() . "\" id=\"" . $this->id() . "\" type=\"submit\" name=\"{$this->name}\" value=\"" . $this->attrTitle() . "\" $titleAttr />\n"; return "<input class=\"action " . $this->extraClass() . "\" id=\"" . $this->id() . "\" type=\"submit\" name=\"$this->action\" value=\"" . $this->attrTitle() . "\" $titleAttr />\n";
} }
/** /**

View File

@ -458,6 +458,16 @@ HTML;
user_error('FormField::setExtraClass() is deprecated. Use FormField::addExtraClass() instead.', E_USER_NOTICE); user_error('FormField::setExtraClass() is deprecated. Use FormField::addExtraClass() instead.', E_USER_NOTICE);
$this->extraClasses[] = $extraClass; $this->extraClasses[] = $extraClass;
} }
/**
* This returns a link used to specify a controller in a form action.
* This lets us use FormFields as controllers.
*/
function FormObjectLink($formName) {
return $this->form->Controller()->Link() . "?executeController=" . $this->form->Name() . ".FieldMap." . $this->Name() . "&executeForm=" . $formName;
}
} }
?> ?>

28
forms/NestedForm.php Normal file
View File

@ -0,0 +1,28 @@
<?php
/**
* This is a form decorator that lets you place a form inside another form.
* The actions will be appropriately rewritten so that the nested form gets called, rather than the parent form.
*/
class NestedForm extends ViewableData {
protected $form;
/**
* Represent the given form in a tabular style
* @param form The form to decorate.
*/
function __construct(Form $form) {
$this->form = $form;
$this->failover = $form;
parent::__construct();
}
function Actions() {
$actions = $this->form->Actions();
foreach($actions as $action) {
$action->setFullAction('action_' . $action->actionName()
.'?formController=' . str_replace(array('?','.'), array('&','%2e'), $this->form->FormAction()) );
}
return $actions;
}
}

View File

@ -957,13 +957,6 @@ JS
return $link; return $link;
} }
/**
* Returns a link by which we can access this form
*/
function FormObjectLink($formName) {
return $this->form->FormAction() . ".ReferencedField.$formName&fieldName={$this->Name()}";
}
/** /**
* @return Int * @return Int
*/ */

View File

@ -5,15 +5,17 @@
* @package forms * @package forms
* @subpackage transformations * @subpackage transformations
*/ */
class TabularStyle extends Form { class TabularStyle extends ViewableData {
protected $form; protected $form;
/** /**
* Represent the given form in a tabular style * Represent the given form in a tabular style
* @param form The form to decorate. * @param form The form to decorate.
*/ */
function __construct(Form $form) { function __construct($form) {
$this->form = $form; $this->form = $form;
$this->failover = $form;
parent::__construct();
} }
/** /**
@ -42,7 +44,7 @@ class TabularStyle extends Form {
function CellActions() { function CellActions() {
$actions = ""; $actions = "";
foreach($this->form->actions as $action) { foreach($this->form->Actions() as $action) {
$actions .= $action->Field(); $actions .= $action->Field();
} }
return $actions; return $actions;

View File

@ -128,7 +128,9 @@ class Member extends DataObject {
* quirky problems (such as using the Windmill 0.3.6 proxy). * quirky problems (such as using the Windmill 0.3.6 proxy).
*/ */
static function session_regenerate_id() { static function session_regenerate_id() {
if(!headers_sent()) session_regenerate_id(true); $file = ""; $line = "";
if (!headers_sent($file, $line)) session_regenerate_id(true);
else user_error("Content already sent at line $line in $file, can't call session_regenerate_id", E_USER_WARNING);
} }
/** /**