-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.datetimepicker-widget.php
64 lines (56 loc) · 1.96 KB
/
main.datetimepicker-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Module DateTimePicker Wigdet (jQuery plugin)
* https://github.com/vbkunin/datetimepicker-widget-for-itop
*
* @author Vladimir Kunin <v.b.kunin@gmail.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
class DateTimePickerJQueryPlugIn implements iPageUIExtension
{
public function GetBannerHtml(iTopWebPage $oPage)
{
if (utils::GetConfig()->GetModuleSetting('datetimepicker-widget', 'enabled', false)) self::AddScript($oPage);
}
public function GetNorthPaneHtml(iTopWebPage $oPage)
{
}
public function GetSouthPaneHtml(iTopWebPage $oPage)
{
}
public static function AddScript($oPage) {
$sConfJSON = json_encode(utils::GetConfig()->GetModuleSetting('datetimepicker-widget', 'default'));
$oPage->add_linked_stylesheet(utils::GetAbsoluteUrlModulesRoot().'datetimepicker-widget/css/jquery.datetimepicker.css');
$oPage->add_linked_script(utils::GetAbsoluteUrlModulesRoot().'datetimepicker-widget/js/jquery.datetimepicker.js');
$oPage->add_ready_script(
<<< EOF
var config = $sConfJSON;
try {
$(".datetime-pick, .date-pick")
.datepicker("destroy")
.each(function () {
var img = document.createElement('img');
img.className = "calendar";
img.name = this.name;
img.src = "../images/calendar.png";
$(this).after(img);
if (this.className == 'datetime-pick') {
config.format = 'Y-m-d H:i';
} else if (this.className == 'date-pick') {
config.format = 'Y-m-d';
config.timepicker = false;
config.closeOnDateSelect = true;
}
$(this).datetimepicker(config);
});
$('.calendar').click(function () {
$(".datetime-pick[name='" + this.name + "'], .date-pick[name='" + this.name + "']").datetimepicker('show');
});
} catch (err) {
// console.log(err);
}
EOF
);
}
}
?>