From f5f3f205e97c2a3219897dd14de7d57659ce1181 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 2 Jul 2011 09:21:30 -0400 Subject: Fixes #3624 input views use class extending rather than overriding --- views/default/input/date.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'views/default/input/date.php') diff --git a/views/default/input/date.php b/views/default/input/date.php index afc40e899..e21a5f8f5 100644 --- a/views/default/input/date.php +++ b/views/default/input/date.php @@ -7,18 +7,23 @@ * @subpackage Core * * @uses $vars['value'] The current value, if any (as a unix timestamp) - * + * @uses $vars['class'] Additional CSS class */ +//@todo popup_calendar deprecated in 1.8. Remove in 2.0 +if (isset($vars['class'])) { + $vars['class'] = "elgg-input-date popup_calendar {$vars['class']}"; +} else { + $vars['class'] = "elgg-input-date popup_calendar"; +} + $defaults = array( 'value' => '', - 'class' => '', + 'disabled' => false, ); $vars = array_merge($defaults, $vars); -//@todo popup_calendar deprecated in 1.8. Remove in 2.0 -$vars['class'] = trim("elgg-input-date popup_calendar {$vars['class']}"); if ($vars['value'] > 86400) { $vars['value'] = date('n/d/Y', $vars['value']); -- cgit v1.2.3 From e88f0a18cf7ad7a029b8c8ba6affdae6f9e079a9 Mon Sep 17 00:00:00 2001 From: cash Date: Mon, 4 Jul 2011 12:01:31 -0400 Subject: Fixes #3560 input/date and output/date support ISO 8601 (YYYY-MM-DD) and Unix timestamps. Need to think about how to handle alternate text formats. --- js/lib/ui.js | 37 +++++++++++++++++++++++++++++++++---- views/default/input/date.php | 39 ++++++++++++++++++++++++++++++--------- views/default/output/date.php | 12 +++++++----- 3 files changed, 70 insertions(+), 18 deletions(-) (limited to 'views/default/input/date.php') diff --git a/js/lib/ui.js b/js/lib/ui.js index fd20acbd1..4426917ed 100644 --- a/js/lib/ui.js +++ b/js/lib/ui.js @@ -20,7 +20,7 @@ elgg.ui.init = function () { $('.elgg-requires-confirmation').live('click', elgg.ui.requiresConfirmation); if ($('.elgg-input-date').length) { - $('.elgg-input-date').datepicker(); + elgg.ui.initDatePicker(); } } @@ -53,7 +53,7 @@ elgg.ui.toggles = function(event) { * targetSelector: The selector used to find the popup * target: The popup jQuery element as found by the selector * source: The jquery element whose click event initiated a popup. - * + * * The return value of the function is used as the options object to .position(). * Handles can also return false to abort the default behvior and override it with their own. * @@ -87,7 +87,7 @@ elgg.ui.popsUp = function(event) { if (!options) { return; } - + // hide if already open if ($target.is(':visible')) { $target.fadeOut(); @@ -120,7 +120,7 @@ elgg.ui.popupClose = function(event) { if (!$target.is(':visible')) { return; } - + // didn't click inside the target if ($eventTarget.closest(target).length > 0) { inTarget = true; @@ -246,5 +246,34 @@ elgg.ui.LoginHandler = function(hook, type, params, options) { return null; }; +/** + * Initialize the date picker + * + * Uses the class .elgg-input-date as the selector. + * + * If the class .elgg-input-timestamp is set on the input element, the onSelect + * method converts the date text to a unix timestamp in seconds. That value is + * stored in a hidden element indicated by the id on the input field. + * + * @return void + */ +elgg.ui.initDatePicker = function() { + $('.elgg-input-date').datepicker({ + // ISO-8601 + dateFormat: 'yy-mm-dd', + onSelect: function(dateText) { + if ($(this).is('.elgg-input-timestamp')) { + // convert to unix timestamp + var date = $.datepicker.parseDate('yy-mm-dd', dateText); + var timestamp = $.datepicker.formatDate('@', date); + timestamp = timestamp / 1000; + + var id = $(this).attr('id'); + $('input[name="' + id + '"]').val(timestamp); + } + } + }); +} + elgg.register_hook_handler('init', 'system', elgg.ui.init); elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.LoginHandler); \ No newline at end of file diff --git a/views/default/input/date.php b/views/default/input/date.php index e21a5f8f5..ceeb2105c 100644 --- a/views/default/input/date.php +++ b/views/default/input/date.php @@ -3,11 +3,18 @@ * Elgg date input * Displays a text field with a popup date picker. * - * @package Elgg - * @subpackage Core + * The elgg.ui JavaScript library initializes the jQueryUI datepicker based + * on the CSS class .elgg-input-date. It uses the ISO 8601 standard for date + * representation: yyyy-mm-dd. * - * @uses $vars['value'] The current value, if any (as a unix timestamp) - * @uses $vars['class'] Additional CSS class + * Unix timestamps are supported by setting the 'timestamp' parameter to true. + * The date is still displayed to the user in a text format but is submitted as + * a unix timestamp in seconds. + * + * @uses $vars['value'] The current value, if any (as a unix timestamp) + * @uses $vars['class'] Additional CSS class + * @uses $vars['timestamp'] Store as a Unix timestamp in seconds. Default = false + * Note: you cannot use an id with the timestamp option. */ //@todo popup_calendar deprecated in 1.8. Remove in 2.0 @@ -20,16 +27,30 @@ if (isset($vars['class'])) { $defaults = array( 'value' => '', 'disabled' => false, + 'timestamp' => false, ); $vars = array_merge($defaults, $vars); +$timestamp = $vars['timestamp']; +unset($vars['timestamp']); + +if ($timestamp) { + echo elgg_view('input/hidden', array( + 'name' => $vars['name'], + 'value' => $vars['value'], + )); -if ($vars['value'] > 86400) { - $vars['value'] = date('n/d/Y', $vars['value']); + $vars['class'] = "{$vars['class']} elgg-input-timestamp"; + $vars['id'] = $vars['name']; + unset($vars['name']); + unset($vars['internalname']); } -$attributes = elgg_format_attributes($vars); +// convert timestamps to text for display +if (is_numeric($vars['value'])) { + $vars['value'] = gmdate('Y/m/d', $vars['value']); +} -?> - /> \ No newline at end of file +$attributes = elgg_format_attributes($vars); +echo ""; diff --git a/views/default/output/date.php b/views/default/output/date.php index fda7668e7..7c98dddc9 100644 --- a/views/default/output/date.php +++ b/views/default/output/date.php @@ -6,10 +6,12 @@ * @package Elgg * @subpackage Core * - * @uses $vars['value'] A UNIX epoch timestamp - * + * @uses $vars['value'] Date as text or a Unix timestamp in seconds */ -if ($vars['value'] > 86400) { - echo date("n/d/Y", $vars['value']); -} \ No newline at end of file +// convert timestamps to text for display +if (is_numeric($vars['value'])) { + $vars['value'] = gmdate('Y/m/d', $vars['value']); +} + +echo $vars['value']; -- cgit v1.2.3