From 8e94a506baa66da18cd7389d22bf94ed8581fd85 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 6 Jun 2003 17:18:45 +0000 Subject: [PATCH] =?utf8?q?Se=20agrega=20la=20primera=20versi=C3=B3n=20prel?= =?utf8?q?iminar=20de=20QuickForm=20Renderer=20que=20dibuja=20con=20Tabla?= =?utf8?q?=20(y=20se=20hacen=20cambios=20cosmeticos=20a=20Tabla).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- HTML/php/QuickForm/Renderer/Tabla.php | 266 ++++++++++++++++++++++++++ HTML/php/Tabla.php | 37 ++-- 2 files changed, 284 insertions(+), 19 deletions(-) create mode 100644 HTML/php/QuickForm/Renderer/Tabla.php diff --git a/HTML/php/QuickForm/Renderer/Tabla.php b/HTML/php/QuickForm/Renderer/Tabla.php new file mode 100644 index 0000000..abf5f88 --- /dev/null +++ b/HTML/php/QuickForm/Renderer/Tabla.php @@ -0,0 +1,266 @@ + | +// | Adam Daniel | +// | Bertrand Mansion | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once 'HTML/QuickForm/Renderer.php'; +require_once 'HTML/Tabla.php'; + +/** + * A concrete renderer for HTML_QuickForm, + * based on QuickForm 2.x built-in one + * + * @access public + */ +class 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; + + /** + * Array with HTML generated for group elements + * @var array + * @access private + */ + var $_groupElements = array(); + + /** + * Constructor. + * + * @param mixed $style Estilo de la tabla. + * + * @access public + */ + function HTML_QuickForm_Renderer_Tabla($style = 'width="400"') + { + $this->HTML_QuickForm_Renderer(); + $this->_tabla =& new Tabla($style); + } // 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(); + $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, 'align' => 'center', 'cabecera' => true)); + //$this->_tabla->updateCellAttributes($id, array('colspan' => 2)); + } + // add form attributes and content + //$html = str_replace('{attributes}', $form->getAttributesString(), $this->_formTemplate); + //$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, 'align' => 'center')); + } // 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) { + if ($element->getLabel()) { + $id = $this->_tabla->addRow( + array( + $element->getLabel() . ($required ? '*' : ''), + $element->toHtml(), + ) + ); + $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left', 'nowrap' => true)); + $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left')); + } else { + $id = $this->_tabla->addRow( + array( + $element->toHtml(), + ) + ); + $this->_tabla->updateCellAttributes($id, 0, array('colspan' => 2, 'align' => 'center')); + } + } else { + $this->_groupElements[] = $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->_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) + { + $id = $this->_tabla->addRow(array($group->getLabel(), join('', $this->_groupElements))); + $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'right', 'nowrap' => true)); + $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left')); +/* if (!empty($this->_groupWrap)) { + $html = str_replace('{content}', implode('', $this->_groupElements), $this->_groupWrap); + } else { + $separator = $group->_separator; + if (is_array($separator)) { + $count = count($separator); + $html = ''; + for ($i = 0; $i < count($this->_groupElements); $i++) { + $html .= $this->_groupElements[$i] . $separator[$i % $count]; + } + $html = substr($html, 0, -strlen($separator[($i - 1) % $count])); + } else { + if (is_null($separator)) { + $separator = ' '; + } + $html = implode((string)$separator, $this->_groupElements); + } + } + $this->_html .= str_replace('{element}', $html, $this->_groupTemplate); + $this->_inGroup = false;*/ + } // end func finishGroup + +} // end class HTML_QuickForm_Renderer_Default + +?> diff --git a/HTML/php/Tabla.php b/HTML/php/Tabla.php index ae441c8..ea34ea4 100644 --- a/HTML/php/Tabla.php +++ b/HTML/php/Tabla.php @@ -84,7 +84,6 @@ class Tabla extends HTML_Table { //inserciones. } - /** * Agrega una fila del tipo Cabecera * @@ -129,7 +128,6 @@ class Tabla extends HTML_Table { return $this->addRow($contenido, 'comun'); } - /** * Modifica el atributo rowSpan a la celda pasada por parametro * @@ -175,7 +173,7 @@ class Tabla extends HTML_Table { return $this->updateCellAttributes($fila, $columna, 'align="'.$valor.'"'); } - /** + /** * Setea una columna como del tipo cabecera * * @param int $columna @@ -275,7 +273,6 @@ class Tabla extends HTML_Table { return $result; } - /** * Cambia las propiedades de una celda * @@ -291,7 +288,7 @@ class Tabla extends HTML_Table { */ function updateCellAttributes($row, $col, $attrs) { - return parent::updateCellAttributes($row, $col, $this->_attrToString($attrs)); + return parent::updateCellAttributes($row, $col, $this->_translateAttributes($attrs)); } /** @@ -309,7 +306,7 @@ class Tabla extends HTML_Table { */ function setCellAttributes($row, $col, $attrs) { - return parent::setCellAttributes($row, $col, $this->_attrToString($attrs)); + return parent::setCellAttributes($row, $col, $this->_translateAttributes($attrs)); } /** @@ -327,7 +324,7 @@ class Tabla extends HTML_Table { */ function addRow($content, $attrs = 'comun') { - return parent::addRow($content,$attrs); + return parent::addRow($content, $attrs); } /** @@ -341,26 +338,26 @@ class Tabla extends HTML_Table { * @return string * @access private */ - function _attrToString($attrs) + function _translateAttributes($attrs) { - $rta = ''; if (!$attrs) { return array(); } if (is_string($attrs)) { $attrs = $this->_parseAttributes($attrs); } + $rta = ''; foreach ($attrs as $attr => $val) { $attr = strtolower($attr); switch ($attr) { case 'comun': - $rta.=$this->_conf['atributos']['celda_comun']; + $rta .= $this->_conf['atributos']['celda_comun']; break; case 'cabecera': - $rta.=$this->_conf['atributos']['celda_cabecera']; + $rta .= $this->_conf['atributos']['celda_cabecera']; break; case 'titulo': - $rta.=$this->_conf['atributos']['celda_titulo']; + $rta .= $this->_conf['atributos']['celda_titulo']; break; case 'align': case 'valign': @@ -369,25 +366,27 @@ class Tabla extends HTML_Table { case 'rowspan': case 'colspan': case 'bgcolor': - case 'cellspacing': - case 'cellpadding': case 'class': case 'border': - $rta.="$attr=\"$val\""; + case 'cellspacing': + case 'cellpadding': + $rta .= "$attr=\"$val\""; break; case 'spacing': case 'padding': - $rta.="cell$attr=\"$val\""; + $rta .= "cell$attr=\"$val\""; break; case 'nowrap': case 'th': - $rta.="$attr"; + $rta .= $attr; break; default: - trigger_error("No se puede setear el atributo $attr", E_USER_ERROR); + trigger_error("No se permite setear el atributo $attr", E_USER_ERROR); } } return $rta; } -} + +} + ?> -- 2.43.0