[evolvis-commits] r17730: add datepicker backend code, so it can already be used/tested↵ but no conversion of existing date-I/O-code to it yet

mirabilos at evolvis.org mirabilos at evolvis.org
Wed Nov 30 12:03:32 CET 2011


Author: mirabilos
Date: 2011-11-30 12:03:32 +0100 (Wed, 30 Nov 2011)
New Revision: 17730

Added:
   trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php
Removed:
   trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php
Modified:
   trunk/gforge_base/evolvisforge-5.1/src/debian/changelog
   trunk/gforge_base/evolvisforge-5.1/src/packaging/links/web-apache2
Log:
add datepicker backend code, so it can already be used/tested
but no conversion of existing date-I/O-code to it yet

[#2214] javascript-control-datepicker pending merges:
  Thorsten Glaser 2011-11-30 use 5.1 $HTML API
    Thorsten Glaser 2011-11-30 add from 4.8
    Roland Mas 2011-11-16 stupid debhelper
    Roland Mas 2011-11-16 [#1754] pull in the icon we will use with DatePicker


Added: trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php	2011-11-30 11:03:32 UTC (rev 17730)
@@ -0,0 +1,262 @@
+<?php
+/**
+ * Date operations for FusionForge
+ *
+ * Copyright © 2010, 2011
+ *	Thorsten “mirabilos” Glaser <t.glaser at tarent.de>
+ * All rights reserved.
+ *
+ * This file is part of FusionForge. FusionForge 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.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *-
+ * API documentation:
+ *
+ * datepick_prepare(); // before emitting the Theme header
+ * datepick_emit('fieldname'[, 'value', usetime?, 'type', attrs()]);
+ * // type: default (prefs), locdef (locale), or a specific one
+ * $timet = datepick_parse(getStringFromRequest('fieldname'));
+ * $value = datepick_format($timet[, usetime?, 'type']);
+ * // these two convert back and forth between time_t and string
+ */
+
+/*-
+ * list of acceptable datepicker locales;
+ * must be defined in gforge/www/js/datepicker.js
+ */
+$datepick_locales = array(
+	'locdef' => _('Locale dependent default'),
+	'american' => _('American (m/d/y, English labels, 12 hour clock, week starts on Sunday)'),
+	'dmy' => _('Day.Month.Year with English labels'),
+	'mdy' => _('Month/Day/Year with English labels'),
+	'ymd' => _('Year-Month-Day with English labels'),
+	'dmy_es' => _('Day.Month.Year with Spanish labels'),
+	'mdy_es' => _('Month/Day/Year with Spanish labels'),
+	'ymd_es' => _('Year-Month-Day with Spanish labels'),
+	'dmy_de' => _('Day.Month.Year with German labels'),
+	'mdy_de' => _('Month/Day/Year with German labels'),
+	'ymd_de' => _('Year-Month-Day with German labels'),
+	'dmy_fr' => _('Day.Month.Year with French labels'),
+	'mdy_fr' => _('Month/Day/Year with French labels'),
+	'ymd_fr' => _('Year-Month-Day with French labels'),
+	'dmy_it' => _('Day.Month.Year with Italian labels'),
+	'mdy_it' => _('Month/Day/Year with Italian labels'),
+	'ymd_it' => _('Year-Month-Day with Italian labels'),
+	'dmy_nl' => _('Day.Month.Year with Dutch labels'),
+	'mdy_nl' => _('Month/Day/Year with Dutch labels'),
+	'ymd_nl' => _('Year-Month-Day with Dutch labels'),
+	'dmy_pl' => _('Day.Month.Year with Polish labels'),
+	'mdy_pl' => _('Month/Day/Year with Polish labels'),
+	'ymd_pl' => _('Year-Month-Day with Polish labels'),
+	'dmy_pt' => _('Day.Month.Year with Portuguese labels'),
+	'mdy_pt' => _('Month/Day/Year with Portuguese labels'),
+	'ymd_pt' => _('Year-Month-Day with Portuguese labels'),
+	'dmy_ro' => _('Day.Month.Year with Romanian labels'),
+	'mdy_ro' => _('Month/Day/Year with Romanian labels'),
+	'ymd_ro' => _('Year-Month-Day with Romanian labels'),
+	'dmy_bg' => _('Day.Month.Year with Bulgarian labels'),
+	'mdy_bg' => _('Month/Day/Year with Bulgarian labels'),
+	'ymd_bg' => _('Year-Month-Day with Bulgarian labels'),
+	'dmy_ru' => _('Day.Month.Year with Russian labels'),
+	'mdy_ru' => _('Month/Day/Year with Russian labels'),
+	'ymd_ru' => _('Year-Month-Day with Russian labels'),
+	'dmy_hu' => _('Day.Month.Year with Hungarian labels'),
+	'mdy_hu' => _('Month/Day/Year with Hungarian labels'),
+	'ymd_hu' => _('Year-Month-Day with Hungarian labels'),
+	'dmy_no' => _('Day.Month.Year with Norwegian labels'),
+	'mdy_no' => _('Month/Day/Year with Norwegian labels'),
+	'ymd_no' => _('Year-Month-Day with Norwegian labels'),
+    );
+
+/* must match definitions in datepicker.js for reverse */
+$datepick_locales_fmtstr = array(
+	'american' => '%m/%d/%Y',
+	'dmy' => '%d.%m.%Y',
+	'mdy' => '%m/%d/%Y',
+	'ymd' => '%Y-%m-%d',
+	'dmy_es' => '%d.%m.%Y',
+	'mdy_es' => '%m/%d/%Y',
+	'ymd_es' => '%Y-%m-%d',
+	'dmy_de' => '%d.%m.%Y',
+	'mdy_de' => '%m/%d/%Y',
+	'ymd_de' => '%Y-%m-%d',
+	'dmy_fr' => '%d.%m.%Y',
+	'mdy_fr' => '%m/%d/%Y',
+	'ymd_fr' => '%Y-%m-%d',
+	'dmy_it' => '%d.%m.%Y',
+	'mdy_it' => '%m/%d/%Y',
+	'ymd_it' => '%Y-%m-%d',
+	'dmy_nl' => '%d.%m.%Y',
+	'mdy_nl' => '%m/%d/%Y',
+	'ymd_nl' => '%Y-%m-%d',
+	'dmy_pl' => '%d.%m.%Y',
+	'mdy_pl' => '%m/%d/%Y',
+	'ymd_pl' => '%Y-%m-%d',
+	'dmy_pt' => '%d.%m.%Y',
+	'mdy_pt' => '%m/%d/%Y',
+	'ymd_pt' => '%Y-%m-%d',
+	'dmy_ro' => '%d.%m.%Y',
+	'mdy_ro' => '%m/%d/%Y',
+	'ymd_ro' => '%Y-%m-%d',
+	'dmy_bg' => '%d.%m.%Y',
+	'mdy_bg' => '%m/%d/%Y',
+	'ymd_bg' => '%Y-%m-%d',
+	'dmy_ru' => '%d.%m.%Y',
+	'mdy_ru' => '%m/%d/%Y',
+	'ymd_ru' => '%Y-%m-%d',
+	'dmy_hu' => '%d.%m.%Y',
+	'mdy_hu' => '%m/%d/%Y',
+	'ymd_hu' => '%Y-%m-%d',
+	'dmy_no' => '%d.%m.%Y',
+	'mdy_no' => '%m/%d/%Y',
+	'ymd_no' => '%Y-%m-%d',
+    );
+
+
+/* emit appropriate header lines for using DatePicker */
+function datepick_prepare() {
+	global $HTML;
+
+	$HTML->addJavascript('/js/prototype.js');
+	$HTML->addStylesheet('/themes/css/datepicker.css');
+	$HTML->addJavascript('/js/prototype-base-extensions.js');
+	$HTML->addJavascript('/js/prototype-date-extensions.js');
+	$HTML->addJavascript('/js/datepicker.js');
+
+	$HTML->footer_hooks[] = 'datepick__footer_hook';
+}
+$datepick_used = array();
+
+/* emit a datepick input field */
+function datepick_emit($fieldname, $fieldvalue='', $usetime=false,
+    $type='default', $attrs=array()) {
+	/* 'default' locale: look at user prefs, fallback to 'locdef' */
+	/* 'locdef' locale: look at gettext, fallback to 'american' */
+	$type = datepick__type($type);
+
+	$attrs['class'] = trim(util_ifsetor($attrs['class'], "") . ' ' .
+	    ($usetime ? 'datetime_' : 'date_') . $type);
+
+	echo '<input type="text" name="' . $fieldname .
+	    '" value="' . $fieldvalue . '" ';
+	foreach ($attrs as $k => $v) {
+		echo $k . '="' . $v . '" ';
+	}
+	echo '/>';
+
+	global $datepick_used;
+	$datepick_used[($usetime ? 'datetime_' : 'date_') . $type] =
+	    array('type' => $type, 'usetime' => $usetime);
+}
+
+/* parse y-m-d [h:m] or d.m.y [h:m] or m/d/y [h:m] format into time_t (int) */
+function datepick_parse($text) {
+	$text = trim($text);
+	$hmin = "";
+
+	if (preg_match('#^[0-9/.-]{5,10} [0-9]{1,2}:[0-9]{1,2}$#', $text)) {
+		$a = explode(' ', $text);
+		$text = trim($a[0]);
+		$hmin = " " . trim($a[1]);
+	}
+
+	if (preg_match('#^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}$#', $text)) {
+		/* ISO 8601 */
+		$a = explode('-', $text);
+		$y = $a[0];
+		$m = $a[1];
+		$d = $a[2];
+	} else if (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,4}$#', $text)) {
+		/* German */
+		$a = explode('.', $text);
+		$y = $a[2];
+		$m = $a[1];
+		$d = $a[0];
+	} else if (preg_match('#^[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,4}$#', $text)) {
+		/* American */
+		$a = explode('/', $text);
+		$y = $a[2];
+		$m = $a[0];
+		$d = $a[1];
+	} else
+		return false;
+	return (strtotime($y."-".$m."-".$d.$hmin));
+}
+
+/* convert time_t into value suitable for emitting a datepicker */
+function datepick_format($timet, $usetime=false, $type='default') {
+	global $datepick_locales_fmtstr;
+
+	$fmtstr = $datepick_locales_fmtstr[datepick__type($type)];
+	if ($usetime)
+		$fmtstr .= ' %H:%M';
+	return (strftime($fmtstr, $timet));
+}
+
+
+/* internal function */
+function datepick__footer_hook($params, $T) {
+	global $datepick_used;
+
+	if (!$datepick_used)
+		return;
+
+	echo '
+<script language="JavaScript" type="text/javascript">//<![CDATA[
+	function createPickers() {';
+
+	foreach ($datepick_used as $k => $v) {
+		echo '
+		$(document.body).select(' . "'input." . $k . "').each(
+			function(e) {
+				new Control.DatePicker(e, {
+					'locale': '" . $v['type'] . "'";
+		if ($v['usetime']) {
+			echo ",
+					'timePicker': true";
+		}
+		echo ",
+					'icon': '/images/office-calendar.png'
+				    });
+			}
+		    );";
+	}
+	echo '
+	}
+	Event.observe(window, "load", createPickers);
+//]]></script>';
+}
+
+/* internal function: convert $type to JS type */
+function datepick__type($type='default') {
+	global $datepick_locales, $G_SESSION;
+
+	if ($type == 'default' && isset($G_SESSION) && $G_SESSION) {
+		$v = $G_SESSION->getPreference('datepick_format');
+		if (isset($v))
+			$type = $v;
+	}
+	if (!isset($datepick_locales[$type])) {
+		$type = 'locdef';
+	}
+
+	if ($type == 'locdef') {
+		$type = _('locale-dependent-default-datepick-format');
+	}
+	if (!isset($datepick_locales[$type]) || $type == 'locdef') {
+		$type = 'american';
+	}
+
+	return ($type);
+}

Modified: trunk/gforge_base/evolvisforge-5.1/src/debian/changelog
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/debian/changelog	2011-11-28 14:53:23 UTC (rev 17729)
+++ trunk/gforge_base/evolvisforge-5.1/src/debian/changelog	2011-11-30 11:03:32 UTC (rev 17730)
@@ -31,12 +31,13 @@
   * Unbreak Project Summary widget changes
   * [#1842] disambiguate some texts
   * www/tracker: {detail,mod{,-limited},add}.php → item.php
+  * Add DatePicker control (backing code; no conversion yet)
 
   [ Mike Esser ]
   * [#1850] Fix merge glitch
   * [#1859] [#1906] Port code from Evolvis 4.8 to 5.1
 
- -- Thorsten Glaser <t.glaser at tarent.de>  Wed, 09 Nov 2011 10:57:22 +0100
+ -- Thorsten Glaser <t.glaser at tarent.de>  Wed, 30 Nov 2011 11:42:38 +0100
 
 fusionforge (5.1.1-3) UNRELEASED; urgency=low
 

Modified: trunk/gforge_base/evolvisforge-5.1/src/packaging/links/web-apache2
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/packaging/links/web-apache2	2011-11-28 14:53:23 UTC (rev 17729)
+++ trunk/gforge_base/evolvisforge-5.1/src/packaging/links/web-apache2	2011-11-30 11:03:32 UTC (rev 17730)
@@ -5,4 +5,4 @@
 usr/share/javascript/jquery usr/share/@OLDPACKAGE@/www/scripts/jquery
 usr/share/javascript/jquery-tipsy usr/share/@OLDPACKAGE@/www/scripts/jquery-tipsy
 usr/share/javascript/jquery-ui usr/share/@OLDPACKAGE@/www/scripts/jquery-ui
-usr/share/icons/Tango/16x16/apps/office-calendar.png usr/share/gforge/www/images/office-calendar.png
+usr/share/icons/Tango/16x16/apps/office-calendar.png usr/share/@OLDPACKAGE@/www/images/office-calendar.png



More information about the evolvis-commits mailing list