Thread: [Pieforms-commit] SF.net SVN: pieforms: [87] pieforms-php5/trunk/src/pieform/elements/ calendar.php
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2006-12-10 10:54:35
|
Revision: 87 http://svn.sourceforge.net/pieforms/?rev=87&view=rev Author: oracleshinoda Date: 2006-12-10 02:54:31 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Calendar element. Provides a date/time picker using a javascript calendar Added Paths: ----------- pieforms-php5/trunk/src/pieform/elements/calendar.php Added: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php (rev 0) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-10 10:54:31 UTC (rev 87) @@ -0,0 +1,97 @@ +<?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 Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +/** + * Provides a javascript calendar for inputting a date. + * + * General documentation about the calendar is available at + * http://www.dynarch.com/demos/jscalendar/doc/html/reference.html + * + * @param array $element The element to render + * @param Pieform $form The form to render the element for + * @return string The HTML for the element + */ +function pieform_render_calendar($element, Pieform $form) { + $id = $form->get_name() . '_' . $element['name']; + $result = '<input type="text"' + . $form->element_attributes($element) + . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; + if (isset($element['imagefile'])) { + $result .= '<a href="" id="'. $id . '_btn" onclick="return false;" class="pieform-calendar-toggle">' + . '<img src="' . $element['imagefile'] . '" alt=""></a>'; + } + else { + $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle" value="...">'; + } + + $options = array_merge($element['caloptions'], array('inputField' => $id, 'button' => $id . '_btn')); + + $encodedoptions = json_encode($options); + // Some options are callbacks and need their quoting removed + foreach (array('dateStatusFunc', 'flatCallback', 'onSelect', 'onClose', 'onUpdate') as $function) { + $encodedoptions = preg_replace('/("' . $function . '"):"([a-zA-Z0-9$]+)"/', '\1:\2', $encodedoptions); + } + $result .= '<script type="text/javascript">Calendar.setup(' . $encodedoptions . ');</script>'; + return $result; +} + +function pieform_render_calendar_set_attributes($element) { + $element['jsroot'] = isset($element['jsroot']) ? $element['jsroot'] : ''; + $element['language'] = isset($element['language']) ? $element['language'] : 'en'; + $element['theme'] = isset($element['theme']) ? $element['theme'] : 'calendar-win2k-2'; + $element['caloptions']['ifFormat'] = '%Y/%m/%d'; + $element['caloptions']['daFormat'] = '%Y/%m/%d'; + $element['rules']['regex'] = '#^(\d{4}/\d{2}/\d{2})?$#'; + return $element; +} + +/** Returns code to go in <head> for all instances of calendar */ +function pieform_get_headdata_calendar($element) { + if (isset($element['themefile'])) { + $themefile = $element['themefile']; + } + else if (isset($element['theme'])) { + $themefile = $element['jsroot'] . $element['theme'] . '.css'; + } + else { + throw new PieformException('No theme chosen for calendar "' . $element['name'] . '": please set themefile or theme'); + } + $libfile = $element['jsroot'] . 'calendar_stripped.js'; + $langfile = $element['jsroot'] . 'lang/calendar-' . $element['language'] . '.js'; + $setupfile = $element['jsroot'] . 'calendar-setup_stripped.js'; + $result = array( + '<link rel="stylesheet" type="text/css" media="all" href="' . $themefile . '">', + '<script type="text/javascript" src="' . $libfile . '"></script>', + '<script type="text/javascript" src="' . $langfile . '"></script>', + '<script type="text/javascript" src="' . $setupfile . '"></script>' + ); + return $result; +} + + +// TODO: use the get_value function to do strtotime? (possibly, also might need the javascript version for ajax forms) + +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-15 01:27:50
|
Revision: 96 http://svn.sourceforge.net/pieforms/?rev=96&view=rev Author: oracleshinoda Date: 2006-12-14 17:27:49 -0800 (Thu, 14 Dec 2006) Log Message: ----------- Made the calendar element deal in unix timestamps (Martyn Smith) Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/calendar.php Modified: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-15 01:26:25 UTC (rev 95) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-15 01:27:49 UTC (rev 96) @@ -38,7 +38,7 @@ $id = $form->get_name() . '_' . $element['name']; $result = '<input type="text"' . $form->element_attributes($element) - . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; + . ' value="' . ( $form->get_value($element) ? Pieform::hsc(strftime($element['caloptions']['ifFormat'],$form->get_value($element))) : '' ) . '">'; if (isset($element['imagefile'])) { $result .= '<a href="" id="'. $id . '_btn" onclick="return false;" class="pieform-calendar-toggle">' . '<img src="' . $element['imagefile'] . '" alt=""></a>'; @@ -62,9 +62,8 @@ $element['jsroot'] = isset($element['jsroot']) ? $element['jsroot'] : ''; $element['language'] = isset($element['language']) ? $element['language'] : 'en'; $element['theme'] = isset($element['theme']) ? $element['theme'] : 'calendar-win2k-2'; - $element['caloptions']['ifFormat'] = '%Y/%m/%d'; - $element['caloptions']['daFormat'] = '%Y/%m/%d'; - $element['rules']['regex'] = '#^(\d{4}/\d{2}/\d{2})?$#'; + $element['caloptions']['ifFormat'] = isset($element['caloptions']['ifFormat']) ? $element['caloptions']['ifFormat'] : '%Y/%m/%d'; + $element['caloptions']['daFormat'] = isset($element['caloptions']['daFormat']) ? $element['caloptions']['daFormat'] : '%Y/%m/%d'; return $element; } @@ -91,7 +90,36 @@ return $result; } +function pieform_get_value_calendar($element, Pieform $form) { + $name = $element['name']; -// TODO: use the get_value function to do strtotime? (possibly, also might need the javascript version for ajax forms) + $global = ($form->get_method() == 'get') ? $_GET : $_POST; + if (isset($element['value'])) { + return $element['value']; + } + + if (isset($global[$name])) { + if (trim($global[$name]) == '') { + return null; + } + + $value = strtotime($global[$name]); + + if ($value === false) { + $form->set_error($name, 'TODO'); + return null; + } + return $value; + } + + if (isset($element['defaultvalue'])) { + return $element['defaultvalue']; + } + + return null; +} + +// TODO: (possibly, also might need the javascript version for ajax forms) + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[Pieforms-commit] SF.net SVN: pieforms: [115]
pieforms-php5/trunk/src/pieform/elements/ calendar.php
From: <ora...@us...> - 2006-12-23 03:57:37
|
Revision: 115 http://svn.sourceforge.net/pieforms/?rev=115&view=rev Author: oracleshinoda Date: 2006-12-22 19:57:27 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new API. Corrected tabindex too. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/calendar.php Modified: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-23 03:56:23 UTC (rev 114) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-23 03:57:27 UTC (rev 115) @@ -30,23 +30,32 @@ * General documentation about the calendar is available at * http://www.dynarch.com/demos/jscalendar/doc/html/reference.html * + * @param Pieform $form The form to render the element for * @param array $element The element to render - * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_calendar($element, Pieform $form) { +function pieform_element_calendar(Pieform $form, $element) { $id = $form->get_name() . '_' . $element['name']; + $value = $form->get_value($element); + if ($value) { + $value = Pieform::hsc(strftime($element['caloptions']['ifFormat'], $value)); + } + + // Build the HTML $result = '<input type="text"' . $form->element_attributes($element) - . ' value="' . ( $form->get_value($element) ? Pieform::hsc(strftime($element['caloptions']['ifFormat'],$form->get_value($element))) : '' ) . '">'; + . ' value="' . $value . '">'; if (isset($element['imagefile'])) { - $result .= '<a href="" id="'. $id . '_btn" onclick="return false;" class="pieform-calendar-toggle">' + $result .= '<a href="" id="'. $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' + . ' tabindex="' . $element['tabindex'] . '">' . '<img src="' . $element['imagefile'] . '" alt=""></a>'; } else { - $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle" value="...">'; + $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' + . ' value="..." tabindex="' . $element['tabindex'] . '">'; } + // Build the configuring javascript $options = array_merge($element['caloptions'], array('inputField' => $id, 'button' => $id . '_btn')); $encodedoptions = json_encode($options); @@ -55,10 +64,17 @@ $encodedoptions = preg_replace('/("' . $function . '"):"([a-zA-Z0-9$]+)"/', '\1:\2', $encodedoptions); } $result .= '<script type="text/javascript">Calendar.setup(' . $encodedoptions . ');</script>'; + return $result; } -function pieform_render_calendar_set_attributes($element) { +/** + * Sets default attributes of the calendar element. + * + * @param array $element The element to configure + * @return array The configured element + */ +function pieform_element_calendar_set_attributes($element) { $element['jsroot'] = isset($element['jsroot']) ? $element['jsroot'] : ''; $element['language'] = isset($element['language']) ? $element['language'] : 'en'; $element['theme'] = isset($element['theme']) ? $element['theme'] : 'calendar-win2k-2'; @@ -67,8 +83,13 @@ return $element; } -/** Returns code to go in <head> for all instances of calendar */ -function pieform_get_headdata_calendar($element) { +/** + * Returns code to go in <head> for the given calendar instance + * + * @param array $element The element to get <head> code for + * @return array An array of HTML elements to go in the <head> + */ +function pieform_element_calendar_get_headdata($element) { if (isset($element['themefile'])) { $themefile = $element['themefile']; } @@ -90,11 +111,17 @@ return $result; } -function pieform_get_value_calendar($element, Pieform $form) { +/** + * Retrieves the value of the calendar as a unix timestamp + * + * @param Pieform $form The form the element is attached to + * @param array $element The element to get the value for + * @return int The unix timestamp represented by the calendar + */ +function pieform_element_calendar_get_value(Pieform $form, $element) { $name = $element['name']; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; - $global = ($form->get_method() == 'get') ? $_GET : $_POST; - if (isset($element['value'])) { return $element['value']; } @@ -107,7 +134,7 @@ $value = strtotime($global[$name]); if ($value === false) { - $form->set_error($name, 'TODO'); + $form->set_error($name, 'TODO (error for invalid calendar value)'); return null; } return $value; @@ -120,6 +147,4 @@ return null; } -// TODO: (possibly, also might need the javascript version for ajax forms) - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[Pieforms-commit] SF.net SVN: pieforms: [207]
pieforms-php5/trunk/src/pieform/elements/ calendar.php
From: <ora...@us...> - 2007-08-01 12:27:19
|
Revision: 207 http://pieforms.svn.sourceforge.net/pieforms/?rev=207&view=rev Author: oracleshinoda Date: 2007-08-01 05:27:19 -0700 (Wed, 01 Aug 2007) Log Message: ----------- German translation for calendar element (thanks to Heinz) Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/calendar.php Modified: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php 2007-08-01 12:24:35 UTC (rev 206) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2007-08-01 12:27:19 UTC (rev 207) @@ -154,7 +154,10 @@ return array( 'en.utf8' => array( 'invalidvalue' => 'Invalid date/time specified' - ) + ), + 'de.utf8' => array( + 'invalidvalue' => 'Datum/Zeit sind falsch festgelegt' + ), ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |