Index: system.js =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.js,v retrieving revision 1.1 diff -u -p -r1.1 system.js --- system.js 13 Feb 2007 07:41:51 -0000 1.1 +++ system.js 16 Feb 2007 23:28:01 -0000 @@ -22,3 +22,37 @@ Drupal.cleanURLsSettingsCheck = function } }}); } + +/** + * Show/hide custom format sections on the date-time settings page. + */ +Drupal.dateTimeAutoAttach = function() { + $("#edit-date-format-short").change(function() { + if ($(this).val() == "custom") { + $("#short-custom-div").show(); + } + else { + $("#short-custom-div").hide(); + } + }); + $("#edit-date-format-medium").change(function() { + if ($(this).val() == "custom") { + $("#medium-custom-div").show(); + } + else { + $("#medium-custom-div").hide(); + } + }); + $("#edit-date-format-long").change(function() { + if ($(this).val() == "custom") { + $("#long-custom-div").show(); + } + else { + $("#long-custom-div").hide(); + } + }); + $("#edit-date-format-short").trigger("change"); + $("#edit-date-format-medium").trigger("change"); + $("#edit-date-format-long").trigger("change"); +} + Index: system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.451 diff -u -p -r1.451 system.module --- system.module 15 Feb 2007 11:40:18 -0000 1.451 +++ system.module 16 Feb 2007 23:28:03 -0000 @@ -774,6 +774,14 @@ function system_rss_feeds_settings() { } function system_date_time_settings() { + drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); + drupal_add_js(' +// Global Killswitch +if (Drupal.jsEnabled) { + $(document).ready(function() { + Drupal.dateTimeAutoAttach(); + }); +}', 'inline'); // Date settings: $zones = _system_zonelist(); @@ -800,6 +808,8 @@ function system_date_time_settings() { $datelongchoices[$f] = format_date(time(), 'custom', $f); } + $datelongchoices['custom'] = $datemediumchoices['custom'] = $dateshortchoices['custom'] = t('Custom format'); + $form['date_default_timezone'] = array( '#type' => 'select', '#title' => t('Default time zone'), @@ -816,30 +826,60 @@ 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', $dateshort[1]); $form['date_format_short'] = array( '#type' => 'select', '#title' => t('Short date format'), - '#default_value' => variable_get('date_format_short', $dateshort[1]), + '#default_value' => (isset($dateshortchoices[$date_format_short])? $date_format_short : 'custom'), '#options' => $dateshortchoices, '#description' => t('The short format of date display.') ); + $form['date_format_short_custom'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Custom short date format'), + '#default_value' => variable_get('date_format_short_custom', ''), + '#description' => t('A user-defined short date format. See the PHP manual for available options.', array('!url' => 'http://php.net/manual/function.date.php')) . (variable_get('date_format_short_custom', '') === ''? '' : t(' This format is currently set to display as %date.', array('%date' => date(variable_get('date_format_short_custom', ''))))), + ); + + $date_format_medium = variable_get('date_format_medium', $datemedium[1]); $form['date_format_medium'] = array( '#type' => 'select', '#title' => t('Medium date format'), - '#default_value' => variable_get('date_format_medium', $datemedium[1]), + '#default_value' => (isset($datemediumchoices[$date_format_medium])? $date_format_medium : 'custom'), '#options' => $datemediumchoices, '#description' => t('The medium sized date display.') ); + $form['date_format_medium_custom'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Custom medium date format'), + '#default_value' => variable_get('date_format_medium_custom', ''), + '#description' => t('A user-defined medium date format. See the PHP manual for available options.', array('!url' => 'http://php.net/manual/function.date.php')) . (variable_get('date_format_medium_custom', '') === ''? '' : t(' This format is currently set to display as %date.', array('%date' => date(variable_get('date_format_medium_custom', ''))))), + ); + + $date_format_long = variable_get('date_format_long', $datelong[0]); $form['date_format_long'] = array( '#type' => 'select', '#title' => t('Long date format'), - '#default_value' => variable_get('date_format_long', $datelong[0]), + '#default_value' => (isset($datelongchoices[$date_format_long])? $date_format_long : 'custom'), '#options' => $datelongchoices, '#description' => t('Longer date format used for detailed display.') ); + $form['date_format_long_custom'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Custom long date format'), + '#default_value' => variable_get('date_format_long_custom', ''), + '#description' => t('A user-defined long date format. See the PHP manual for available options.', array('!url' => 'http://php.net/manual/function.date.php')) . (variable_get('date_format_long_custom', '') === ''? '' : t(' This format is currently set to display as %date.', array('%date' => date(variable_get('date_format_long_custom', ''))))), + ); + $form['date_first_day'] = array( '#type' => 'select', '#title' => t('First day of week'), @@ -851,6 +891,18 @@ function system_date_time_settings() { return system_settings_form($form); } +function system_date_time_settings_validate($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']; + } +} + function system_site_maintenance_settings() { $form['site_offline'] = array(