/** * Fetch a calendar element * * @param string $name Element name * @param string $value Element value * @param object &$node XMLElement node object containing the settings for the element * @param string $control_name Control name * @return string */ public function fetchElement($name, $value, &$node, $control_name) { // Load the calendar behavior Behavior::calendar(); $format = $node->attributes('format') ? $node->attributes('format') : '%Y-%m-%d'; $class = $node->attributes('class') ? $node->attributes('class') : 'inputbox'; return Input::calendar($name, $value, array('format' => $format, 'class' => $class)); }
/** * Displays a calendar control field * * @param string $name * @param string $value * @param array $options * @return string HTML markup for a calendar field */ public static function calendar($name, $value = null, $options = array()) { static $done; if ($done === null) { $done = array(); } $readonly = isset($options['readonly']) && $options['readonly'] == 'readonly'; $disabled = isset($options['disabled']) && $options['disabled'] == 'disabled'; $format = 'yy-mm-dd'; if (isset($options['format'])) { $format = $options['format'] ? $options['format'] : $format; unset($options['format']); } if (!isset($options['class'])) { $options['class'] = 'calendar-field'; } else { $options['class'] = ' calendar-field'; } if (!$readonly && !$disabled) { // Load the calendar behavior Behavior::calendar(); Behavior::tooltip(); $id = self::getIdAttribute($name, $options); // Only display the triggers once for each control. if (!in_array($id, $done)) { $format = $format == 'Y-m-d H:i:s' || $format == '%Y-%m-%d %H:%M:%S' || $format == 'Y-m-d' ? 'yy-mm-dd' : $format; \App::get('document')->addScriptDeclaration("\n\t\t\t\t\tjQuery(document).ready(function(\$){\n\t\t\t\t\t\t\$('#" . $id . "').datetimepicker({\n\t\t\t\t\t\t\tduration: '',\n\t\t\t\t\t\t\tshowTime: true,\n\t\t\t\t\t\t\tconstrainInput: false,\n\t\t\t\t\t\t\tstepMinutes: 1,\n\t\t\t\t\t\t\tstepHours: 1,\n\t\t\t\t\t\t\taltTimeField: '',\n\t\t\t\t\t\t\ttime24h: true,\n\t\t\t\t\t\t\tdateFormat: '" . $format . "',\n\t\t\t\t\t\t\ttimeFormat: 'HH:mm:00'\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t"); $done[] = $id; } return '<span class="input-datetime">' . self::text($name, $value, $options) . '</span>'; } else { $value = 0 !== (int) $value ? with(new Date($value))->format('Y-m-d H:i:s') : ''; return self::text($name . 'disabled', 0 !== (int) $value ? with(new Date($value))->format('Y-m-d H:i:s') : '', $options) . self::hidden($name, $value, $options); } }