Thread: [Pieforms-commit] SF.net SVN: pieforms: [167] pieforms-php5/branches/0.2.0/src
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2007-01-11 09:48:45
|
Revision: 167 http://svn.sourceforge.net/pieforms/?rev=167&view=rev Author: oracleshinoda Date: 2007-01-11 01:48:45 -0800 (Thu, 11 Jan 2007) Log Message: ----------- Merged changes from trunk Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform.php pieforms-php5/branches/0.2.0/src/static/core/pieforms.js Modified: pieforms-php5/branches/0.2.0/src/pieform.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform.php 2007-01-11 09:42:55 UTC (rev 166) +++ pieforms-php5/branches/0.2.0/src/pieform.php 2007-01-11 09:48:45 UTC (rev 167) @@ -285,7 +285,10 @@ 'rulei18n' => array(), // The tabindex for the form (managed automatically by Pieforms) - 'tabindex' => false + 'tabindex' => false, + + // Whether to add a class of the type of the element to each element + 'elementclasses' => false ); $data = array_merge($formdefaults, $formconfig, $data); $this->data = $data; @@ -1049,7 +1052,7 @@ * @param array $element The element to make an ID for * @return string The ID for the element */ - public static function make_id($element) { + public function make_id($element) { if (isset($element['id'])) { return self::hsc($element['id']); } @@ -1071,7 +1074,7 @@ * @param array $element The element to make a class for * @return string The class for an element */ - public static function make_class($element) { + public function make_class($element) { $classes = array(); if (isset($element['class'])) { $classes[] = $element['class']; @@ -1082,6 +1085,9 @@ if (!empty($element['error'])) { $classes[] = 'error'; } + if ($this->data['elementclasses']) { + $classes[] = $element['type']; + } // Please make sure that 'autofocus' is the last class added in this // method. Otherwise, improve the logic for removing 'autofocus' from // the elemnt class string in pieform_render_element @@ -1336,8 +1342,8 @@ throw new PieformException('No such form renderer function: "' . $rendererfunction . '"'); } - $element['id'] = Pieform::make_id($element); - $element['class'] = Pieform::make_class($element); + $element['id'] = $form->make_id($element); + $element['class'] = $form->make_class($element); $builtelement = $function($form, $element); // Remove the 'autofocus' class, because we only want it on the form input Modified: pieforms-php5/branches/0.2.0/src/static/core/pieforms.js =================================================================== --- pieforms-php5/branches/0.2.0/src/static/core/pieforms.js 2007-01-11 09:42:55 UTC (rev 166) +++ pieforms-php5/branches/0.2.0/src/static/core/pieforms.js 2007-01-11 09:48:45 UTC (rev 167) @@ -60,7 +60,7 @@ this.grippie.dimensions = getElementDimensions(this.grippie); // Set wrapper and textarea dimensions - setElementDimensions(this.wrapper, {'h': this.dimensions.h + this.grippie.dimensions.h + 1}); + setElementDimensions(this.wrapper, {'h': this.dimensions.h + this.grippie.dimensions.h + 1, 'w': this.dimensions.w}); setStyle(this.element, { 'margin-bottom': '0', 'width': '100%', @@ -82,7 +82,6 @@ this.grippie.style.width = '100%'; this.grippie.style.paddingLeft = '2px'; setStyle(this.grippie, { - 'width': '100%', 'padding-left': '2px' }); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-04 23:00:06
|
Revision: 176 http://svn.sourceforge.net/pieforms/?rev=176&view=rev Author: oracleshinoda Date: 2007-02-04 15:00:03 -0800 (Sun, 04 Feb 2007) Log Message: ----------- Merged fixes from trunk Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php pieforms-php5/branches/0.2.0/src/pieform.php Added Paths: ----------- pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php Copied: pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php (from rev 171, pieforms-php5/trunk/src/pieform/elements/bytes.php) =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php (rev 0) +++ pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php 2007-02-04 23:00:03 UTC (rev 176) @@ -0,0 +1,151 @@ +<?php +/** + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package pieform + * @subpackage element + * @author Martyn Smith <ma...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +/** + * Provides a size chooser, with a text box for a number and a + * select box to choose the units, in bytes, kilobytes, or megabytes + * + * @param Pieform $form The form to render the element for + * @param array $element The element to render + * @return string The HTML for the element + */ +function pieform_element_bytes(Pieform $form, $element) { + $formname = $form->get_name(); + $result = ''; + $name = $element['name']; + if (!isset($element['defaultvalue'])) { + $element['defaultvalue'] = null; + } + + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + + // Get the value of the element for rendering. + if (isset($element['value'])) { + $bytes = $element['value']; + $values = pieform_element_bytes_get_bytes_from_bytes($element['value']); + } + else if (isset($global[$element['name']]) + && isset($global[$element['name'] . '_units'])) { + $values = array('number' => $global[$element['name']], + 'units' => $global[$element['name'] . '_units']); + $bytes = $values['number'] * pieform_element_bytes_in($values['units']); + } + else if (isset($element['defaultvalue'])) { + $bytes = $element['defaultvalue']; + $values = pieform_element_bytes_get_bytes_from_bytes($bytes); + } + else { + $values = array('number' => '0', 'units' => 'bytes'); + $bytes = 0; + } + + // @todo probably create with an actual input element, as tabindex doesn't work here for one thing + // Same with the select. And do the events using mochikit signal instead of dom events + $numberinput = '<input'; + $numberinput .= ' type="text" size="8" name="' . $name . '"'; + $numberinput .= ' id="' . $formname . '_' . $name . '" value="' . $values['number'] . '" tabindex="' . $element['tabindex'] . '"'; + $numberinput .= (isset($element['error']) ? ' class="error"' : '') . ">\n"; + + $uselect = '<select onchange="' . $name . '_change()" '; + $uselect .= 'name="' . $name . '_units" id="' . $formname . '_' . $name . '_units"' . ' tabindex="' . $element['tabindex'] . "\">\n"; + foreach (pieform_element_bytes_get_bytes_units() as $u) { + $uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' + . $form->i18n('element', 'bytes', $u, $element) . "</option>\n"; + } + $uselect .= "</select>\n"; + + return $numberinput . $uselect; +} + +/** + * Gets the value of the expiry element and converts it to a time in seconds. + * + * @param Pieform $form The form the element is attached to + * @param array $element The element to get the value for + * @return int The number of seconds until expiry + */ +function pieform_element_bytes_get_value(Pieform $form, $element) { + $name = $element['name']; + + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + $unit = $global[$name . '_units']; + $allunits = pieform_element_bytes_get_bytes_units(); + $number = $global[$name]; + + if (!is_numeric($number)) { + $form->set_error($name, $form->i18n('element', 'bytes', 'invalidvalue', $element)); + } + + if (!in_array($unit,$allunits) || $number < 0) { + return null; + } + return $number * pieform_element_bytes_in($unit); +} + +function pieform_element_bytes_in($units) { + switch ($units) { + case 'megabytes': + return 1048576; + break; + case 'kilobytes': + return 1024; + break; + default: + return 1; + break; + }; +} + +function pieform_element_bytes_i18n() { + return array( + 'en.utf8' => array( + 'bytes' => 'Bytes', + 'kilobytes' => 'Kilobytes', + 'megabytes' => 'Megabytes', + 'invalidvalue' => 'Value must be a number', + ), + ); +} + +function pieform_element_bytes_get_bytes_units() { + return array('bytes', 'kilobytes', 'megabytes'); +} + +function pieform_element_bytes_get_bytes_from_bytes($bytes) { + if ($bytes == null) { + return array('number' => '0', 'units' => 'bytes'); + } + + foreach (array('megabytes', 'kilobytes') as $units) { + if ( $bytes > pieform_element_bytes_in($units) ) { + return array('number' => $bytes / pieform_element_bytes_in($units) , 'units' => $units); + } + } + + return array('number' => $bytes, 'units' => 'bytes'); +} + +?> Modified: pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php 2007-02-04 22:40:21 UTC (rev 175) +++ pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php 2007-02-04 23:00:03 UTC (rev 176) @@ -34,8 +34,11 @@ */ function pieform_element_fieldset(Pieform $form, $element) { $result = "\n<fieldset"; - if (!empty($element['collapsable'])) { - $classes = array('collapsable'); + if (!empty($element['collapsible'])) { + if (!isset($element['legend']) || $element['legend'] === '') { + Pieform::info('Collapsible fieldsets should have a legend so they can be toggled'); + } + $classes = array('collapsible'); // Work out whether any of the children have errors on them $error = false; foreach ($element['elements'] as $subelement) { @@ -52,7 +55,7 @@ $result .= ">\n"; if (isset($element['legend'])) { $result .= '<legend'; - if (!empty($element['collapsable'])) { + if (!empty($element['collapsible'])) { $id = substr(md5(microtime()), 0, 4); $result .= ' id="' . $id . '">'; $result .= '<script type="text/javascript">'; Modified: pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php 2007-02-04 22:40:21 UTC (rev 175) +++ pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php 2007-02-04 23:00:03 UTC (rev 176) @@ -39,8 +39,15 @@ if ($rawelement['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance if (0 === strpos($builtelement, "\n<fieldset")) { - $closelegendpos = strpos($builtelement, '</legend>') + 9; - $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + $closelegendpos = strpos($builtelement, '</legend>'); + if ($closelegendpos !== false) { + $closelegendpos += 9; + $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + } + else { + $pos = strpos($builtelement, '>') + 1; + $builtelement = substr($builtelement, 0, $pos) . '<table>' . substr($builtelement, $pos); + } } else { $builtelement = substr($builtelement, 0, 11) . '<table>' . substr($builtelement, 11); Modified: pieforms-php5/branches/0.2.0/src/pieform.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-04 22:40:21 UTC (rev 175) +++ pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-04 23:00:03 UTC (rev 176) @@ -325,6 +325,22 @@ throw new PieformException('Forms must have a list of elements'); } + // Rename all the keys to have nice compliant names + // @todo: + // - This isn't done for elements inside fieldsets + // - There's no easy way for other things do do all this preprocessing if they + // need. It should be a method so that other things (like multirecord) + // can use it. + $elements = array(); + foreach ($this->data['elements'] as $name => $element) { + $newname = preg_replace('/[^a-zA-Z0-9_]/', '_', $name); + if (isset($elements[$name])) { + throw new PieformException('Element "' . $name . '" has a dangerous name that interferes with another element'); + } + $elements[$newname] = $element; + } + $this->data['elements'] = $elements; + // Remove elements to ignore foreach ($this->data['elements'] as $name => $element) { if (isset($element['type']) && $element['type'] == 'fieldset') { @@ -867,6 +883,12 @@ return $result; } + /** + * Builds the javascript for submitting the form. Note that the iframe is + * not hidden with display: none, as safari/konqueror/ns6 ignore things with + * display: none. Positioning it absolute and 'hidden' has the same effect + * without the breakage. + */ private function submit_js() { $strprocessingform = get_string('processingform'); @@ -885,9 +907,9 @@ if (!iframe) { iframe = createDOM('iframe', { 'name': '{$this->name}_iframe', - 'id' : '{$this->name}_iframe' + 'id' : '{$this->name}_iframe', + 'style': 'position: absolute; visibility: hidden;' }); - hideElement(iframe); insertSiblingNodesAfter($('{$this->name}'), iframe); window.pieformHandler_{$this->name} = function(data) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |