|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Form element to select a date. |
|
6
|
|
|
* |
|
7
|
|
|
* Class DatePicker |
|
8
|
|
|
*/ |
|
9
|
|
|
class DateTimeRangePicker extends DateRangePicker |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* HTML code to display this datepicker. |
|
13
|
|
|
* |
|
14
|
|
|
* @return string |
|
15
|
|
|
*/ |
|
16
|
|
|
public function toHtml() |
|
17
|
|
|
{ |
|
18
|
|
|
if ($this->_flagFrozen) { |
|
19
|
|
|
return $this->getFrozenHtml(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$id = $this->getAttribute('id'); |
|
23
|
|
|
$value = $this->getValue(); |
|
24
|
|
|
$label = $this->getLabel(); |
|
25
|
|
|
|
|
26
|
|
|
if (!empty($value)) { |
|
27
|
|
|
$value = api_format_date($value, DATE_FORMAT_LONG_NO_DAY); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return ' |
|
31
|
|
|
<div class="input-group"> |
|
32
|
|
|
<span class="input-group-addon cursor-pointer"> |
|
33
|
|
|
<input '.$this->_getAttrString($this->_attributes).'> |
|
34
|
|
|
</span> |
|
35
|
|
|
<p class="form-control disabled" id="'.$id.'_alt_text">'.$value.'</p> |
|
36
|
|
|
<input class="form-control" type="hidden" id="'.$id.'_alt" value="'.$value.'"> |
|
37
|
|
|
<span class="input-group-btn"> |
|
38
|
|
|
<button class="btn btn-default" type="button" |
|
39
|
|
|
title="'.sprintf(get_lang('ResetFieldX'), $this->_label).'"> |
|
40
|
|
|
<span class="fa fa-trash text-danger" aria-hidden="true"></span> |
|
41
|
|
|
<span class="sr-only">'.sprintf(get_lang('ResetFieldX'), $this->_label).'</span> |
|
42
|
|
|
</button> |
|
43
|
|
|
</span> |
|
44
|
|
|
</div> |
|
45
|
|
|
<div class="input-group"> |
|
46
|
|
|
<br /> |
|
47
|
|
|
<p id="'.$id.'_time_range"> |
|
48
|
|
|
<input type="text" name="'.$id.'_time_range_start" class="time start" autocomplete="off"> |
|
49
|
|
|
'.get_lang('To').' |
|
50
|
|
|
<input type="text" name="'.$id.'_time_range_end" class="time end " autocomplete="off"> |
|
51
|
|
|
</p> |
|
52
|
|
|
</div> |
|
53
|
|
|
'.$this->getElementJS(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the necessary javascript for this datepicker. |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
private function getElementJS() |
|
62
|
|
|
{ |
|
63
|
|
|
$js = null; |
|
64
|
|
|
$id = $this->getAttribute('id'); |
|
65
|
|
|
|
|
66
|
|
|
$js .= "<script> |
|
67
|
|
|
$(function() { |
|
68
|
|
|
var txtDate = $('#$id'), |
|
69
|
|
|
inputGroup = txtDate.parents('.input-group'), |
|
70
|
|
|
txtDateAlt = $('#{$id}_alt'), |
|
71
|
|
|
txtDateAltText = $('#{$id}_alt_text'); |
|
72
|
|
|
|
|
73
|
|
|
txtDate |
|
74
|
|
|
.hide() |
|
75
|
|
|
.datepicker({ |
|
76
|
|
|
defaultDate: '".$this->getValue()."', |
|
77
|
|
|
dateFormat: 'yy-mm-dd', |
|
78
|
|
|
altField: '#{$id}_alt', |
|
79
|
|
|
altFormat: \"".get_lang('DateFormatLongNoDayJS')."\", |
|
80
|
|
|
showOn: 'both', |
|
81
|
|
|
buttonImage: '".Display::return_icon('attendance.png', null, [], ICON_SIZE_TINY, true, true)."', |
|
82
|
|
|
buttonImageOnly: true, |
|
83
|
|
|
buttonText: '".get_lang('SelectDate')."', |
|
84
|
|
|
changeMonth: true, |
|
85
|
|
|
changeYear: true, |
|
86
|
|
|
yearRange: 'c-60y:c+5y' |
|
87
|
|
|
}) |
|
88
|
|
|
.on('change', function (e) { |
|
89
|
|
|
txtDateAltText.text(txtDateAlt.val()); |
|
90
|
|
|
}); |
|
91
|
|
|
|
|
92
|
|
|
txtDateAltText.on('click', function () { |
|
93
|
|
|
txtDate.datepicker('show'); |
|
94
|
|
|
}); |
|
95
|
|
|
|
|
96
|
|
|
inputGroup |
|
97
|
|
|
.find('button') |
|
98
|
|
|
.on('click', function (e) { |
|
99
|
|
|
e.preventDefault(); |
|
100
|
|
|
|
|
101
|
|
|
$('#$id, #{$id}_alt').val(''); |
|
102
|
|
|
$('#{$id}_alt_text').html(''); |
|
103
|
|
|
}); |
|
104
|
|
|
|
|
105
|
|
|
$('#".$id."_time_range .time').timepicker({ |
|
106
|
|
|
'showDuration': true, |
|
107
|
|
|
'timeFormat': 'H:i:s', |
|
108
|
|
|
'scrollDefault': 'now', |
|
109
|
|
|
|
|
110
|
|
|
}); |
|
111
|
|
|
var timeOnlyExampleEl = document.getElementById('".$id."_time_range'); |
|
112
|
|
|
var timeOnlyDatepair = new Datepair(timeOnlyExampleEl); |
|
113
|
|
|
|
|
114
|
|
|
}); |
|
115
|
|
|
</script>"; |
|
116
|
|
|
|
|
117
|
|
|
return $js; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|