2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableTextField
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* This control represents a user-defined text field in a user defined form
|
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
|
|
|
class EditableTextField extends EditableFormField {
|
|
|
|
|
2009-03-16 22:29:19 +01:00
|
|
|
public static $db = array(
|
2008-09-29 05:18:23 +02:00
|
|
|
"Size" => "Int",
|
|
|
|
"MinLength" => "Int",
|
|
|
|
"MaxLength" => "Int",
|
|
|
|
"Rows" => "Int"
|
|
|
|
);
|
|
|
|
|
2009-03-16 22:29:19 +01:00
|
|
|
public static $size = 32;
|
|
|
|
|
|
|
|
public static $min_length = 1;
|
|
|
|
|
|
|
|
public static $max_length = 32;
|
|
|
|
|
|
|
|
public static $rows = 1;
|
2009-03-16 22:32:16 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
static $singular_name = 'Text field';
|
2009-03-16 22:29:19 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
static $plural_name = 'Text fields';
|
|
|
|
|
|
|
|
function __construct( $record = null, $isSingleton = false ) {
|
2009-03-16 22:29:19 +01:00
|
|
|
$this->Size = self::$size;
|
|
|
|
$this->MinLength = self::$min_length;
|
|
|
|
$this->MaxLength = self::$max_length;
|
|
|
|
$this->Rows = self::$rows;
|
2008-09-29 05:18:23 +02:00
|
|
|
parent::__construct( $record, $isSingleton );
|
2009-03-16 22:32:16 +01:00
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
function ExtraOptions() {
|
|
|
|
|
|
|
|
// eventually replace hard-coded "Fields"?
|
|
|
|
$baseName = "Fields[$this->ID]";
|
|
|
|
|
|
|
|
$extraFields = new FieldSet(
|
|
|
|
new TextField($baseName . "[Size]", _t('EditableTextField.TEXTBOXLENGTH', 'Length of text box'), (string)$this->Size),
|
|
|
|
new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
|
|
|
|
new TextField($baseName . "[MinLength]", "", (string)$this->MinLength),
|
|
|
|
new TextField($baseName . "[MaxLength]", " - ", (string)$this->MaxLength)
|
|
|
|
),
|
|
|
|
new TextField($baseName . "[Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), (string)$this->Rows)
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach( parent::ExtraOptions() as $extraField )
|
|
|
|
$extraFields->push( $extraField );
|
|
|
|
|
|
|
|
if( $this->readonly )
|
|
|
|
$extraFields = $extraFields->makeReadonly();
|
|
|
|
|
|
|
|
return $extraFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
function populateFromPostData( $data ) {
|
|
|
|
|
2009-03-16 22:29:19 +01:00
|
|
|
$this->Size = !empty( $data['Size'] ) ? $data['Size'] : self::$size;
|
|
|
|
$this->MinLength = !empty( $data['MinLength'] ) ? $data['MinLength'] : self::$min_length;
|
|
|
|
$this->MaxLength = !empty( $data['MaxLength'] ) ? $data['MaxLength'] : self::$max_length;
|
|
|
|
$this->Rows = !empty( $data['Rows'] ) ? $data['Rows'] : self::$rows;
|
2008-09-29 05:18:23 +02:00
|
|
|
parent::populateFromPostData( $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFormField() {
|
|
|
|
return $this->createField();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFilterField() {
|
|
|
|
return $this->createField( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
function createField( $asFilter = false ) {
|
|
|
|
if( $this->Rows == 1 )
|
2009-03-16 22:29:19 +01:00
|
|
|
return new TextField( $this->Name, $this->Title, ( $asFilter ) ? "" : $this->getField('Default'), $this->MaxLength);
|
2008-09-29 05:18:23 +02:00
|
|
|
else
|
2009-03-16 22:29:19 +01:00
|
|
|
return new TextareaField( $this->Name, $this->Title, $this->Rows, $this->MaxLength, ( $asFilter ) ? "" : $this->getField('Default') );
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates the default fields.
|
|
|
|
*/
|
|
|
|
function DefaultField() {
|
2009-04-20 01:52:44 +02:00
|
|
|
$disabled = ($this->readonly) ? " disabled=\"disabled\"" : '';
|
|
|
|
|
|
|
|
if($this->Rows == 1){
|
2008-09-29 05:18:23 +02:00
|
|
|
return '<div class="field text"><label class="left">'._t('EditableTextField.DEFAULTTEXT', 'Default Text').' </label> <input class="defaultText" name="Fields['.Convert::raw2att( $this->ID ).'][Default]" type="text" value="'.Convert::raw2att( $this->getField('Default') ).'"'.$disabled.' /></div>';
|
|
|
|
}else{
|
|
|
|
return '<div class="field text"><label class="left">'._t('EditableTextField.DEFAULTTEXT', 'Default Text').' </label> <textarea class="defaultText" name="Fields['.Convert::raw2att( $this->ID ).'][Default]"'.$disabled.'>'.Convert::raw2att( $this->getField('Default') ).'</textarea></div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|