MERGE Using FormField->template in most fields

This commit is contained in:
Ingo Schommer 2011-12-21 17:35:42 +01:00
parent b36ad3b876
commit a6148c33da
17 changed files with 59 additions and 63 deletions

View File

@ -6,6 +6,10 @@
*/
class CheckboxField extends FormField {
protected $template = 'CheckboxField';
protected $fieldHolderTemplate = 'CheckboxFieldHolder';
function setValue($value) {
$this->value = ($value) ? 1 : 0;
}
@ -18,13 +22,6 @@ class CheckboxField extends FormField {
return ($this->value) ? 1 : 0;
}
function Field($properties = array()) {
return $this->customise($properties)->renderWith('CheckboxField');
}
function FieldHolder() {
$this->setFieldHolderTemplate(($this->fieldHolderTemplate) ? $this->fieldHolderTemplate : 'CheckboxFieldHolder');
return parent::FieldHolder();
}
/**

View File

@ -33,8 +33,8 @@
* @subpackage fields-basic
*/
class CheckboxSetField extends OptionsetField {
protected $disabled = false;
protected $template = 'CheckboxSetField';
/**
* @var Array
@ -133,7 +133,7 @@ class CheckboxSetField extends OptionsetField {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
return $this->customise($properties)->renderWith('CheckboxSetField');
return $this->customise($properties)->renderWith($this->getTemplate());
}
function setDisabled($val) {

View File

@ -16,6 +16,7 @@ class CreditCardField extends TextField {
"<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"$parts[3]\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>";
return $field;
}
function dataValue() {
if(is_array($this->value)) return implode("", $this->value);
else return $this->value;

View File

@ -103,6 +103,7 @@ class CurrencyField_Readonly extends ReadonlyField{
$valforInput = $this->value ? Convert::raw2att($val) : "";
return "<span class=\"readonly ".$this->extraClass()."\" id=\"" . $this->id() . "\">$val</span><input type=\"hidden\" name=\"".$this->name."\" value=\"".$valforInput."\" />";
}
/**
* This already is a readonly field.
*/

View File

@ -77,6 +77,8 @@
*/
class DropdownField extends FormField {
protected $template = 'DropdownField';
/**
* @var boolean $source Associative or numeric array of all dropdown items,
* with array key as the submitted field value, and the array value as a
@ -91,11 +93,6 @@ class DropdownField extends FormField {
*/
protected $isSelected;
/**
* @var boolean $disabled
*/
protected $disabled;
/**
* @var boolean $hasEmptyDefault Show the first <option> element as
* empty (not having a value), with an optional label defined through
@ -162,7 +159,7 @@ class DropdownField extends FormField {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
return $this->customise($properties)->renderWith('DropdownField');
return $this->customise($properties)->renderWith($this->getTemplate());
}
/**

View File

@ -5,7 +5,7 @@
* @subpackage fields-formattedinput
*/
class EmailField extends TextField {
function jsValidation() {
$formID = $this->form->FormName();
$error = _t('EmailField.VALIDATIONJS', 'Please enter an email address.');
@ -40,10 +40,6 @@ if(typeof fromAnOnBlur != 'undefined'){
JS;
}
public function Field($properties = array()) {
return $this->customise($properties)->renderWith('TextField');
}
/**
* Returns the field type - used by templates.
* @return string

View File

@ -41,6 +41,8 @@
* @subpackage fields-files
*/
class FileField extends FormField {
protected $template = 'FileField';
/**
* Restrict filesize for either all filetypes
@ -112,7 +114,7 @@ class FileField extends FormField {
public function Field($properties = array()) {
$properties = array_merge($properties, array('MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize()));
return $this->customise($properties)->renderWith('FileField');
return $this->customise($properties)->renderWith($this->getTemplate());
}
public function saveInto(DataObject $record) {

View File

@ -20,6 +20,8 @@
*/
class FormAction extends FormField {
protected $template = 'FormAction';
protected $extraData;
protected $action;
@ -85,7 +87,7 @@ class FormAction extends FormField {
'UseButtonTag' => $this->useButtonTag
)
);
return $this->customise($properties)->renderWith('FormAction');
return $this->customise($properties)->renderWith($this->getTemplate());
}
public function Type() {

View File

@ -76,7 +76,7 @@ class FormField extends RequestHandler {
/**
* @var String
*/
protected $template;
protected $template = 'FormField';
/**
* @var Custom Validation Message for the Field
@ -87,7 +87,7 @@ class FormField extends RequestHandler {
* Template name to render this FormField field holder into.
* @var string
*/
protected $fieldHolderTemplate;
protected $fieldHolderTemplate = 'FieldHolder';
/**
* Create a new field.
@ -334,10 +334,22 @@ class FormField extends RequestHandler {
return $this->form;
}
/**
* @return String
*/
public function getFieldHolderTemplate() {
return $this->fieldHolderTemplate;
}
/**
* Set name of template (without path or extension) for the holder,
* which in turn is responsible for rendering {@link Field()}.
*
* Caution: Not consistently implemented in all subclasses,
* please check the {@link Field()} method on the subclass for support.
*
* @param String
*/
public function setFieldHolderTemplate($template) {
$this->fieldHolderTemplate = $template;
}
@ -386,7 +398,9 @@ class FormField extends RequestHandler {
}
/**
* Set name of template (without path or extension)
* Set name of template (without path or extension).
* Caution: Not consistently implemented in all subclasses,
* please check the {@link Field()} method on the subclass for support.
*
* @param String
*/
@ -412,7 +426,8 @@ class FormField extends RequestHandler {
* @return string
*/
function Field($properties = array()) {
return $this->customise($properties)->renderWith('FormField');
$obj = ($properties) ? $this->customise($properties) : $this;
return $obj->renderWith($this->getTemplate());
}
/**
@ -426,9 +441,8 @@ class FormField extends RequestHandler {
* @return string
*/
function FieldHolder($properties = array()) {
return $this->customise($properties)->renderWith(
($this->fieldHolderTemplate) ? $this->fieldHolderTemplate : 'FieldHolder'
);
$obj = ($properties) ? $this->customise($properties) : $this;
return $obj->renderWith($this->getFieldHolderTemplate());
}
/**

View File

@ -6,6 +6,8 @@
* @subpackage fields-dataless
*/
class HeaderField extends DatalessField {
protected $template = 'HeaderField';
/**
* @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
@ -33,9 +35,5 @@ class HeaderField extends DatalessField {
public function getHeadingLevel() {
return $this->headingLevel;
}
function Field($properties = array()) {
return $this->customise($properties)->renderWith('HeaderField');
}
}

View File

@ -6,9 +6,7 @@
*/
class HiddenField extends FormField {
function Field($properties = array()) {
return $this->customise($properties)->renderWith('HiddenField');
}
protected $template = 'HiddenField';
function FieldHolder() {
return $this->Field();

View File

@ -21,6 +21,7 @@ class ImageFormAction extends FormAction {
$this->className = $className;
parent::__construct($action, $title, $form);
}
function Field() {
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js');
@ -30,6 +31,4 @@ class ImageFormAction extends FormAction {
if($this->hoverImage) $classClause .= 'rollover ';
return "<input class=\"{$classClause}action\" id=\"" . $this->id() . "\" type=\"image\" name=\"{$this->name}\" src=\"{$this->image}\" title=\"{$this->title}\" alt=\"{$this->title}\" />";
}
}
?>
}

View File

@ -8,6 +8,8 @@
* @subpackage fields-dataless
*/
class LabelField extends DatalessField {
protected $template = 'LabelField';
/**
* @param string $name
@ -27,11 +29,4 @@ class LabelField extends DatalessField {
parent::__construct($name, $title, $form);
}
/**
* Returns a label containing the title, and an HTML class if given.
*/
function Field($properties = array()) {
return $this->customise($properties)->renderWith('LabelField');
}
}

View File

@ -55,6 +55,8 @@
* @subpackage fields-basic
*/
class OptionsetField extends DropdownField {
protected $template = 'OptionsetField';
/**
* @var Array
@ -86,7 +88,7 @@ class OptionsetField extends DropdownField {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
return $this->customise($properties)->renderWith('OptionsetField');
return $this->customise($properties)->renderWith($this->getTemplate());
}
function performReadonlyTransformation() {

View File

@ -4,7 +4,7 @@
* @package forms
* @subpackage fields-formattedinput
*/
class PasswordField extends FormField {
class PasswordField extends TextField {
/**
* maxlength of the password field
@ -24,20 +24,10 @@ class PasswordField extends FormField {
}
function Field() {
$disabled = $this->isDisabled()?"disabled=\"disabled\"":"";
$readonly = $this->isReadonly()?"readonly=\"readonly\"":"";
if($this->maxLength) {
return "<input class=\"text\" type=\"password\" id=\"" . $this->id() .
"\" name=\"{$this->name}\" value=\"" . $this->attrValue() .
"\" maxlength=\"$this->maxLength\" size=\"$this->maxLength\" $disabled $readonly />";
} else {
return "<input class=\"text\" type=\"password\" id=\"" . $this->id() .
"\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" $disabled $readonly />";
}
function Type() {
return 'password';
}
/**
* Makes a pretty readonly field with some stars in it
*/

View File

@ -6,6 +6,8 @@
*/
class TextField extends FormField {
protected $template = 'TextField';
/**
* @var Int
*/
@ -43,7 +45,7 @@ class TextField extends FormField {
)
);
return $this->customise($properties)->renderWith('TextField');
return parent::Field($properties);
}
function InternallyLabelledField() {

View File

@ -22,6 +22,8 @@
*/
class TextareaField extends FormField {
protected $template = 'TextareaField';
protected $rows, $cols;
/**
@ -57,7 +59,7 @@ class TextareaField extends FormField {
)
);
return $this->customise($properties)->renderWith('TextareaField');
return parent::Field($properties);
}
/**