54 { name: 'subdevice', type: 'int' }, |
54 { name: 'subdevice', type: 'int' }, |
55 { name: 'inuse', type: 'int' }, |
55 { name: 'inuse', type: 'int' }, |
56 { name: 'description', type: 'string' }, |
56 { name: 'description', type: 'string' }, |
57 { name: 'direction', type: 'string' }, |
57 { name: 'direction', type: 'string' }, |
58 { name: 'value', type: 'int' }, |
58 { name: 'value', type: 'int' }, |
|
59 { name: 'offset', type: 'int' }, |
|
60 { name: 'present', type: 'string' }, |
|
61 { name: 'gpiopin', type: 'int' }, |
|
62 { name: 'comment', type: 'string' }, |
59 { name: 'timestamp', type: 'int' } |
63 { name: 'timestamp', type: 'int' } |
60 ], |
64 ], |
61 id: 'uuid', |
65 id: 'uuid', |
62 url: 'getdevices.php' |
66 url: 'getdevices.php' |
63 }, |
67 }, |
64 dataAdapter = new $.jqx.dataAdapter(source), |
68 dataAdapter = new $.jqx.dataAdapter(source), |
65 editrow = -1; |
69 editrow = -1, |
|
70 tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds |
66 |
71 |
67 // initialize the input fields. |
72 // initialize the input fields. |
68 $('#dev_uuid').jqxInput({ theme: theme, width: 640, height: 23 }); |
73 $('#dev_uuid').jqxInput({ theme: theme, width: 480, height: 23 }); |
69 $('#dev_description').jqxInput({ theme: theme, width: 640, height: 23 }); |
74 $('#dev_description').jqxInput({ theme: theme, width: 800, height: 23 }); |
70 $('#dev_type').jqxDropDownList({ |
75 $('#dev_type').jqxDropDownList({ |
71 theme: theme, |
76 theme: theme, |
72 source: DeviceTypeAdapter, |
77 source: DeviceTypeAdapter, |
73 valueMember: 'mno', |
78 valueMember: 'mno', |
74 displayMember: 'en', |
79 displayMember: 'en', |
83 displayMember: 'en', |
88 displayMember: 'en', |
84 width: 180, |
89 width: 180, |
85 height: 23, |
90 height: 23, |
86 autoDropDownHeight: true |
91 autoDropDownHeight: true |
87 }); |
92 }); |
88 |
93 $('#dev_value').jqxNumberInput(Spin0dec); |
|
94 $('#dev_offset').jqxNumberInput(Spin0dec); |
|
95 $('#dev_address').jqxInput({ theme: theme, width: 200, height: 23 }); |
|
96 $('#dev_subdevice').jqxNumberInput(SubInt); |
|
97 $('#dev_present').jqxDropDownList({ |
|
98 theme: theme, |
|
99 source: DevicePresentAdapter, |
|
100 valueMember: 'mno', |
|
101 displayMember: 'en', |
|
102 width: 180, |
|
103 height: 23, |
|
104 autoDropDownHeight: true |
|
105 }); |
|
106 $('#dev_gpiopin').jqxNumberInput(GPIOInt); |
|
107 $('#dev_inuse').jqxNumberInput(Show0dec); |
|
108 $('#dev_timestamp').jqxInput({ theme: theme, width: 200, height: 23 }); |
|
109 $('#dev_comment').jqxInput({ theme: theme, width: 800, height: 23 }); |
89 |
110 |
90 // initialize jqxGrid |
111 // initialize jqxGrid |
91 $('#jqxgrid').jqxGrid({ |
112 $('#jqxgrid').jqxGrid({ |
92 width: 1280, |
113 width: 1280, |
93 height: 630, |
114 height: 630, |
119 { text: 'Direction', datafield: 'direction', width: 120 }, |
140 { text: 'Direction', datafield: 'direction', width: 120 }, |
120 { text: 'Value', datafield: 'value', width: 80 }, |
141 { text: 'Value', datafield: 'value', width: 80 }, |
121 { text: 'Description', datafield: 'description' }, |
142 { text: 'Description', datafield: 'description' }, |
122 { text: 'Last change', datafield: 'timestamp', width: 200, |
143 { text: 'Last change', datafield: 'timestamp', width: 200, |
123 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { |
144 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { |
124 var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds |
145 var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); |
125 var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " ");; |
|
126 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>'; |
146 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>'; |
127 } |
147 } |
128 }, |
148 }, |
129 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() { |
149 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() { |
130 return 'Edit'; |
150 return 'Edit'; |
133 editrow = row; |
153 editrow = row; |
134 $('#popupWindow').jqxWindow({ position: { x: 110, y: 15 } }); |
154 $('#popupWindow').jqxWindow({ position: { x: 110, y: 15 } }); |
135 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow); |
155 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow); |
136 $('#dev_uuid').val(dataRecord.uuid); |
156 $('#dev_uuid').val(dataRecord.uuid); |
137 $('#dev_description').val(dataRecord.description); |
157 $('#dev_description').val(dataRecord.description); |
138 // dev_type |
158 $('#dev_type').val(dataRecord.type); |
139 // dev_direction |
159 $('#dev_direction').val(dataRecord.direction); |
140 // dev_value |
160 $('#dev_value').val(dataRecord.value); |
141 // dev_offset |
161 $('#dev_offset').val(dataRecord.offset); |
142 // dev_address |
162 $('#dev_address').val(dataRecord.address); |
143 // dev_subdevice |
163 $('#dev_subdevice').val(dataRecord.subdevice); |
144 // dev_present |
164 $('#dev_present').val(dataRecord.present); |
145 // dev_gpiopin |
165 $('#dev_gpiopin').val(dataRecord.gpiopin); |
146 // dev_inuse |
166 $('#dev_inuse').val(dataRecord.inuse); |
147 // dev_timestamp |
167 var date = new Date((dataRecord.timestamp * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); |
148 // dev_comment |
168 $('#dev_timestamp').val(date); |
149 |
169 $('#dev_comment').val(dataRecord.comment); |
150 // show the popup window. |
170 // show the popup window. |
151 $('#popupWindow').jqxWindow('open'); |
171 $('#popupWindow').jqxWindow('open'); |
152 } |
172 } |
153 } |
173 } |
154 ], |
174 ], |
167 }); |
187 }); |
168 $('#popupWindow').on('open', function() { |
188 $('#popupWindow').on('open', function() { |
169 $('#dev_description').jqxInput('selectAll'); |
189 $('#dev_description').jqxInput('selectAll'); |
170 }); |
190 }); |
171 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme }); |
191 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme }); |
|
192 $('#Delete').click(function() { |
|
193 if (editrow >= 0) { |
|
194 // Open a popup to confirm this action. |
|
195 $('#eventWindow').jqxWindow('open'); |
|
196 $('#delOk').click(function() { |
|
197 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
198 $('#jqxgrid').jqxGrid('deleterow', rowID); |
|
199 }); |
|
200 } |
|
201 $('#popupWindow').jqxWindow('hide'); |
|
202 }); |
|
203 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme }); |
|
204 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme }); |
|
205 $('#Save').click(function() { |
|
206 var row, rowID = -1; |
|
207 if (editrow >= 0) { |
|
208 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
209 } |
|
210 row = { |
|
211 uuid: dataRecord.uuid, |
|
212 type: $('#type').val() |
|
213 }; |
|
214 if (editrow >= 0) { |
|
215 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
216 } else { |
|
217 $('#jqxgrid').jqxGrid('addrow', null, row); |
|
218 } |
|
219 $('#popupWindow').jqxWindow('hide'); |
|
220 }); |
|
221 createDelElements(); |
172 |
222 |
173 websocket.onmessage = function(evt) { |
223 websocket.onmessage = function(evt) { |
174 var msg = evt.data; |
224 var msg = evt.data; |
175 var obj = JSON.parse(msg); |
225 var obj = JSON.parse(msg); |
176 |
226 |