X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/e98a38c3bcf5bf2f5da82c9a01f9f6d008b4c537..3bd11bc0e2c0e7eacb4e17e7189c3e0e73599342:/lib/MECON/HTML/QuickForm/Renderer/Tabla.php diff --git a/lib/MECON/HTML/QuickForm/Renderer/Tabla.php b/lib/MECON/HTML/QuickForm/Renderer/Tabla.php index 7f7432e..4ef1fad 100644 --- a/lib/MECON/HTML/QuickForm/Renderer/Tabla.php +++ b/lib/MECON/HTML/QuickForm/Renderer/Tabla.php @@ -1,31 +1,35 @@ - | -// | Adam Daniel | -// | Bertrand Mansion | -// +----------------------------------------------------------------------+ -// -// $Id$ + +------------------------------------------------------------------------------- +$Id$ +-----------------------------------------------------------------------------*/ require_once 'HTML/QuickForm/Renderer.php'; require_once 'MECON/HTML/Tabla.php'; /** - * A concrete renderer for HTML_QuickForm, - * based on QuickForm 2.x built-in one + * QuickForm renderer que usa Tabla como backend. + * Basado en el QuickForm Renderer basico. * * @access public */ @@ -36,7 +40,7 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { * @var object Tabla * @access private */ - var $_tabla; + var $tabla; /** * HTML con los scripts para poner antes del formulario (tipicamente @@ -84,14 +88,20 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { /** * Constructor. * - * @param mixed $style Estilo de la tabla. + * @param mixed $param Array o sting con el estilo de la tabla u objeto + * tabla alternativo para usar. * * @access public */ - function MECON_HTML_QuickForm_Renderer_Tabla($style = array()) + function MECON_HTML_QuickForm_Renderer_Tabla($param = array()) { $this->HTML_QuickForm_Renderer(); - $this->_tabla =& new Tabla($style); + if (is_a($param, 'Tabla')) { + $this->setTable($param); + } + else { + $this->tabla =& new MECON_HTML_Tabla($param); + } } // end constructor /** @@ -103,7 +113,7 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { function toHtml() { return $this->_script . $this->_prepend . - $this->_tabla->toHtml() . + $this->tabla->toHtml() . $this->_append; } // end func toHtml @@ -118,8 +128,10 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { { # FIXME - deberia sacarlo del QuickForm #$this->_prepend = $form->getFormStart(); - $attrs = $form->getAttributesString(); - $this->_prepend = "\n\n"; +# $attrs = $form->getAttributesString(); + $attrs = $form->getAttributes(true); + $this->_prepend = "\n\n"; + } // end func startForm /** @@ -134,11 +146,11 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { { // add a required note, if one is needed if (!empty($form->_required) && !$form->_freezeAll) { - $id = $this->_tabla->addRow( - array($form->getRequiredNote()), - array('colspan' => 2, 'align' => 'center', 'cabecera' => true) + $id = $this->tabla->addRow( + array(''.$form->getRequiredNote().''), + array('colspan' => 2, 'cabecera' => true) ); - //$this->_tabla->updateCellAttributes($id, array('colspan' => 2)); + //$this->tabla->updateCellAttributes($id, array('colspan' => 2)); } // add form attributes and content //$this->_html = str_replace('{content}', $this->_html, $html); @@ -146,7 +158,7 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { $this->_script = strval($form->getValidationScript()); # FIXME - deberia sacarlo del QuickForm #$this->_append = $form->getFormEnd(); - $this->_append = "\n\n"; + $this->_append = "\n\n"; } // end func finishForm /** @@ -159,9 +171,9 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { function renderHeader(&$header) { $name = $header->getName(); - $this->_tabla->addRow( + $this->tabla->addRow( array($header->toHtml()), - array('colspan' => 2, $name => true, 'align' => 'center') + array('colspan' => 2, $name => true) ); } // end func renderHeader @@ -178,14 +190,14 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { function renderElement(&$element, $required, $error) { if (!$this->_inGroup) { - $id = $this->_tabla->addRow( + $id = $this->tabla->addRow( array( - $element->getLabel() . ($required ? '*' : ''), - $element->toHtml() . ($error ? "
$error" : ''), + $element->getLabel() . ($required ? '*' : ''), + $element->toHtml() . ($error ? "
$error" : ''), ) ); - $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left', 'nowrap' => true)); - $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left')); + $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(); } @@ -213,7 +225,7 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { */ function renderHtml(&$data) { - $this->_tabla->addRow( + $this->tabla->addRow( array($header->toHtml()), array('colspan' => 2) ); @@ -247,19 +259,69 @@ class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer { $name = $group->getName(); $sep = $group->_separator; if (strtolower($name) == 'botones') { - $id = $this->_tabla->addRow( + $id = $this->tabla->addRow( array(join('', $this->_groupElements)) ); - $this->_tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'right', 'colspan' => 2)); + $this->tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2)); } else { - $id = $this->_tabla->addRow( + $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', 'nowrap' => true)); + $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