1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
4 -------------------------------------------------------------------------------
5 This file is part of mlib.
7 mlib is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your option)
12 mlib is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License; if not,
17 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------
20 Creado: jue jul 17 15:36:26 ART 2003
21 Autor: Leandro Lucarella <llucar@mecon.gov.ar>
22 -------------------------------------------------------------------------------
24 -----------------------------------------------------------------------------*/
26 require_once 'HTML/QuickForm/Renderer.php';
27 require_once 'MLIB/HTML/Tabla.php';
30 * QuickForm renderer que usa Tabla como backend.
31 * Basado en el QuickForm Renderer basico.
35 class MLIB_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer {
38 * Tabla usada para dibujar el formulario.
45 * HTML con los scripts para poner antes del formulario (tipicamente
53 * HTML para agregar antes de la tabla (tipicamente un javascript).
60 * HTML para agregar despues de la tabla.
67 * True if we are inside a group
71 var $_inGroup = false;
74 * Group error related message.
78 var $_groupError = '';
81 * Array with HTML generated for group elements
85 var $_groupElements = array();
90 * @param mixed $param Array o sting con el estilo de la tabla u objeto
91 * tabla alternativo para usar.
95 function MLIB_HTML_QuickForm_Renderer_Tabla($param = array())
97 $this->HTML_QuickForm_Renderer();
98 if (is_a($param, 'Tabla')) {
99 $this->setTable($param);
102 $this->tabla =& new MLIB_HTML_Tabla($param);
107 * returns the HTML generated for the form
114 return $this->_script . $this->_prepend .
115 $this->tabla->toHtml() .
120 * Called when visiting a form, before processing any form elements
122 * @param object An HTML_QuickForm object being visited
126 function startForm(&$form)
128 # FIXME - deberia sacarlo del QuickForm
129 #$this->_prepend = $form->getFormStart();
130 # $attrs = $form->getAttributesString();
131 $attrs = $form->getAttributes(true);
132 $this->_prepend = "\n<form$attrs>\n";
134 } // end func startForm
137 * Called when visiting a form, after processing all form elements
138 * Adds required note, form attributes, validation javascript and form content.
140 * @param object An HTML_QuickForm object being visited
144 function finishForm(&$form)
146 // add a required note, if one is needed
147 if (!empty($form->_required) && !$form->_freezeAll) {
148 $id = $this->tabla->addRow(
149 array('<font size="-2">'.$form->getRequiredNote().'</font>'),
150 array('colspan' => 2, 'cabecera' => true)
152 //$this->tabla->updateCellAttributes($id, array('colspan' => 2));
154 // add form attributes and content
155 //$this->_html = str_replace('{content}', $this->_html, $html);
156 // add a validation script
157 $this->_script = strval($form->getValidationScript());
158 # FIXME - deberia sacarlo del QuickForm
159 #$this->_append = $form->getFormEnd();
160 $this->_append = "\n</form>\n";
161 } // end func finishForm
164 * Called when visiting a header element
166 * @param object An HTML_QuickForm_header element being visited
170 function renderHeader(&$header)
172 $name = $header->getName();
173 $this->tabla->addRow(
174 array($header->toHtml()),
175 array('colspan' => 2, $name => true)
177 } // end func renderHeader
180 * Renders an element Html
181 * Called when visiting an element
183 * @param object An HTML_QuickForm_element object being visited
184 * @param bool Whether an element is required
185 * @param string An error message associated with an element
189 function renderElement(&$element, $required, $error)
191 if (!$this->_inGroup) {
192 $id = $this->tabla->addRow(
194 $element->getLabel() . ($required ? '<font color="red">*</FONT>' : ''),
195 $element->toHtml() . ($error ? "<br><font color=\"red\">$error</FONT>" : ''),
198 $this->tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
199 $this->tabla->updateCellAttributes($id, 1, array('align' => 'left'));
201 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
203 } // end func renderElement
206 * Renders an hidden element
207 * Called when visiting a hidden element
209 * @param object An HTML_QuickForm_hidden object being visited
213 function renderHidden(&$element)
215 $this->_prepend .= "\n\t". $element->toHtml();
216 } // end func renderHidden
219 * Called when visiting a raw HTML/text pseudo-element
221 * @param object An HTML_QuickForm_html element being visited
225 function renderHtml(&$data)
227 $this->tabla->addRow(
228 array($header->toHtml()),
229 array('colspan' => 2)
231 } // end func renderHtml
234 * Called when visiting a group, before processing any group elements
236 * @param object An HTML_QuickForm_group object being visited
237 * @param bool Whether a group is required
238 * @param string An error message associated with a group
242 function startGroup(&$group, $required, $error)
244 $this->_groupElements = array();
245 $this->_groupError = $error;
246 $this->_inGroup = true;
247 } // end func startGroup
250 * Called when visiting a group, after processing all group elements
252 * @param object An HTML_QuickForm_group object being visited
256 function finishGroup(&$group)
258 $name = $group->getName();
259 $sep = $group->_separator;
260 if (strtolower($name) == 'botones') {
261 $id = $this->tabla->addRow(
262 array(join('', $this->_groupElements))
264 $this->tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2));
266 $id = $this->tabla->addRow(
267 array($group->getLabel(), join($sep, $this->_groupElements)),
268 array('valign' => 'middle', 'align' => 'left')
270 $this->tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
272 $this->_inGroup = false;
273 } // end func finishGroup
276 * Actualiza atributos de la tabla interna.
278 * @param mixed $attrs Html attributes
281 * @deprecated Usar $renderer->tabla->updateAttributes().
283 function updateAttributes($attrs) {
284 $this->tabla->updateAttributes($attrs);
289 * @param mixed $attrs Html attributes
292 * @deprecated Usar $renderer->tabla->setAttributes().
294 function setAttributes($attrs) {
295 $this->tabla->setAttributes($attrs);
302 * @deprecated Usar $renderer->tabla->getAttributes().
304 function getAttributes() {
305 return $this->tabla->getAttributes();
309 * Setea la tabla que utilizará el renderer.
311 * @param Tabla $param Objeto tabla alternativo para utilizar
315 * @deprecated Usar $renderer->tabla.
317 function setTable(&$param) {
318 $this->tabla =& $param;
322 return $this->tabla->getCSS();
325 } // end class HTML_QuickForm_Renderer_Default