Révision b720ea3e
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/date/date_popup/date_popup.module | ||
---|---|---|
16 | 16 |
* If no time elements are included in the format string, only the date |
17 | 17 |
* textfield will be created. If no date elements are included in the format |
18 | 18 |
* string, only the time textfield, will be created. |
19 |
* |
|
20 | 19 |
*/ |
21 | 20 |
|
22 | 21 |
/** |
... | ... | |
44 | 43 |
/** |
45 | 44 |
* Get the location of the Willington Vega timepicker library. |
46 | 45 |
* |
47 |
* @return |
|
46 |
* @return string
|
|
48 | 47 |
* The location of the library, or FALSE if the library isn't installed. |
49 | 48 |
*/ |
50 | 49 |
function date_popup_get_wvega_path() { |
... | ... | |
94 | 93 |
} |
95 | 94 |
|
96 | 95 |
/** |
97 |
* Create a unique CSS id name and output a single inline JS block for |
|
98 |
* each startup function to call and settings array to pass it. This |
|
99 |
* used to create a unique CSS class for each unique combination of |
|
96 |
* Create a unique CSS id name and output a single inline JS block. |
|
97 |
* |
|
98 |
* For each startup function to call and settings array to pass it. |
|
99 |
* |
|
100 |
* This used to create a unique CSS class for each unique combination of |
|
100 | 101 |
* function and settings, but using classes requires a DOM traversal |
101 | 102 |
* and is much slower than an id lookup. The new approach returns to |
102 | 103 |
* requiring a duplicate copy of the settings/code for every element |
... | ... | |
104 | 105 |
* putting the ids for each unique function/settings combo into |
105 | 106 |
* Drupal.settings and searching for each listed id. |
106 | 107 |
* |
107 |
* @param $pfx
|
|
108 |
* @param string $id
|
|
108 | 109 |
* The CSS class prefix to search the DOM for. |
109 | 110 |
* TODO : unused ? |
110 |
* @param $func |
|
111 |
* The jQuery function to invoke on each DOM element containing the |
|
112 |
* returned CSS class. |
|
113 |
* @param $settings |
|
111 |
* |
|
112 |
* @param string $func |
|
113 |
* The jQuery function to invoke on each DOM element |
|
114 |
* containing the returned CSS class. |
|
115 |
* |
|
116 |
* @param array $settings |
|
114 | 117 |
* The settings array to pass to the jQuery function. |
118 |
* |
|
115 | 119 |
* @returns |
116 |
* The CSS id to assign to the element that should have |
|
117 |
* $func($settings) invoked on it.
|
|
120 |
* The CSS id to assign to the element that should have $func($settings)
|
|
121 |
* invoked on it.
|
|
118 | 122 |
*/ |
119 | 123 |
function date_popup_js_settings_id($id, $func, $settings) { |
120 | 124 |
static $js_added = FALSE; |
... | ... | |
123 | 127 |
// Make sure popup date selector grid is in correct year. |
124 | 128 |
if (!empty($settings['yearRange'])) { |
125 | 129 |
$parts = explode(':', $settings['yearRange']); |
126 |
// Set the default date to 0 or the lowest bound if the date ranges do not include the current year |
|
127 |
// Necessary for the datepicker to render and select dates correctly |
|
128 |
$defaultDate = ($parts[0] > 0 || 0 > $parts[1]) ? $parts[0] : 0; |
|
129 |
$settings += array('defaultDate' => (string) $defaultDate . 'y'); |
|
130 |
// Set the default date to 0 or the lowest bound if |
|
131 |
// the date ranges do not include the current year. |
|
132 |
// Necessary for the datepicker to render and select dates correctly. |
|
133 |
$default_date = ($parts[0] > 0 || 0 > $parts[1]) ? $parts[0] : 0; |
|
134 |
$settings += array('defaultDate' => (string) $default_date . 'y'); |
|
130 | 135 |
} |
131 | 136 |
|
132 | 137 |
if (!$js_added) { |
133 |
drupal_add_js(drupal_get_path('module', 'date_popup') .'/date_popup.js'); |
|
138 |
drupal_add_js(drupal_get_path('module', 'date_popup') . '/date_popup.js');
|
|
134 | 139 |
$js_added = TRUE; |
135 | 140 |
} |
136 | 141 |
|
... | ... | |
140 | 145 |
$id_count[$id] = 0; |
141 | 146 |
} |
142 | 147 |
|
143 |
// It looks like we need the additional id_count for this to |
|
144 |
// work correctly when there are multiple values. |
|
145 |
// $return_id = "$id-$func-popup";
|
|
146 |
$return_id = "$id-$func-popup-". $id_count[$id]++; |
|
148 |
// It looks like we need the additional id_count for this to
|
|
149 |
// work correctly when there are multiple values.
|
|
150 |
// $return_id = "$id-$func-popup";
|
|
151 |
$return_id = "$id-$func-popup-" . $id_count[$id]++;
|
|
147 | 152 |
$js_settings['datePopup'][$return_id] = array( |
148 | 153 |
'func' => $func, |
149 |
'settings' => $settings |
|
154 |
'settings' => $settings,
|
|
150 | 155 |
); |
151 | 156 |
drupal_add_js($js_settings, 'setting'); |
152 | 157 |
return $return_id; |
153 | 158 |
} |
154 | 159 |
|
160 |
/** |
|
161 |
* Date popup theme handler. |
|
162 |
*/ |
|
155 | 163 |
function date_popup_theme() { |
156 | 164 |
return array( |
157 |
'date_popup' => array('render element' => 'element'), |
|
158 |
); |
|
165 |
'date_popup' => array( |
|
166 |
'render element' => 'element', |
|
167 |
), |
|
168 |
); |
|
159 | 169 |
} |
160 | 170 |
|
161 | 171 |
/** |
162 | 172 |
* Implements hook_element_info(). |
163 | 173 |
* |
164 | 174 |
* Set the #type to date_popup and fill the element #default_value with |
165 |
* a date adjusted to the proper local timezone in datetime format (YYYY-MM-DD HH:MM:SS). |
|
175 |
* a date adjusted to the proper local timezone in datetime format |
|
176 |
* (YYYY-MM-DD HH:MM:SS). |
|
166 | 177 |
* |
167 | 178 |
* The element will create two textfields, one for the date and one for the |
168 | 179 |
* time. The date textfield will include a jQuery popup calendar date picker, |
... | ... | |
218 | 229 |
return $type; |
219 | 230 |
} |
220 | 231 |
|
232 |
/** |
|
233 |
* Date popup date granularity. |
|
234 |
*/ |
|
221 | 235 |
function date_popup_date_granularity($element) { |
222 | 236 |
$granularity = date_format_order($element['#date_format']); |
223 | 237 |
return array_intersect($granularity, array('month', 'day', 'year')); |
224 | 238 |
} |
225 | 239 |
|
240 |
/** |
|
241 |
* Date popup time granularity. |
|
242 |
*/ |
|
226 | 243 |
function date_popup_time_granularity($element) { |
227 | 244 |
$granularity = date_format_order($element['#date_format']); |
228 | 245 |
return array_intersect($granularity, array('hour', 'minute', 'second')); |
229 | 246 |
} |
230 | 247 |
|
248 |
/** |
|
249 |
* Date popup date format. |
|
250 |
*/ |
|
231 | 251 |
function date_popup_date_format($element) { |
232 | 252 |
return (date_limit_format($element['#date_format'], date_popup_date_granularity($element))); |
233 | 253 |
} |
234 | 254 |
|
255 |
/** |
|
256 |
* Date popup time format. |
|
257 |
*/ |
|
235 | 258 |
function date_popup_time_format($element) { |
236 | 259 |
return date_popup_format_to_popup_time(date_limit_format($element['#date_format'], date_popup_time_granularity($element)), $element['#timepicker']); |
237 | 260 |
} |
... | ... | |
239 | 262 |
/** |
240 | 263 |
* Element value callback for date_popup element. |
241 | 264 |
*/ |
265 |
// @codingStandardsIgnoreStart |
|
242 | 266 |
function date_popup_element_value_callback($element, $input = FALSE, &$form_state) { |
243 | 267 |
$granularity = date_format_order($element['#date_format']); |
244 | 268 |
$has_time = date_has_time($granularity); |
... | ... | |
266 | 290 |
return $return; |
267 | 291 |
|
268 | 292 |
} |
293 |
// @codingStandardsIgnoreEnd |
|
269 | 294 |
|
270 | 295 |
/** |
271 | 296 |
* Javascript popup element processing. |
297 |
* |
|
272 | 298 |
* Add popup attributes to $element. |
273 | 299 |
*/ |
274 | 300 |
function date_popup_element_process($element, &$form_state, $form) { |
... | ... | |
284 | 310 |
|
285 | 311 |
if (!empty($element['#ajax'])) { |
286 | 312 |
$element['#ajax'] += array( |
287 |
'trigger_as' => array('name' =>$element['#name']), |
|
313 |
'trigger_as' => array( |
|
314 |
'name' => $element['#name'], |
|
315 |
), |
|
288 | 316 |
'event' => 'change', |
289 | 317 |
); |
290 | 318 |
} |
... | ... | |
292 | 320 |
$element['date'] = date_popup_process_date_part($element); |
293 | 321 |
$element['time'] = date_popup_process_time_part($element); |
294 | 322 |
|
323 |
// Make changes if instance is set to be rendered as a regular field. |
|
324 |
if (!empty($element['#instance']['widget']['settings']['no_fieldset']) && $element['#field']['cardinality'] == 1) { |
|
325 |
if (!empty($element['date']) && empty($element['time'])) { |
|
326 |
$element['date']['#title'] = check_plain($element['#instance']['label']); |
|
327 |
$element['date']['#required'] = $element['#required']; |
|
328 |
} |
|
329 |
elseif (empty($element['date']) && !empty($element['time'])) { |
|
330 |
$element['time']['#title'] = check_plain($element['#instance']['label']); |
|
331 |
$element['time']['#required'] = $element['#required']; |
|
332 |
} |
|
333 |
} |
|
334 |
|
|
295 | 335 |
if (isset($element['#element_validate'])) { |
296 | 336 |
array_push($element['#element_validate'], 'date_popup_validate'); |
297 | 337 |
} |
... | ... | |
300 | 340 |
} |
301 | 341 |
|
302 | 342 |
$context = array( |
303 |
'form' => $form, |
|
343 |
'form' => $form,
|
|
304 | 344 |
); |
305 | 345 |
drupal_alter('date_popup_process', $element, $form_state, $context); |
306 | 346 |
|
... | ... | |
313 | 353 |
function date_popup_process_date_part(&$element) { |
314 | 354 |
$granularity = date_format_order($element['#date_format']); |
315 | 355 |
$date_granularity = date_popup_date_granularity($element); |
316 |
if (empty($date_granularity)) return array(); |
|
356 |
if (empty($date_granularity)) { |
|
357 |
return array(); |
|
358 |
} |
|
317 | 359 |
|
318 | 360 |
// The datepicker can't handle zero or negative values like 0:+1 |
319 | 361 |
// even though the Date API can handle them, so rework the value |
320 | 362 |
// we pass to the datepicker to use defaults it can accept (such as +0:+1) |
321 | 363 |
// date_range_string() adds the necessary +/- signs to the range string. |
322 | 364 |
$this_year = date_format(date_now(), 'Y'); |
365 |
// When used as a Views exposed filter widget, $element['#value'] contains an array instead an string. |
|
366 |
// Fill the 'date' string in this case. |
|
367 |
$mock = NULL; |
|
368 |
$callback_values = date_popup_element_value_callback($element, FALSE, $mock); |
|
369 |
if (!isset($element['#value']['date']) && isset($callback_values['date'])) { |
|
370 |
$element['#value']['date'] = $callback_values['date']; |
|
371 |
} |
|
323 | 372 |
$date = ''; |
324 | 373 |
if (!empty($element['#value']['date'])) { |
325 | 374 |
$date = new DateObject($element['#value']['date'], $element['#date_timezone'], date_popup_date_format($element)); |
... | ... | |
336 | 385 |
'closeAtTop' => FALSE, |
337 | 386 |
'speed' => 'immediate', |
338 | 387 |
'firstDay' => intval(variable_get('date_first_day', 0)), |
339 |
//'buttonImage' => base_path() . drupal_get_path('module', 'date_api') ."/images/calendar.png", |
|
340 |
//'buttonImageOnly' => TRUE, |
|
388 |
// 'buttonImage' => base_path() |
|
389 |
// . drupal_get_path('module', 'date_api') ."/images/calendar.png", |
|
390 |
// 'buttonImageOnly' => TRUE, |
|
341 | 391 |
'dateFormat' => date_popup_format_to_popup(date_popup_date_format($element), 'datepicker'), |
342 | 392 |
'yearRange' => $year_range, |
343 | 393 |
// Custom setting, will be expanded in Drupal.behaviors.date_popup() |
... | ... | |
347 | 397 |
// Create a unique id for each set of custom settings. |
348 | 398 |
$id = date_popup_js_settings_id($element['#id'], 'datepicker', $settings); |
349 | 399 |
|
350 |
// Manually build this element and set the value - this will prevent corrupting
|
|
351 |
// the parent value
|
|
400 |
// Manually build this element and set the value - |
|
401 |
// this will prevent corrupting the parent value.
|
|
352 | 402 |
$parents = array_merge($element['#parents'], array('date')); |
353 | 403 |
$sub_element = array( |
354 | 404 |
'#type' => 'textfield', |
355 | 405 |
'#title' => theme('date_part_label_date', array('part_type' => 'date', 'element' => $element)), |
356 | 406 |
'#title_display' => $element['#date_label_position'] == 'above' ? 'before' : 'invisible', |
357 |
'#default_value' => $element['#value']['date'],
|
|
407 |
'#default_value' => date_format_date($date, 'custom', date_popup_date_format($element)),
|
|
358 | 408 |
'#id' => $id, |
359 | 409 |
'#input' => FALSE, |
360 | 410 |
'#size' => !empty($element['#size']) ? $element['#size'] : 20, |
361 | 411 |
'#maxlength' => !empty($element['#maxlength']) ? $element['#maxlength'] : 30, |
362 | 412 |
'#attributes' => $element['#attributes'], |
363 | 413 |
'#parents' => $parents, |
364 |
'#name' => array_shift($parents) . '['. implode('][', $parents) .']',
|
|
414 |
'#name' => array_shift($parents) . '[' . implode('][', $parents) . ']',
|
|
365 | 415 |
'#ajax' => !empty($element['#ajax']) ? $element['#ajax'] : FALSE, |
366 | 416 |
); |
367 | 417 |
$sub_element['#value'] = $sub_element['#default_value']; |
368 |
// TODO, figure out exactly when we want this description. In many places it is not desired. |
|
369 |
$sub_element['#description'] = ' '. t('E.g., @date', array('@date' => date_format_date(date_example_date(), 'custom', date_popup_date_format($element)))); |
|
418 |
// TODO, figure out exactly when we want this description. |
|
419 |
// In many places it is not desired. |
|
420 |
$sub_element['#description'] = ' ' . t('E.g., @date', array( |
|
421 |
'@date' => date_format_date( |
|
422 |
date_example_date(), |
|
423 |
'custom', |
|
424 |
date_popup_date_format($element) |
|
425 |
), |
|
426 |
)); |
|
370 | 427 |
|
371 | 428 |
return $sub_element; |
372 | 429 |
} |
... | ... | |
377 | 434 |
function date_popup_process_time_part(&$element) { |
378 | 435 |
$granularity = date_format_order($element['#date_format']); |
379 | 436 |
$has_time = date_has_time($granularity); |
380 |
if (empty($has_time)) return array(); |
|
437 |
if (empty($has_time)) { |
|
438 |
return array(); |
|
439 |
} |
|
440 |
|
|
441 |
// When used as a Views exposed filter widget, $element['#value'] contains an array instead an string. |
|
442 |
// Fill the 'time' string in this case. |
|
443 |
$mock = NULL; |
|
444 |
$callback_values = date_popup_element_value_callback($element, FALSE, $mock); |
|
445 |
if (!isset($element['#value']['time']) && isset($callback_values['time'])) { |
|
446 |
$element['#value']['time'] = $callback_values['time']; |
|
447 |
} |
|
381 | 448 |
|
382 | 449 |
switch ($element['#timepicker']) { |
383 | 450 |
case 'default': |
... | ... | |
385 | 452 |
$settings = array( |
386 | 453 |
'show24Hours' => strpos($element['#date_format'], 'H') !== FALSE ? TRUE : FALSE, |
387 | 454 |
'showSeconds' => (in_array('second', $granularity) ? TRUE : FALSE), |
388 |
'timeSteps' => array(1, intval($element['#date_increment']), (in_array('second', $granularity) ? $element['#date_increment'] : 0)), |
|
455 |
'timeSteps' => array( |
|
456 |
1, |
|
457 |
intval($element['#date_increment']), |
|
458 |
(in_array('second', $granularity) ? $element['#date_increment'] : 0), |
|
459 |
), |
|
389 | 460 |
'spinnerImage' => '', |
390 | 461 |
'fromTo' => isset($fromto), |
391 |
);
|
|
462 |
); |
|
392 | 463 |
if (strpos($element['#date_format'], 'a') !== FALSE) { |
393 | 464 |
// Then we are using lowercase am/pm. |
394 | 465 |
$settings['ampmNames'] = array('am', 'pm'); |
... | ... | |
397 | 468 |
$settings['ampmPrefix'] = ' '; |
398 | 469 |
} |
399 | 470 |
break; |
471 |
|
|
400 | 472 |
case 'wvega': |
401 | 473 |
$func = 'timepicker'; |
402 |
$time_granularity = array_intersect($granularity, array('hour', 'minute', 'second')); |
|
474 |
$grans = array('hour', 'minute', 'second'); |
|
475 |
$time_granularity = array_intersect($granularity, $grans); |
|
403 | 476 |
$format = date_popup_format_to_popup_time(date_limit_format($element['#date_format'], $time_granularity), 'wvega'); |
404 | 477 |
// The first value in the dropdown list should be the same as the element |
405 | 478 |
// default_value, but it needs to be in JS format (i.e. milliseconds since |
... | ... | |
414 | 487 |
'scrollbar' => TRUE, |
415 | 488 |
); |
416 | 489 |
break; |
490 |
|
|
417 | 491 |
default: |
418 | 492 |
$func = ''; |
419 | 493 |
$settings = array(); |
... | ... | |
423 | 497 |
// Create a unique id for each set of custom settings. |
424 | 498 |
$id = date_popup_js_settings_id($element['#id'], $func, $settings); |
425 | 499 |
|
426 |
// Manually build this element and set the value - this will prevent corrupting
|
|
427 |
// the parent value
|
|
500 |
// Manually build this element and set the value - |
|
501 |
// this will prevent corrupting the parent value.
|
|
428 | 502 |
$parents = array_merge($element['#parents'], array('time')); |
429 | 503 |
$sub_element = array( |
430 | 504 |
'#type' => 'textfield', |
... | ... | |
436 | 510 |
'#maxlength' => 10, |
437 | 511 |
'#attributes' => $element['#attributes'], |
438 | 512 |
'#parents' => $parents, |
439 |
'#name' => array_shift($parents) . '['. implode('][', $parents) .']',
|
|
513 |
'#name' => array_shift($parents) . '[' . implode('][', $parents) . ']',
|
|
440 | 514 |
'#ajax' => !empty($element['#ajax']) ? $element['#ajax'] : FALSE, |
441 | 515 |
); |
442 | 516 |
|
443 | 517 |
$sub_element['#value'] = $sub_element['#default_value']; |
444 | 518 |
|
445 |
// TODO, figure out exactly when we want this description. In many places it is not desired. |
|
519 |
// TODO, figure out exactly when we want this description. |
|
520 |
// In many places it is not desired. |
|
446 | 521 |
$example_date = date_now(); |
447 | 522 |
date_increment_round($example_date, $element['#date_increment']); |
448 |
$sub_element['#description'] = t('E.g., @date', array('@date' => date_format_date($example_date, 'custom', date_popup_time_format($element)))); |
|
523 |
$sub_element['#description'] = t('E.g., @date', array( |
|
524 |
'@date' => date_format_date( |
|
525 |
$example_date, |
|
526 |
'custom', |
|
527 |
date_popup_time_format($element) |
|
528 |
))); |
|
449 | 529 |
|
450 | 530 |
return ($sub_element); |
451 | 531 |
} |
... | ... | |
456 | 536 |
* When used as a Views widget, the validation step always gets triggered, |
457 | 537 |
* even with no form submission. Before form submission $element['#value'] |
458 | 538 |
* contains a string, after submission it contains an array. |
459 |
* |
|
460 | 539 |
*/ |
461 | 540 |
function date_popup_validate($element, &$form_state) { |
462 | 541 |
|
... | ... | |
473 | 552 |
|
474 | 553 |
$input_exists = NULL; |
475 | 554 |
$input = drupal_array_get_nested_value($form_state['values'], $element['#parents'], $input_exists); |
555 |
// If the date is a string, it is not considered valid and can cause problems |
|
556 |
// later on, so just exit out now. |
|
557 |
if (is_string($input)) { |
|
558 |
return; |
|
559 |
} |
|
476 | 560 |
|
477 | 561 |
drupal_alter('date_popup_pre_validate', $element, $form_state, $input); |
478 | 562 |
|
... | ... | |
481 | 565 |
$time_granularity = date_popup_time_granularity($element); |
482 | 566 |
$has_time = date_has_time($granularity); |
483 | 567 |
|
484 |
$label = !empty($element['#date_title']) ? $element['#date_title'] : (!empty($element['#title']) ? $element['#title'] : ''); |
|
485 |
$label = t($label); |
|
486 |
|
|
568 |
// @codingStandardsIgnoreStart |
|
569 |
$label = ''; |
|
570 |
if (!empty($element['#date_title'])) { |
|
571 |
$label = t($element['#date_title']); |
|
572 |
} |
|
573 |
elseif (!empty($element['#title'])) { |
|
574 |
$label = t($element['#title']); |
|
575 |
} |
|
576 |
// @codingStandardsIgnoreEnd |
|
487 | 577 |
$date = date_popup_input_date($element, $input); |
488 | 578 |
|
489 | 579 |
// If the date has errors, display them. |
... | ... | |
517 | 607 |
/** |
518 | 608 |
* Helper function for extracting a date value out of user input. |
519 | 609 |
* |
520 |
* @param autocomplete
|
|
610 |
* @param bool $auto_complete
|
|
521 | 611 |
* Should we add a time value to complete the date if there is no time? |
522 | 612 |
* Useful anytime the time value is optional. |
523 | 613 |
*/ |
... | ... | |
532 | 622 |
|
533 | 623 |
$format = date_popup_date_format($element); |
534 | 624 |
$format .= $has_time ? ' ' . date_popup_time_format($element) : ''; |
535 |
$datetime = $input['date'];
|
|
536 |
$datetime .= $has_time ? ' ' . $input['time'] : '';
|
|
625 |
$datetime = trim($input['date']);
|
|
626 |
$datetime .= $has_time ? ' ' . trim($input['time']) : '';
|
|
537 | 627 |
$date = new DateObject($datetime, $element['#date_timezone'], $format); |
538 | 628 |
if (is_object($date)) { |
539 | 629 |
$date->limitGranularity($granularity); |
... | ... | |
552 | 642 |
return array( |
553 | 643 |
'H:i:s', |
554 | 644 |
'h:i:sA', |
555 |
);
|
|
645 |
); |
|
556 | 646 |
} |
557 | 647 |
|
558 | 648 |
/** |
... | ... | |
561 | 651 |
* TODO Remove any formats not supported by the widget, if any. |
562 | 652 |
*/ |
563 | 653 |
function date_popup_formats() { |
564 |
$formats = str_replace('i', 'i:s', array_keys(system_get_date_formats('short'))); |
|
654 |
// Load short date formats. |
|
655 |
$formats = system_get_date_formats('short'); |
|
656 |
|
|
657 |
// Load custom date formats. |
|
658 |
if ($formats_custom = system_get_date_formats('custom')) { |
|
659 |
$formats = array_merge($formats, $formats_custom); |
|
660 |
} |
|
661 |
|
|
662 |
$formats = str_replace('i', 'i:s', array_keys($formats)); |
|
565 | 663 |
$formats = drupal_map_assoc($formats); |
664 |
|
|
566 | 665 |
return $formats; |
567 | 666 |
} |
568 | 667 |
|
... | ... | |
570 | 669 |
* Recreate a date format string so it has the values popup expects. |
571 | 670 |
* |
572 | 671 |
* @param string $format |
573 |
* a normal date format string, like Y-m-d |
|
672 |
* A normal date format string, like Y-m-d |
|
673 |
* |
|
574 | 674 |
* @return string |
575 | 675 |
* A format string in popup format, like YMD-, for the |
576 | 676 |
* earlier 'calendar' version, or m/d/Y for the later 'datepicker' |
... | ... | |
588 | 688 |
* Recreate a time format string so it has the values popup expects. |
589 | 689 |
* |
590 | 690 |
* @param string $format |
591 |
* a normal time format string, like h:i (a) |
|
691 |
* A normal time format string, like h:i (a) |
|
692 |
* |
|
592 | 693 |
* @return string |
593 |
* a format string that the popup can accept like h:i a
|
|
694 |
* A format string that the popup can accept like h:i a
|
|
594 | 695 |
*/ |
595 | 696 |
function date_popup_format_to_popup_time($format, $timepicker = NULL) { |
596 | 697 |
if (empty($format)) { |
597 | 698 |
$format = 'H:i'; |
598 | 699 |
} |
599 |
$format = str_replace(array('/', '-', ' .', ',', 'F', 'M', 'l', 'z', 'w', 'W', 'd', 'j', 'm', 'n', 'y', 'Y'), '', $format); |
|
700 |
$symbols = array( |
|
701 |
'/', |
|
702 |
'-', |
|
703 |
' .', |
|
704 |
',', |
|
705 |
'F', |
|
706 |
'M', |
|
707 |
'l', |
|
708 |
'z', |
|
709 |
'w', |
|
710 |
'W', |
|
711 |
'd', |
|
712 |
'j', |
|
713 |
'm', |
|
714 |
'n', |
|
715 |
'y', |
|
716 |
'Y', |
|
717 |
); |
|
718 |
$format = str_replace($symbols, '', $format); |
|
600 | 719 |
$format = strtr($format, date_popup_timepicker_format_replacements($timepicker)); |
601 | 720 |
return $format; |
602 | 721 |
} |
... | ... | |
605 | 724 |
* Reconstruct popup format string into normal format string. |
606 | 725 |
* |
607 | 726 |
* @param string $format |
608 |
* a string in popup format, like YMD- |
|
727 |
* A string in popup format, like YMD- |
|
728 |
* |
|
609 | 729 |
* @return string |
610 |
* a normal date format string, like Y-m-d
|
|
730 |
* A normal date format string, like Y-m-d
|
|
611 | 731 |
*/ |
612 | 732 |
function date_popup_popup_to_format($format) { |
613 | 733 |
$replace = array_flip(date_popup_datepicker_format_replacements()); |
... | ... | |
621 | 741 |
* This function returns a map of format replacements required to change any |
622 | 742 |
* input format into one that the given timepicker can support. |
623 | 743 |
* |
624 |
* @param $timepicker |
|
744 |
* @param string $timepicker
|
|
625 | 745 |
* The time entry plugin being used: either 'wvega' or 'default'. |
626 |
* @return |
|
746 |
* |
|
747 |
* @return array |
|
627 | 748 |
* A map of replacements. |
628 | 749 |
*/ |
629 | 750 |
function date_popup_timepicker_format_replacements($timepicker = 'default') { |
630 | 751 |
switch ($timepicker) { |
631 | 752 |
case 'wvega': |
632 |
return array(
|
|
633 |
'a' => 'A', // The wvega timepicker only supports uppercase AM/PM.
|
|
634 |
); |
|
753 |
// The wvega timepicker only supports uppercase AM/PM.
|
|
754 |
return array('a' => 'A');
|
|
755 |
|
|
635 | 756 |
default: |
636 |
return array( |
|
637 |
'G' => 'H', // The default timeEntry plugin requires leading zeros. |
|
638 |
'g' => 'h', |
|
639 |
); |
|
757 |
// The default timeEntry plugin requires leading zeros. |
|
758 |
return array('G' => 'H', 'g' => 'h'); |
|
640 | 759 |
} |
641 | 760 |
} |
642 | 761 |
|
... | ... | |
645 | 764 |
*/ |
646 | 765 |
function date_popup_datepicker_format_replacements() { |
647 | 766 |
return array( |
648 |
'd' => 'dd', |
|
649 |
'j' => 'd', |
|
650 |
'l' => 'DD', |
|
651 |
'D' => 'D', |
|
652 |
'm' => 'mm', |
|
653 |
'n' => 'm', |
|
654 |
'F' => 'MM', |
|
655 |
'M' => 'M', |
|
656 |
'Y' => 'yy', |
|
657 |
'y' => 'y', |
|
767 |
'd' => 'dd',
|
|
768 |
'j' => 'd',
|
|
769 |
'l' => 'DD',
|
|
770 |
'D' => 'D',
|
|
771 |
'm' => 'mm',
|
|
772 |
'n' => 'm',
|
|
773 |
'F' => 'MM',
|
|
774 |
'M' => 'M',
|
|
775 |
'Y' => 'yy',
|
|
776 |
'y' => 'y',
|
|
658 | 777 |
); |
659 | 778 |
} |
660 | 779 |
|
... | ... | |
667 | 786 |
$element = $vars['element']; |
668 | 787 |
$attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array()); |
669 | 788 |
$attributes['class'][] = 'container-inline-date'; |
670 |
// If there is no description, the floating date elements need some extra padding below them. |
|
789 |
// If there is no description, the floating date |
|
790 |
// elements need some extra padding below them. |
|
671 | 791 |
$wrapper_attributes = array('class' => array('date-padding')); |
672 | 792 |
if (empty($element['date']['#description'])) { |
673 | 793 |
$wrapper_attributes['class'][] = 'clearfix'; |
674 | 794 |
} |
675 |
// Add an wrapper to mimic the way a single value field works, for ease in using #states. |
|
795 |
// Add an wrapper to mimic the way a single value field works, |
|
796 |
// for ease in using #states. |
|
676 | 797 |
if (isset($element['#children'])) { |
677 |
$element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) .'>' . $element['#children'] . '</div>'; |
|
798 |
$element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) . '>' . $element['#children'] . '</div>';
|
|
678 | 799 |
} |
679 |
return '<div ' . drupal_attributes($attributes) .'>' . theme('form_element', $element) . '</div>'; |
|
800 |
return '<div ' . drupal_attributes($attributes) . '>' . theme('form_element', $element) . '</div>';
|
|
680 | 801 |
} |
681 | 802 |
|
682 | 803 |
/** |
... | ... | |
707 | 828 |
'#type' => 'select', |
708 | 829 |
'#options' => array( |
709 | 830 |
'default' => t('Use default jQuery timepicker'), |
710 |
'wvega' => t('Use dropdown timepicker'), |
|
711 |
'none' => t('Manual time entry, no jQuery timepicker')
|
|
831 |
'wvega' => t('Use dropdown timepicker'),
|
|
832 |
'none' => t('Manual time entry, no jQuery timepicker'),
|
|
712 | 833 |
), |
713 | 834 |
'#title' => t('Timepicker'), |
714 | 835 |
'#default_value' => variable_get('date_popup_timepicker', $preferred_timepicker), |
... | ... | |
734 | 855 |
} |
735 | 856 |
EOM; |
736 | 857 |
|
737 |
$form['#suffix'] = t('<p>The Date Popup calendar includes some css for IE6 that breaks css validation. Since IE 6 is now superceded by IE 7, 8, and 9, the special css for IE 6 has been removed from the regular css used by the Date Popup. If you find you need that css after all, you can add it back in your theme. Look at the way the Garland theme adds special IE-only css in in its page.tpl.php file. The css you need is:</p>') .'<blockquote><PRE>' . $css .'</PRE></blockquote>';
|
|
858 |
$form['#suffix'] = t('<p>The Date Popup calendar includes some css for IE6 that breaks css validation. Since IE 6 is now superceded by IE 7, 8, and 9, the special css for IE 6 has been removed from the regular css used by the Date Popup. If you find you need that css after all, you can add it back in your theme. Look at the way the Garland theme adds special IE-only css in in its page.tpl.php file. The css you need is:</p>') . '<blockquote><PRE>' . $css . '</PRE></blockquote>';
|
|
738 | 859 |
|
739 | 860 |
return system_settings_form($form); |
740 | 861 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules