Thu, 25 Apr 2024 14:26:47 +0200
Version 0.9.19a6. Fixes after a short trial on the production controller. Fixed json for alternate beer termperature sensor. Fixed division by 1000 for the room temperature and humidity values. The dropdown list for devices shows the address instead of description in the list.
685 | 1 | /***************************************************************************** |
2 | * Copyright (C) 2024 | |
3 | * | |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * BrewCloud is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | ||
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
24 | function createDelElements() { |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
25 | $('#eventWindow').jqxWindow({ |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
26 | theme: theme, |
703
344470c6bb1c
Fermenter editor layout is ready. Load record done. Add and Delete a new fermenter is done.
Michiel Broek <mbroek@mbse.eu>
parents:
701
diff
changeset
|
27 | position: { x: 430, y: 210 }, |
344470c6bb1c
Fermenter editor layout is ready. Load record done. Add and Delete a new fermenter is done.
Michiel Broek <mbroek@mbse.eu>
parents:
701
diff
changeset
|
28 | width: 420, |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
29 | height: 175, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
30 | resizable: false, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
31 | isModal: true, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
32 | modalOpacity: 0.4, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
33 | okButton: $('#delOk'), |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
34 | cancelButton: $('#delCancel'), |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
35 | initContent: function() { |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
36 | $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
37 | $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
38 | $('#delCancel').focus(); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
39 | } |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
40 | }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
41 | $('#eventWindow').jqxWindow('hide'); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
42 | } |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
43 | |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
44 | |
699 | 45 | function createAddElements() { |
46 | $('#addWindow').jqxWindow({ | |
47 | theme: theme, | |
48 | position: { x: 400, y: 210 }, | |
49 | width: 480, | |
50 | height: 180, | |
51 | resizable: false, | |
52 | isModal: true, | |
53 | modalOpacity: 0.4, | |
54 | okButton: $('#addOk'), | |
55 | cancelButton: $('#addCancel'), | |
56 | initContent: function() { | |
57 | $('#addType').jqxDropDownList({ | |
58 | theme: theme, | |
59 | source: DeviceTypeAdapter, | |
60 | valueMember: 'mno', | |
61 | displayMember: 'en', | |
62 | width: 180, | |
63 | height: 30, | |
64 | autoDropDownHeight: true | |
65 | }); | |
66 | $("#addType").jqxDropDownList('disableItem', "W1" ); /* These are auto created, so disable. */ | |
67 | $("#addType").jqxDropDownList('disableItem', "GPIO" ); | |
68 | $("#addType").jqxDropDownList('disableItem', "SIM" ); | |
69 | $('#addOk').jqxButton({ template: 'success', width: '65px', theme: theme }); | |
70 | $('#addCancel').jqxButton({ template: 'primary', width: '65px', theme: theme }); | |
71 | $('#addCancel').focus(); | |
72 | } | |
73 | }); | |
74 | $('#addWindow').jqxWindow('hide'); | |
75 | } | |
76 | ||
77 | ||
78 | ||
685 | 79 | $(document).ready(function() { |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
80 | var dataRecord = {}, |
699 | 81 | url = 'getdevices.php', |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
82 | source = { |
685 | 83 | datatype: 'json', |
84 | cache: false, | |
85 | datafields: [ | |
86 | { name: 'uuid', type: 'string' }, | |
87 | { name: 'type', type: 'string' }, | |
88 | { name: 'address', type: 'string' }, | |
89 | { name: 'subdevice', type: 'int' }, | |
90 | { name: 'inuse', type: 'int' }, | |
91 | { name: 'description', type: 'string' }, | |
92 | { name: 'direction', type: 'string' }, | |
93 | { name: 'value', type: 'int' }, | |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
94 | { name: 'offset', type: 'int' }, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
95 | { name: 'present', type: 'string' }, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
96 | { name: 'gpiopin', type: 'int' }, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
97 | { name: 'comment', type: 'string' }, |
685 | 98 | { name: 'timestamp', type: 'int' } |
99 | ], | |
100 | id: 'uuid', | |
699 | 101 | url: url |
685 | 102 | }, |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
103 | dataAdapter = new $.jqx.dataAdapter(source), |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
104 | editrow = -1, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
105 | tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
106 | |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
107 | // initialize the input fields. |
699 | 108 | $('#dev_uuid').jqxInput({ theme: theme, width: 360, height: 23 }); |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
109 | $('#dev_description').jqxInput({ theme: theme, width: 800, height: 23 }); |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
110 | $('#dev_type').jqxDropDownList({ |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
111 | theme: theme, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
112 | source: DeviceTypeAdapter, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
113 | valueMember: 'mno', |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
114 | displayMember: 'en', |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
115 | width: 180, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
116 | height: 23, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
117 | autoDropDownHeight: true |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
118 | }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
119 | $('#dev_direction').jqxDropDownList({ |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
120 | theme: theme, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
121 | source: DeviceDirectionAdapter, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
122 | valueMember: 'mno', |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
123 | displayMember: 'en', |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
124 | width: 180, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
125 | height: 23, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
126 | autoDropDownHeight: true |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
127 | }); |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
128 | $('#dev_value').jqxNumberInput(Spin0dec); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
129 | $('#dev_offset').jqxNumberInput(Spin0dec); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
130 | $('#dev_address').jqxInput({ theme: theme, width: 200, height: 23 }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
131 | $('#dev_subdevice').jqxNumberInput(SubInt); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
132 | $('#dev_present').jqxDropDownList({ |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
133 | theme: theme, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
134 | source: DevicePresentAdapter, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
135 | valueMember: 'mno', |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
136 | displayMember: 'en', |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
137 | width: 180, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
138 | height: 23, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
139 | autoDropDownHeight: true |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
140 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
141 | $('#dev_gpiopin').jqxNumberInput(GPIOInt); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
142 | $('#dev_inuse').jqxNumberInput(Show0dec); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
143 | $('#dev_timestamp').jqxInput({ theme: theme, width: 200, height: 23 }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
144 | $('#dev_comment').jqxInput({ theme: theme, width: 800, height: 23 }); |
685 | 145 | |
146 | // initialize jqxGrid | |
147 | $('#jqxgrid').jqxGrid({ | |
148 | width: 1280, | |
149 | height: 630, | |
150 | source: dataAdapter, | |
151 | theme: theme, | |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
152 | showstatusbar: true, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
153 | renderstatusbar: function(statusbar) { |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
154 | var rowCount = $("#jqxgrid").jqxGrid('getrows').length; |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
155 | statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Total items: ' + rowCount + '</div>'); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
156 | var container, addButton, impButton; |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
157 | container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
158 | addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' + |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
159 | 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>'); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
160 | container.append(addButton); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
161 | statusbar.append(container); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
162 | addButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
163 | // add new row. |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
164 | addButton.click(function(event) { |
699 | 165 | $('#addType').val('NA'); |
166 | $('#addWindow').jqxWindow('open'); | |
167 | $('#addOk').click(function() { | |
168 | if ($('#addType').val() != 'NA') { | |
169 | console.log('Add type ' + $('#addType').val()); | |
170 | var data, | |
171 | data = 'add=true&type=' + $('#addType').val(); | |
172 | console.log(data); | |
173 | $.ajax({ | |
174 | dataType: 'json', | |
175 | url: url, | |
176 | cache: false, | |
177 | data: data, | |
178 | type: 'POST', | |
179 | success: function(data) { | |
180 | if (data.error) { | |
181 | console.log('add: ' + data.msg); | |
182 | alert('Error: ' + data.msg); | |
183 | } else { | |
184 | console.log('add: success'); | |
185 | } | |
186 | }, | |
187 | error: function(jqXHR, textStatus, errorThrown) { | |
188 | } | |
189 | }); | |
700 | 190 | $('#jqxgrid').jqxGrid('updatebounddata'); |
699 | 191 | } else { |
192 | console.log('Add wrong type'); | |
193 | } | |
194 | }); | |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
195 | }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
196 | }, |
685 | 197 | columns: [ |
198 | { text: 'Address', datafield: 'address', width: 200 }, | |
700 | 199 | { text: 'Sub', datafield: 'subdevice', width: 60 }, |
200 | { text: 'Type', datafield: 'type', width: 100 }, | |
685 | 201 | { text: 'Direction', datafield: 'direction', width: 120 }, |
202 | { text: 'Value', datafield: 'value', width: 80 }, | |
203 | { text: 'Description', datafield: 'description' }, | |
204 | { text: 'Last change', datafield: 'timestamp', width: 200, | |
205 | cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { | |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
206 | var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); |
685 | 207 | return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>'; |
208 | } | |
209 | }, | |
210 | { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() { | |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
211 | return 'Edit'; |
685 | 212 | }, buttonclick: function(row) { |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
213 | // open the popup window when the user clicks a button. |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
214 | editrow = row; |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
215 | $('#popupWindow').jqxWindow({ position: { x: 110, y: 15 } }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
216 | dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
217 | $('#dev_uuid').val(dataRecord.uuid); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
218 | $('#dev_description').val(dataRecord.description); |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
219 | $('#dev_type').val(dataRecord.type); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
220 | $('#dev_direction').val(dataRecord.direction); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
221 | $('#dev_value').val(dataRecord.value); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
222 | $('#dev_offset').val(dataRecord.offset); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
223 | $('#dev_address').val(dataRecord.address); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
224 | $('#dev_subdevice').val(dataRecord.subdevice); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
225 | $('#dev_present').val(dataRecord.present); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
226 | $('#dev_gpiopin').val(dataRecord.gpiopin); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
227 | $('#dev_inuse').val(dataRecord.inuse); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
228 | var date = new Date((dataRecord.timestamp * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
229 | $('#dev_timestamp').val(date); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
230 | $('#dev_comment').val(dataRecord.comment); |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
231 | // show the popup window. |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
232 | $('#popupWindow').jqxWindow('open'); |
685 | 233 | } |
234 | } | |
235 | ], | |
236 | }); | |
237 | ||
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
238 | // initialize the popup window and buttons. |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
239 | $('#popupWindow').jqxWindow({ |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
240 | width: 1050, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
241 | height: 625, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
242 | resizable: false, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
243 | theme: theme, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
244 | isModal: true, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
245 | autoOpen: false, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
246 | cancelButton: $('#Cancel'), |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
247 | modalOpacity: 0.40 |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
248 | }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
249 | $('#popupWindow').on('open', function() { |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
250 | $('#dev_description').jqxInput('selectAll'); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
251 | }); |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
252 | $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme }); |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
253 | $('#Delete').click(function() { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
254 | if (editrow >= 0) { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
255 | // Open a popup to confirm this action. |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
256 | $('#eventWindow').jqxWindow('open'); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
257 | $('#delOk').click(function() { |
700 | 258 | var data, |
259 | data = 'del=true&uuid=' + $('#dev_uuid').val(); | |
260 | $.ajax({ | |
261 | dataType: 'json', | |
262 | url: url, | |
263 | cache: false, | |
264 | data: data, | |
265 | type: 'POST', | |
266 | success: function(data) { | |
267 | if (data.error) { | |
268 | console.log('del: ' + data.msg); | |
269 | alert('Error: ' + data.msg); | |
270 | } else { | |
271 | console.log('del: success'); | |
272 | } | |
273 | }, | |
274 | error: function(jqXHR, textStatus, errorThrown) {} | |
275 | }); | |
276 | $('#jqxgrid').jqxGrid('updatebounddata'); | |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
277 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
278 | } |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
279 | $('#popupWindow').jqxWindow('hide'); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
280 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
281 | $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
282 | $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
283 | $('#Save').click(function() { |
701 | 284 | var data, |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
285 | row = { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
286 | uuid: dataRecord.uuid, |
701 | 287 | type: $('#dev_type').val(), |
288 | direction: $('#dev_direction').val(), | |
289 | value: parseInt($('#dev_value').jqxNumberInput('decimal')), | |
290 | offset: parseInt($('#dev_offset').jqxNumberInput('decimal')), | |
291 | present: $('#dev_present').val(), | |
292 | address: $('#dev_address').val(), | |
293 | subdevice: parseInt($('#dev_subdevice').jqxNumberInput('decimal')), | |
294 | gpiopin: parseInt($('#dev_gpiopin').jqxNumberInput('val')), | |
295 | description: $('#dev_description').val(), | |
296 | comment: $('#dev_comment').val() | |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
297 | }; |
701 | 298 | data = 'update=true&' + $.param(row); |
299 | console.log(data); | |
300 | $.ajax({ | |
301 | dataType: 'json', | |
302 | url: url, | |
303 | cache: false, | |
304 | data: data, | |
305 | type: 'POST', | |
306 | success: function(data) { | |
307 | if (data.error) { | |
308 | console.log('update: ' + data.msg); | |
309 | alert('Error: ' + data.msg); | |
310 | } else { | |
311 | console.log('update: success'); | |
312 | } | |
313 | }, | |
314 | error: function(jqXHR, textStatus, errorThrown) {} | |
315 | }); | |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
316 | $('#popupWindow').jqxWindow('hide'); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
317 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
318 | createDelElements(); |
699 | 319 | createAddElements(); |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
320 | |
685 | 321 | websocket.onmessage = function(evt) { |
322 | var msg = evt.data; | |
323 | var obj = JSON.parse(msg); | |
324 | ||
325 | if (obj.ping) { | |
326 | websocket.send('{"pong":' + obj.ping + '}'); | |
327 | } | |
328 | ||
329 | if (obj.type == 'device') { | |
330 | // Use the message to trigger update. | |
331 | $('#jqxgrid').jqxGrid('updatebounddata'); | |
332 | } | |
333 | } | |
334 | }); |