pieforms-commit Mailing List for Pieforms
Status: Alpha
Brought to you by:
oracleshinoda
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(73) |
Dec
(83) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(16) |
Feb
(19) |
Mar
(12) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(45) |
2008 |
Jan
(20) |
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(2) |
May
(1) |
Jun
(5) |
Jul
(1) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
(7) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
1
|
2
(4) |
3
|
4
|
5
|
6
|
7
(4) |
8
|
9
|
10
|
11
(3) |
12
|
13
|
14
|
15
|
16
|
17
|
18
|
19
|
20
(4) |
21
|
22
|
23
|
24
|
25
(1) |
26
|
27
|
28
|
29
|
30
|
31
|
|
|
|
From: <ora...@us...> - 2007-01-20 08:05:45
|
Revision: 171 http://svn.sourceforge.net/pieforms/?rev=171&view=rev Author: oracleshinoda Date: 2007-01-20 00:05:44 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Added an element to get a size in bytes. It allows the user to select kilobytes or megabytes as units as well Added Paths: ----------- pieforms-php5/trunk/src/pieform/elements/bytes.php Added: pieforms-php5/trunk/src/pieform/elements/bytes.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/bytes.php (rev 0) +++ pieforms-php5/trunk/src/pieform/elements/bytes.php 2007-01-20 08:05:44 UTC (rev 171) @@ -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'); +} + +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-01-20 08:03:37
|
Revision: 170 http://svn.sourceforge.net/pieforms/?rev=170&view=rev Author: oracleshinoda Date: 2007-01-20 00:03:36 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Use the type of the element instead of the name when working out the custom rule function Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-01-20 08:03:05 UTC (rev 169) +++ pieforms-php5/trunk/src/pieform.php 2007-01-20 08:03:36 UTC (rev 170) @@ -815,7 +815,7 @@ if (!$this->get_error($element['name'])) { // See if this element has a function that describes // how this rule should apply to it - $function = 'pieform_element_' . $element['name'] . '_rule_' . $rule; + $function = 'pieform_element_' . $element['type'] . '_rule_' . $rule; if (!function_exists($function)) { // Try instead the default rule function $function = 'pieform_rule_' . $rule; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-01-20 08:03:04
|
Revision: 169 http://svn.sourceforge.net/pieforms/?rev=169&view=rev Author: oracleshinoda Date: 2007-01-20 00:03:05 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Re-added missing get_value function that actually works, so that checkboxes behave normally Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/checkbox.php Modified: pieforms-php5/trunk/src/pieform/elements/checkbox.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/checkbox.php 2007-01-20 08:02:11 UTC (rev 168) +++ pieforms-php5/trunk/src/pieform/elements/checkbox.php 2007-01-20 08:03:05 UTC (rev 169) @@ -50,4 +50,26 @@ . '>'; } +function pieform_element_checkbox_get_value(Pieform $form, $element) { + $name = $element['name']; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + + if (isset($element['value'])) { + return $element['value']; + } + + if ($form->is_submitted()) { + if(isset($global[$name])) { + return true; + } + return false; + } + + if (isset($element['defaultvalue'])) { + return $element['defaultvalue']; + } + + return false; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-01-20 08:02:14
|
Revision: 168 http://svn.sourceforge.net/pieforms/?rev=168&view=rev Author: oracleshinoda Date: 2007-01-20 00:02:11 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Allow the entries to be keyed by 'key' instead of title, just in case the title is not unique for some reason Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php Modified: pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2007-01-11 09:48:45 UTC (rev 167) +++ pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2007-01-20 08:02:11 UTC (rev 168) @@ -102,14 +102,18 @@ if ($rawelement['type'] == 'fieldset') { throw new PieformException('The multicolumntable renderer does not support fieldsets'); } - if (!array_key_exists($rawelement['title'], $this->elements)) { - $this->elements[$rawelement['title']] = array(); - $this->elements[$rawelement['title']]['rawelements'] = array(); - $this->elements[$rawelement['title']]['builtelements'] = array(); - $this->elements[$rawelement['title']]['settings'] = $rawelement; + + if (!isset($rawelement['key'])) { + $rawelement['key'] = $rawelement['title']; } - $this->elements[$rawelement['title']]['rawelements'][] = $rawelement; - $this->elements[$rawelement['title']]['builtelements'][] = $builtelement; + if (!array_key_exists($rawelement['key'], $this->elements)) { + $this->elements[$rawelement['key']] = array(); + $this->elements[$rawelement['key']]['rawelements'] = array(); + $this->elements[$rawelement['key']]['builtelements'] = array(); + $this->elements[$rawelement['key']]['settings'] = $rawelement; + } + $this->elements[$rawelement['key']]['rawelements'][] = $rawelement; + $this->elements[$rawelement['key']]['builtelements'][] = $builtelement; } function set_form(Pieform $form) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |