Index: modules/system/admin.css =================================================================== RCS file: /cvs/drupal/drupal/modules/system/admin.css,v retrieving revision 1.12 diff -u -p -r1.12 admin.css --- modules/system/admin.css 23 Nov 2006 11:05:46 -0000 1.12 +++ modules/system/admin.css 14 Mar 2007 16:10:56 -0000 @@ -96,4 +96,26 @@ table.system-status-report tr.ok th { } .theme-settings-bottom { clear: both; -} \ No newline at end of file +} + +/* +** Date and time settings page +*/ +div.date-container { + overflow: auto; +} + +div.date-container > div { + float: left; +} + +div.custom-format { + display: none; +} + +div.date-container #short-custom, +div.date-container #medium-custom, +div.date-container #long-custom { + margin-left: 15px; + width: 50%; +} Index: modules/system/system.js =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.js,v retrieving revision 1.1 diff -u -p -r1.1 system.js --- modules/system/system.js 13 Feb 2007 07:41:51 -0000 1.1 +++ modules/system/system.js 14 Mar 2007 16:10:56 -0000 @@ -22,3 +22,28 @@ Drupal.cleanURLsSettingsCheck = function } }}); } + +/** + * Show/hide custom format sections on the date-time settings page. + */ +Drupal.dateTimeAutoAttach = function() { + // Show/hide custom format depending on the select's value. + $(".date-container select").change(function() { + $(this).parents(".date-container").children(".custom-format")[$(this).val() == "custom" ? "show" : "hide"](); + }); + + // Hide the labels to simplify the UI. + $(".custom-format .form-item label").css("visibility", "hidden"); + + // Attach keyup handler to custom format inputs. + $(".custom-format input").keyup(function() { + var input = $(this); + var url = Drupal.settings.dateTime.lookup +(Drupal.settings.dateTime.lookup.match(/\?q=/)? "&format=" : "?q=") + Drupal.encodeURIComponent(input.val()); + $.getJSON(url, function(data) { + $(".description span", input.parent()).html(data.response); + }); + }); + + // Trigger the event handler to show the form input if necessary. + $(".date-container select").trigger("change"); +} Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.454 diff -u -p -r1.454 system.module --- modules/system/system.module 12 Mar 2007 13:01:10 -0000 1.454 +++ modules/system/system.module 14 Mar 2007 16:10:59 -0000 @@ -243,6 +243,11 @@ function system_menu() { 'page callback' => 'drupal_get_form', 'page arguments' => array('system_date_time_settings'), ); + $items['admin/settings/date-time/lookup'] = array( + 'title' => t('Date and time lookup'), + 'type' => MENU_CALLBACK, + 'page callback' => 'system_date_time_lookup', + ); $items['admin/settings/site-maintenance'] = array( 'title' => t('Site maintenance'), 'description' => t('Take the site off-line for maintenance or bring it back online.'), @@ -774,32 +779,43 @@ function system_rss_feeds_settings() { } function system_date_time_settings() { + drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); + drupal_add_js(array('dateTime' => array('lookup' => url('admin/settings/date-time/lookup'))), 'setting'); + drupal_add_js(' +// Global Killswitch +if (Drupal.jsEnabled) { + $(document).ready(function() { + Drupal.dateTimeAutoAttach(); + }); +}', 'inline'); // Date settings: $zones = _system_zonelist(); // Date settings: possible date formats - $dateshort = array('Y-m-d H:i', 'm/d/Y - H:i', 'd/m/Y - H:i', 'Y/m/d - H:i', + $date_short = array('Y-m-d H:i', 'm/d/Y - H:i', 'd/m/Y - H:i', 'Y/m/d - H:i', 'd.m.Y - H:i', 'm/d/Y - g:ia', 'd/m/Y - g:ia', 'Y/m/d - g:ia', 'M j Y - H:i', 'j M Y - H:i', 'Y M j - H:i', 'M j Y - g:ia', 'j M Y - g:ia', 'Y M j - g:ia'); - $datemedium = array('D, Y-m-d H:i', 'D, m/d/Y - H:i', 'D, d/m/Y - H:i', + $date_medium = array('D, Y-m-d H:i', 'D, m/d/Y - H:i', 'D, d/m/Y - H:i', 'D, Y/m/d - H:i', 'F j, Y - H:i', 'j F, Y - H:i', 'Y, F j - H:i', 'D, m/d/Y - g:ia', 'D, d/m/Y - g:ia', 'D, Y/m/d - g:ia', 'F j, Y - g:ia', 'j F Y - g:ia', 'Y, F j - g:ia', 'j. F Y - G:i'); - $datelong = array('l, F j, Y - H:i', 'l, j F, Y - H:i', 'l, Y, F j - H:i', + $date_long = array('l, F j, Y - H:i', 'l, j F, Y - H:i', 'l, Y, F j - H:i', 'l, F j, Y - g:ia', 'l, j F Y - g:ia', 'l, Y, F j - g:ia', 'l, j. F Y - G:i'); // Date settings: construct choices for user - foreach ($dateshort as $f) { - $dateshortchoices[$f] = format_date(time(), 'custom', $f); + foreach ($date_short as $f) { + $date_short_choices[$f] = format_date(time(), 'custom', $f); } - foreach ($datemedium as $f) { - $datemediumchoices[$f] = format_date(time(), 'custom', $f); + foreach ($date_medium as $f) { + $date_medium_choices[$f] = format_date(time(), 'custom', $f); } - foreach ($datelong as $f) { - $datelongchoices[$f] = format_date(time(), 'custom', $f); + foreach ($date_long as $f) { + $date_long_choices[$f] = format_date(time(), 'custom', $f); } + $date_long_choices['custom'] = $date_medium_choices['custom'] = $date_short_choices['custom'] = t('Custom format'); + $form['date_default_timezone'] = array( '#type' => 'select', '#title' => t('Default time zone'), @@ -816,30 +832,68 @@ function system_date_time_settings() { '#description' => t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.') ); + $date_format_short = variable_get('date_format_short', $date_short[1]); $form['date_format_short'] = array( + '#prefix' => '
', + '#suffix' => '
', '#type' => 'select', '#title' => t('Short date format'), - '#default_value' => variable_get('date_format_short', $dateshort[1]), - '#options' => $dateshortchoices, + '#default_value' => (isset($date_short_choices[$date_format_short]) ? $date_format_short : 'custom'), + '#options' => $date_short_choices, '#description' => t('The short format of date display.') ); + $default_short_custom = variable_get('date_format_short_custom', (isset($date_short_choices[$date_format_short]) ? $date_format_short : '')); + $form['date_format_short_custom'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Custom short date format'), + '#default_value' => $default_short_custom, + '#description' => t('A user-defined short date format. See the PHP manual for available options. This format is currently set to display as %date.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_short_custom))), + ); + + $date_format_medium = variable_get('date_format_medium', $date_medium[1]); $form['date_format_medium'] = array( + '#prefix' => '
', + '#suffix' => '
', '#type' => 'select', '#title' => t('Medium date format'), - '#default_value' => variable_get('date_format_medium', $datemedium[1]), - '#options' => $datemediumchoices, - '#description' => t('The medium sized date display.') + '#default_value' => (isset($datemediumchoices[$date_format_medium]) ? $date_format_medium : 'custom'), + '#options' => $date_medium_choices, + '#description' => t('The medium sized date display.'), + ); + $default_medium_custom = variable_get('date_format_medium_custom', (isset($date_medium_choices[$date_format_medium]) ? $date_format_medium : '')); + $form['date_format_medium_custom'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Custom medium date format'), + '#default_value' => $default_medium_custom, + '#description' => t('A user-defined medium date format. See the PHP manual for available options. This format is currently set to display as %date.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_medium_custom))), ); + $date_format_long = variable_get('date_format_long', $date_long[0]); $form['date_format_long'] = array( + '#prefix' => '
', + '#suffix' => '
', '#type' => 'select', '#title' => t('Long date format'), - '#default_value' => variable_get('date_format_long', $datelong[0]), - '#options' => $datelongchoices, + '#default_value' => (isset($date_long_choices[$date_format_long]) ? $date_format_long : 'custom'), + '#options' => $date_long_choices, '#description' => t('Longer date format used for detailed display.') ); + $default_long_custom = variable_get('date_format_long_custom', (isset($date_long_choices[$date_format_long]) ? $date_format_long : '')); + $form['date_format_long_custom'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Custom long date format'), + '#default_value' => $default_long_custom, + '#description' => t('A user-defined long date format. See the PHP manual for available options. This format is currently set to display as %date.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_long_custom))), + ); + $form['date_first_day'] = array( '#type' => 'select', '#title' => t('First day of week'), @@ -851,6 +905,29 @@ function system_date_time_settings() { return system_settings_form($form); } +function system_date_time_settings_submit($form_id, $form_values) { + if ($form_values['date_format_short'] == 'custom') { + $form_values['date_format_short'] = $form_values['date_format_short_custom']; + } + if ($form_values['date_format_medium'] == 'custom') { + $form_values['date_format_medium'] = $form_values['date_format_medium_custom']; + } + if ($form_values['date_format_long'] == 'custom') { + $form_values['date_format_long'] = $form_values['date_format_long_custom']; + } + return system_settings_form_submit($form_id, $form_values); +} + +/** + * Return the date for a given format string via Ajax. + */ +function system_date_time_lookup() { + $format = isset($_GET['format']) ? $_GET['format'] : array_pop(array_slice(explode('&', $_GET['q'], 2), 1)); + $result = format_date(time(), 'custom', $format); + echo drupal_to_js(array('response' => $result)); + exit; +} + function system_site_maintenance_settings() { $form['site_offline'] = array(