[Pieforms-commit] SF.net SVN: pieforms: [23] pieforms/src/pieform/renderers/div.php
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2006-11-18 11:53:55
|
Revision: 23 http://svn.sourceforge.net/pieforms/?rev=23&view=rev Author: oracleshinoda Date: 2006-11-18 03:53:53 -0800 (Sat, 18 Nov 2006) Log Message: ----------- * Updated the <div> renderer to match the <table> renderer much more closely. * Updated the header comment to be correct * Added javascript for adding/removing errors and messages. Totally untested (there's no js in SVN to test with) * Fixed hsc() -> Pieform::hsc() Modified Paths: -------------- pieforms/src/pieform/renderers/div.php Modified: pieforms/src/pieform/renderers/div.php =================================================================== --- pieforms/src/pieform/renderers/div.php 2006-11-18 11:51:58 UTC (rev 22) +++ pieforms/src/pieform/renderers/div.php 2006-11-18 11:53:53 UTC (rev 23) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,18 +16,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-renderer + * @package pieform + * @subpackage renderer * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** - * Default renderer - renders form elements inside <div>s. + * Renders form elements inside <div>s. * * @param string $builtelement The element, already built * @param array $rawelement The element in raw form, for looking up @@ -35,37 +33,84 @@ * @return string The element rendered inside an appropriate * container. */ -function form_renderer_div($builtelement, $rawelement) { +function pieform_renderer_div($builtelement, $rawelement) { // Set the class of the enclosing <div> to match that of the element $result = '<div'; + if (isset($rawelement['name'])) { + $result .= ' id="' . $rawelement['name'] . '_container"'; + } if ($rawelement['class']) { $result .= ' class="' . $rawelement['class'] . '"'; } $result .= '>'; - if (isset($rawelement['title']) && $rawelement['type'] != 'fieldset') { - $result .= '<label for="' . $rawelement['id'] . '">' . hsc($rawelement['title']) . '</label>'; + if (isset($rawelement['title']) && $rawelement['title'] !== '' && $rawelement['type'] != 'fieldset') { + if (!empty($rawelement['nolabel'])) { + // Don't bother with a label for the element + $result .= Pieform::hsc($rawelement['title']); + } + else { + $result .= '<label for="' . $rawelement['id'] . '">' . Pieform::hsc($rawelement['title']) . '</label>'; + } } $result .= $builtelement; // Contextual help if (!empty($rawelement['help'])) { - $result .= ' <span class="help"><a href="#" title="' . hsc($rawelement['help']) . '">?</a></span>'; + $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; } // Description - optional description of the element, or other note that should be visible // on the form itself (without the user having to hover over contextual help if (!empty($rawelement['description'])) { - $result .= '<div class="description"> ' . hsc($rawelement['description']) . "</div>"; + $result .= '<div class="description"> ' . Pieform::hsc($rawelement['description']) . "</div>"; } if (!empty($rawelement['error'])) { - $result .= '<div class="errmsg">' . hsc($rawelement['error']) . '</div>'; + $result .= '<div class="errmsg">' . Pieform::hsc($rawelement['error']) . '</div>'; } $result .= "</div>\n"; return $result; } +function pieform_renderer_table_messages_js($id, $submitid) { + $result = <<<EOF +// Given a message and form element name, should set an error on the element +function {$id}_set_error(message, element) { + {$id}_remove_error(element); + element += '_container'; + // @todo set error class on input elements... + $(element).parentNode.insertBefore(DIV({'id': '{$id}_error_' + element, 'class': 'errmsg'}, message), $(element).nextSibling); +} +// Given a form element name, should remove an error associated with it +function {$id}_remove_error(element) { + element += '_container'; + var elem = $('{$id}_error_' + element); + if (elem) { + removeElement(elem); + } +} +function {$id}_message(message, type) { + var elem = $('{$id}_message'); + var msg = DIV({'id': '{$id}_message', 'class': type}, message); + if (elem) { + swapDOM(elem, msg); + } + else { + appendChildNodes($('{$submitid}_container').parentNode, msg); + } +} +function {$id}_remove_message() { + var elem = $('{$id}_message'); + if (elem) { + removeElement(elem); + } +} + +EOF; + return $result; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |