/usr/local/miolo2/classes/ui/controls/inputcontrols.class

Go to the documentation of this file.
00001 <?php
00002 
00003 class MTextField extends MFormControl
00004 {
00005     public $size; // =0 => hidden
00006     public $type; //text, multiline, password, file
00007     public $validator;
00008     public $rows;
00009     public $cols;
00010 
00011     public function __construct( $name='',$value='',$label='', $size=10, $hint='', $validator=NULL, $isReadOnly=false )
00012     {
00013         parent::__construct( $name, $value, $label, '', $hint );
00014 
00015         $this->setReadOnly( $isReadOnly );
00016         $this->size     = $size;
00017         $this->type     = ( ($size > 0) ) ? 'text' : 'hidden';
00018         $this->setValidator( $validator );
00019         $this->rows     = 1;
00020         $this->cols     = $this->size;
00021         $this->formMode = MControl::FORM_MODE_SHOW_SIDE;
00022         $this->formName = $this->page->getName();
00023     
00024     }
00025 
00026     public function getValidator()
00027     {
00028         if($this->validator && $this->validator->name)
00029         {
00030             return $this->validator;
00031         }
00032         if ( method_exists($this->form, 'getFieldValidator') )
00033         {
00034             return $this->validator = $this->form->getFieldValidator($this->name);
00035         }
00036     }
00037 
00038 
00039     public function setValidator( $value )
00040     {
00041         $this->validator = is_string($value) ? new MaskValidator( $name, $label, $value ) : $value;
00042     }
00043 
00044     public function generateInner()
00045     {
00046         if ( ( $this->label ) && ( $this->type == 'hidden' ) )
00047         {
00048             $span = new Span( $this->name, $this->value, 'm-caption' ) ;
00049             $html = $this->painter->span( $span );
00050         }
00051 
00052         if ( $this->autoPostBack )
00053         {
00054             $this->AddAttribute( 'onblur', "return _doPostBack('{$this->event}','');".
00055                "document.{$this->page->name}.submit();");
00056         }
00057 
00058         if ( $this->getClass() == '' )
00059         {
00060             $this->setClass( 'm-text-field' );
00061         }
00062 
00063         if ( $this->readonly )
00064         {
00065             $this->SetClass('m-readonly');
00066             $this->AddAttribute('readonly');
00067         }
00068 
00069         if ( $this->getValidator()->mask )
00070         {
00071             $this->addAttribute('onKeyPress', 'return MIOLO_Validate_Mask('.$this->getValidator()->name.',event)');
00072         }
00073 
00074         if ( ( $this->type=='text' )     ||
00075              ( $this->type=='password' ) ||
00076              ( $this->type=='file' )
00077             )
00078         {
00079             $size = '';
00080 
00081             if ( $this->type=='text' && $this->size )
00082             {
00083                 $size = $this->size;
00084             }
00085 
00086             $text = $this->getRender('inputtext');
00087             $this->inner = $this->generateLabel() . $text;
00088         }
00089         else if ( ($this->type=='multiline') )
00090         {
00091             $text = $this->getRender('inputtextarea');
00092             $this->inner = $this->generateLabel() . $text;
00093         }
00094     }
00095 }
00096 
00097 
00098 class MPasswordField extends MTextField
00099 {
00100     public function __construct( $name='', $value='', $label='', $size=20, $hint='', $validator=null )
00101     {
00102         parent::__construct( $name, $value, $label, $size, $hint, $validator );
00103 
00104         $this->type = 'password';
00105     }
00106 }
00107 
00108 
00109 class MHiddenField extends MTextField
00110 {
00111     public function generate()
00112     {
00113         return $this->getRender('inputhidden');
00114     }
00115 }
00116 
00117 
00118 class MMultiLineField extends MTextField
00119 {
00120     public function __construct( $name='', $value='', $label='', $size=20, $rows=1, $cols=20, $hint='', $validator=null )
00121     {
00122         parent::__construct( $name, $value, $label, $size, $hint, $validator );
00123 
00124         $this->type = 'multiline';
00125         $this->rows = $rows;
00126         $this->cols = $cols;
00127         $this->setClass('m-multiline-field');
00128     }
00129 }
00130 
00131 
00132 class MFileField extends MTextField
00133 {
00134     public function __construct( $name='', $value='', $label='', $size=40, $hint='' )
00135     {
00136         parent::__construct( $name, $value, $label, $size, $hint );
00137 
00138         $this->type = 'file';
00139     }
00140 
00141     public function copyFile( $path )
00142     {
00143         if( $f=$_FILES[$this->name]['tmp_name'])
00144         {
00145             copy( $f, $path );
00146             return true;
00147         }
00148         else
00149         {
00150             return false;
00151         }
00152     }
00153 
00154     public function getFileName( )
00155     {
00156         return $_FILES[$this->name]['name'];
00157     }
00158 
00159     public function getFileType( )
00160     {
00161         return $_FILES[$this->name]['type'];
00162     }
00163 }
00164 
00165 
00166 class MCalendarField extends MTextField
00167 {
00168     public function __construct( $name='', $value='', $label='', $size=20, $hint='', $type='calendar-win2k-1' )
00169     {
00170         // este campo vai usar o calendário javascript 
00171         parent::__construct( $name, $value, $label, $size, $hint);
00172 
00173         $page = $this->page;
00174         $page->addScript('datepicker/calendar.js');
00175         $page->addScript('datepicker/lang/calendar-pt-br.js');
00176         $page->addScript('datepicker/calendar-setup.js');
00177 
00178         $styleURL = $this->manager->getAbsoluteURL('scripts/datepicker/css/' . $type . '.css');
00179 
00180         $this->page->addStyleURL($styleURL);
00181         $this->setValidator( new DATEDMYValidator( $name, $label ) );
00182     }
00183 
00184 
00185     public function generateInner()
00186     {
00187         parent::generateInner();
00188 
00189         if ( ! $this->readonly )
00190         {
00191             $location = $this->manager->getUI()->getImage('', 'cal.gif' );
00192             $imgName  = 'btn'.$this->name;
00193 
00194             $image = new MImage( $imgName, _M('Click to open the calendar'), $location );
00195 
00196             $this->page->addJsCode( "Calendar.setup({inputField:\"{$this->name}\", ifFormat:\"%d/%m/%Y\", button:\"$imgName\"});" );
00197             $image->generateInner();
00198             $this->inner .= '&nbsp;' . $image->getInner();
00199         }
00200     }
00201 }
00202 
00203 
00204 class MCurrencyField extends MTextField
00205 {
00206     private $ISOCode = 'REAL';
00207 
00208     public function __construct( $name='', $value='', $label='', $size=10, $hint='' )
00209     {
00210         // este campo vai usar validacao/formatacao javascript 
00211         parent::__construct( $name, $value, $label, $size, $hint );
00212 
00213         $page = $this->page;
00214 
00215         $page->addScript( 'm_utils.js' );
00216         $page->addScript( 'm_currency.js' );
00217     }
00218 
00219 
00220     public function getValue()
00221     {
00222         // internal ($this->value): float - 12345.67
00223         // external (return): formated string - R$ 12.345,67
00224         $format = new MCurrencyFormatter();
00225 
00226         $value = $format->formatWithSymbol( $this->value, $this->ISOCode );
00227 
00228         return $value;
00229     }
00230 
00231 
00232     public function setValue( $value )
00233     {
00234         // internal ($this->value): float - 12345.67
00235         // external ($value): formated string - 12.345,67
00236         $format = new MCurrencyFormatter();
00237 
00238         $value = $format->toDecimal($value, $this->ISOCode);
00239         $this->value = (float)$value;
00240     }
00241 
00242 
00243     public function generateInner()
00244     {
00245         $this->addAttribute( 'onBlur', "MIOLO_Currency(document.{$this->formName}.{$this->name})" );
00246 
00247         parent::generateInner();
00248     }
00249 }
00250 
00251 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil