------------------------------------------------------------------------------- $Id$ -----------------------------------------------------------------------------*/ require_once 'HTML/QuickForm/Renderer.php'; require_once 'MLIB/HTML/Tabla.php'; /** * QuickForm renderer que usa Tabla como backend. * Basado en el QuickForm Renderer basico. * * @access public */ class MLIB_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { /** * Tabla usada para dibujar el formulario. * @var object Tabla * @access private */ var $tabla; /** * HTML con los scripts para poner antes del formulario (tipicamente * un javascript). * @var string * @access private */ var $_script = ''; /** * HTML para agregar antes de la tabla (tipicamente un javascript). * @var string * @access private */ var $_prepend = ''; /** * HTML para agregar despues de la tabla. * @var string * @access private */ var $_append = ''; /** * True if we are inside a group * @var bool * @access private */ var $_inGroup = false; /** * Group error related message. * @var string * @access private */ var $_groupError = ''; /** * Array with HTML generated for group elements * @var array * @access private */ var $_groupElements = array(); /** * Constructor. * * @param mixed $param Array o sting con el estilo de la tabla u objeto * tabla alternativo para usar. * * @access public */ function MLIB_HTML_QuickForm_Renderer_Tabla($param = array()) { $this->HTML_QuickForm_Renderer(); if (is_a($param, 'Tabla')) { $this->setTable($param); } else { $this->tabla =& new MLIB_HTML_Tabla($param); } } // end constructor /** * returns the HTML generated for the form * * @access public * @return string */ function toHtml() { return $this->_script . $this->_prepend . $this->tabla->toHtml() . $this->_append; } // end func toHtml /** * Called when visiting a form, before processing any form elements * * @param object An HTML_QuickForm object being visited * @access public * @return void */ function startForm(&$form) { # FIXME - deberia sacarlo del QuickForm #$this->_prepend = $form->getFormStart(); # $attrs = $form->getAttributesString(); $attrs = $form->getAttributes(true); $this->_prepend = "\n\n"; } // end func startForm /** * Called when visiting a form, after processing all form elements * Adds required note, form attributes, validation javascript and form content. * * @param object An HTML_QuickForm object being visited * @access public * @return void */ function finishForm(&$form) { // add a required note, if one is needed if (!empty($form->_required) && !$form->_freezeAll) { $id = $this->tabla->addRow( array(''.$form->getRequiredNote().''), array('colspan' => 2, 'cabecera' => true) ); //$this->tabla->updateCellAttributes($id, array('colspan' => 2)); } // add form attributes and content //$this->_html = str_replace('{content}', $this->_html, $html); // add a validation script $this->_script = strval($form->getValidationScript()); # FIXME - deberia sacarlo del QuickForm #$this->_append = $form->getFormEnd(); $this->_append = "\n\n"; } // end func finishForm /** * Called when visiting a header element * * @param object An HTML_QuickForm_header element being visited * @access public * @return void */ function renderHeader(&$header) { $name = $header->getName(); $this->tabla->addRow( array($header->toHtml()), array('colspan' => 2, $name => true) ); } // end func renderHeader /** * Renders an element Html * Called when visiting an element * * @param object An HTML_QuickForm_element object being visited * @param bool Whether an element is required * @param string An error message associated with an element * @access public * @return void */ function renderElement(&$element, $required, $error) { if (!$this->_inGroup) { $id = $this->tabla->addRow( array( $element->getLabel() . ($required ? '*' : ''), $element->toHtml() . ($error ? "
$error" : ''), ) ); $this->tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left')); $this->tabla->updateCellAttributes($id, 1, array('align' => 'left')); } else { $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml(); } } // end func renderElement /** * Renders an hidden element * Called when visiting a hidden element * * @param object An HTML_QuickForm_hidden object being visited * @access public * @return void */ function renderHidden(&$element) { $this->_prepend .= "\n\t". $element->toHtml(); } // end func renderHidden /** * Called when visiting a raw HTML/text pseudo-element * * @param object An HTML_QuickForm_html element being visited * @access public * @return void */ function renderHtml(&$data) { $this->tabla->addRow( array($header->toHtml()), array('colspan' => 2) ); } // end func renderHtml /** * Called when visiting a group, before processing any group elements * * @param object An HTML_QuickForm_group object being visited * @param bool Whether a group is required * @param string An error message associated with a group * @access public * @return void */ function startGroup(&$group, $required, $error) { $this->_groupElements = array(); $this->_groupError = $error; $this->_inGroup = true; } // end func startGroup /** * Called when visiting a group, after processing all group elements * * @param object An HTML_QuickForm_group object being visited * @access public * @return void */ function finishGroup(&$group) { $name = $group->getName(); $sep = $group->_separator; if (strtolower($name) == 'botones') { $id = $this->tabla->addRow( array(join('', $this->_groupElements)) ); $this->tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2)); } else { $id = $this->tabla->addRow( array($group->getLabel(), join($sep, $this->_groupElements)), array('valign' => 'middle', 'align' => 'left') ); $this->tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left')); } $this->_inGroup = false; } // end func finishGroup /** * Actualiza atributos de la tabla interna. * * @param mixed $attrs Html attributes * @access public * @return void * @deprecated Usar $renderer->tabla->updateAttributes(). */ function updateAttributes($attrs) { $this->tabla->updateAttributes($attrs); } /** * Setea atributos. * * @param mixed $attrs Html attributes * @access public * @return void * @deprecated Usar $renderer->tabla->setAttributes(). */ function setAttributes($attrs) { $this->tabla->setAttributes($attrs); } /** * Obtiene atributos. * * @access public * @return mixed * @deprecated Usar $renderer->tabla->getAttributes(). */ function getAttributes() { return $this->tabla->getAttributes(); } /** * Setea la tabla que utilizará el renderer. * * @param Tabla $param Objeto tabla alternativo para utilizar * * @access public * * @deprecated Usar $renderer->tabla. */ function setTable(&$param) { $this->tabla =& $param; } function getCSS() { return $this->tabla->getCSS(); } } // end class HTML_QuickForm_Renderer_Default ?>