ENHANCEMENT Added FormField->setTemplate() and getTemplate(), using it in TabSet and other already template-driven FormField subclasses

This commit is contained in:
Ingo Schommer 2011-04-16 15:09:30 +12:00
parent 87bdb0d3d1
commit 03547fb205
5 changed files with 34 additions and 4 deletions

View File

@ -10,6 +10,8 @@
*/ */
class FileIFrameField extends FileField { class FileIFrameField extends FileField {
protected $template = 'FileIFrameField';
public static $allowed_actions = array ( public static $allowed_actions = array (
'iframe', 'iframe',
'EditFileForm', 'EditFileForm',
@ -109,7 +111,7 @@ class FileIFrameField extends FileField {
Requirements::css('sapphire/css/FileIFrameField.css'); Requirements::css('sapphire/css/FileIFrameField.css');
return $this->renderWith('FileIFrameField'); return $this->renderWith($this->template);
} }
/** /**

View File

@ -68,6 +68,11 @@ class FormField extends RequestHandler {
*/ */
protected $disabled = false; protected $disabled = false;
/**
* @var String
*/
protected $template;
/** /**
* @var Custom Validation Message for the Field * @var Custom Validation Message for the Field
*/ */
@ -356,6 +361,22 @@ class FormField extends RequestHandler {
return $this->customValidationMessage; return $this->customValidationMessage;
} }
/**
* Set name of template (without path or extension)
*
* @param String
*/
function setTemplate($template) {
$this->template = $template;
}
/**
* @return String
*/
function getTemplate() {
return $this->template;
}
/** /**
* Returns the form field - used by templates. * Returns the form field - used by templates.
* Although FieldHolder is generally what is inserted into templates, all of the field holder * Although FieldHolder is generally what is inserted into templates, all of the field holder

View File

@ -7,6 +7,9 @@
* @subpackage fields-structural * @subpackage fields-structural
*/ */
class SelectionGroup extends CompositeField { class SelectionGroup extends CompositeField {
protected $template = "SelectionGroup";
/** /**
* Create a new selection group. * Create a new selection group.
* @param name The field name of the selection group. * @param name The field name of the selection group.
@ -83,7 +86,7 @@ class SelectionGroup extends CompositeField {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/SelectionGroup.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/SelectionGroup.js');
Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css'); Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css');
return $this->renderWith("SelectionGroup"); return $this->renderWith($this->template);
} }
} }

View File

@ -27,6 +27,8 @@
*/ */
class TabSet extends CompositeField { class TabSet extends CompositeField {
protected $template = "TabSetFieldHolder";
/** /**
* @param string $name Identifier * @param string $name Identifier
* @param string $title (Optional) Natural language title of the tabset * @param string $title (Optional) Natural language title of the tabset
@ -80,7 +82,7 @@ class TabSet extends CompositeField {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js');
return $this->renderWith("TabSetFieldHolder"); return $this->renderWith($this->template);
} }
/** /**

View File

@ -6,6 +6,8 @@
*/ */
class ToggleCompositeField extends CompositeField { class ToggleCompositeField extends CompositeField {
protected $template = "ToggleCompositeField";
/** /**
* @var $headingLevel int * @var $headingLevel int
*/ */
@ -26,7 +28,7 @@ class ToggleCompositeField extends CompositeField {
Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
Requirements::javascript(SAPPHIRE_DIR . "/javascript/ToggleCompositeField.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/ToggleCompositeField.js");
return $this->renderWith("ToggleCompositeField"); return $this->renderWith($this->template);
} }
/** /**