-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdateTimePicker.js
More file actions
165 lines (150 loc) · 5.97 KB
/
dateTimePicker.js
File metadata and controls
165 lines (150 loc) · 5.97 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
freeboard.addStyle('.list-unstyled','padding-left:5px;');
freeboard.addStyle('.collapse','display:none;');
freeboard.addStyle('.collapse.in',"display:block;");
var timePickerWidget = function (settings) {
var self = this;
var titleElement = $('<h2 class="section-title"></h2>');
var wrapperElement = $('<div class="">');
var pickerElement = $(`<div style="margin-bottom:10px;">
<h2 class='section-title' style="margin-bottom:2px;">Start Date/Time:</h2>
<input type='text' class="form-control" style="width:200px" id='datetimepicker6'/>
</div>
<div style="width:200px; margin-bottom:10px;">
<h2 class='section-title' style="margin-bottom:2px">End Date/Time:</h2>
<input type='text' class="form-control" style="width:200px;" id='datetimepicker7'/>
</div>`);
var buttonElement = $("<button id='submit'>Update</button>");
var currentSettings = settings;
var isOn = false;
var onText;
var offText;
// function updateState() {
// indicatorElement.toggleClass("on", isOn);
//
// if (isOn) {
// stateElement.text((_.isUndefined(onText) ? (_.isUndefined(currentSettings.on_text) ? "" : currentSettings.on_text) : onText));
// }
// else {
// stateElement.text((_.isUndefined(offText) ? (_.isUndefined(currentSettings.off_text) ? "" : currentSettings.off_text) : offText));
// }
// }
this.render = function (element) {
$(element).append(titleElement);
pickerElement.appendTo(wrapperElement);
buttonElement.appendTo(wrapperElement);
$(element).append(wrapperElement);
$('#datetimepicker6').datetimepicker({
'showTodayButton': true,
'showClose':true,
icons: {
time: 'fa fa-clock-o',
today: 'fa fa-dot-circle-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
clear: 'fa fa-trash-o',
close: 'fa fa-times'
}
});
$('#datetimepicker7').datetimepicker({
'showTodayButton':true,
'debug':true,
'showClose':true,
//'widgetPositioning':{vertical:'bottom'},
useCurrent: false, //Important! See issue #1075
icons: {
time: 'fa fa-clock-o',
today: 'fa fa-dot-circle-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
clear: 'fa fa-trash-o',
close: 'fa fa-times'
}
});
if(currentSettings.start_date != undefined) {
$('#datetimepicker6').data("DateTimePicker").date(new Date(currentSettings.start_date));
}
if(currentSettings.end_date != undefined) {
$('#datetimepicker7').data("DateTimePicker").date(new Date(currentSettings.end_date));
}
$("#datetimepicker6").on("dp.change", function (e) {
$('#datetimepicker7').data("DateTimePicker").minDate(e.date);
currentSettings.start_date = e.date.utc().toISOString();
});
$("#datetimepicker7").on("dp.change", function (e) {
$('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
currentSettings.end_date = e.date.utc().toISOString();
});
buttonElement.on("click", function(e) {
freeboard.setDatasourceSettings("UCLA",{"start":currentSettings.start_date,"end":currentSettings.end_date});
});
if (currentSettings.on_change) {
window.clickfunc = new Function ("sensor",currentSettings.on_change);
$(element).delegate('select#deviceSelect',"change",function(e){
window.clickfunc(this.value);
// var optionSelected = $("option:selected", this);
// var valueSelected = this.value;
// window.selectedResource = valueSelected;
// console.log(window.selectedResource);
});
}
}
this.onSettingsChanged = function (newSettings) {
currentSettings = newSettings;
titleElement.html((_.isUndefined(newSettings.title) ? "" : newSettings.title));
}
this.onCalculatedValueChanged = function (settingName, newValue) {
if (settingName == "options") {
if (newValue.constructor === Array) {
dropdownElement.empty();
newValue.forEach(function(sensor){
dropdownElement.append('<OPTION VALUE='+sensor.guid+'>'+sensor.info.Name+'</OPTION>');
});
}
}
}
this.onDispose = function () {
}
this.getHeight = function () {
return 6;
}
this.onSettingsChanged(settings);
};
freeboard.loadWidgetPlugin({
type_name: "timepicker",
display_name: "Date Time Picker",
external_scripts: ["https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js",
"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css"],
settings: [
{
name: "title",
display_name: "Title",
type: "text"
},
{
name: "start_date",
display_name: "Initial Start Date",
type: "calculated"
},
{
name: "end_date",
display_name: "Initial End Date",
type: "calculated"
},
{
name: "on_change",
"display_name":"On Change Function",
"type":"calculated"
}
],
newInstance: function (settings, newInstanceCallback) {
newInstanceCallback(new timePickerWidget(settings));
}
});