You are here

function date_popup_process_time in Date 6

Same name and namespace in other branches
  1. 5.2 date_popup/date_popup.module \date_popup_process_time()
  2. 6.2 date_popup/date_popup.module \date_popup_process_time()
  3. 7 date_popup/date_popup.module \date_popup_process_time()

Process the time portion of the element.

1 call to date_popup_process_time()
date_popup_process in date_popup/date_popup.module
Javascript popup element processing. Add popup attributes to $element.

File

date_popup/date_popup.module, line 248
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_process_time(&$element, $edit = NULL, $date = NULL) {
  $granularity = date_format_order($element['#date_format']);
  $time_granularity = array_intersect($granularity, array(
    'hour',
    'minute',
    'second',
  ));
  $time_format = date_popup_format_to_popup_time(date_limit_format($element['#date_format'], $time_granularity));
  if (empty($time_granularity)) {
    return array();
  }
  $spinner_text = array(
    t('Now'),
    t('Previous field'),
    t('Next field'),
    t('Increment'),
    t('Decrement'),
  );
  $settings = "\n" . "show24Hours: " . (strpos($element['#date_format'], 'H') ? 'true' : 'false') . ", \n" . "showSeconds: " . (in_array('second', $granularity) ? 'true' : 'false') . ", \n" . "timeSteps: [1," . $element['#date_increment'] . "," . (in_array('second', $granularity) ? $element['#date_increment'] : 0) . "], \n" . "spinnerImage: ''\n";

  // This is just a placeholder to indicate the method to constrain from and to times.
  // Not yet implemented.
  if (isset($fromto)) {
    $settings . +", minTime: (input.id == 'tTo' ? getTime(\$('#tFrom').val()) : null), \n" . "maxTime: (input.id == 'tFrom' ? getTime(\$('#tTo').val()) : null)} ";
  }
  drupal_add_js('// Global Killswitch
    if (Drupal.jsEnabled) {
      $(document).ready(function() {$(\'.jquery-timeentry-' . $element['#id'] . '\').timeEntry({' . $settings . '});
      })}', 'inline');

  // Create a unique class for each element so we can use custom settings.
  $sub_element = array(
    '#type' => 'textfield',
    '#default_value' => is_object($date) ? date_format($date, $time_format) : '',
    '#attributes' => array(
      'class' => 'jquery-timeentry-' . $element['#id'],
    ),
    '#size' => 10,
    '#maxlength' => 10,
  );

  // TODO, figure out exactly when we want this description. In many places it is not desired.
  $element['#description'] .= t('  @date', array(
    '@date' => date($time_format, time()),
  ));
  return $sub_element;
}