Tue, 23 Apr 2024 19:50:05 +0200
Added device delete
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, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
27 | position: { x: 490, y: 210 }, |
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
28 | width: 300, |
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 | console.log('Del ' + $('#dev_uuid').val()); |
259 | var data, | |
260 | data = 'del=true&uuid=' + $('#dev_uuid').val(); | |
261 | console.log(data); | |
262 | $.ajax({ | |
263 | dataType: 'json', | |
264 | url: url, | |
265 | cache: false, | |
266 | data: data, | |
267 | type: 'POST', | |
268 | success: function(data) { | |
269 | if (data.error) { | |
270 | console.log('del: ' + data.msg); | |
271 | alert('Error: ' + data.msg); | |
272 | } else { | |
273 | console.log('del: success'); | |
274 | } | |
275 | }, | |
276 | error: function(jqXHR, textStatus, errorThrown) {} | |
277 | }); | |
278 | $('#jqxgrid').jqxGrid('updatebounddata'); | |
279 | // var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); | |
280 | // $('#jqxgrid').jqxGrid('deleterow', rowID); | |
687
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
281 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
282 | } |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
283 | $('#popupWindow').jqxWindow('hide'); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
284 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
285 | $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
286 | $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
287 | $('#Save').click(function() { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
288 | var row, rowID = -1; |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
289 | if (editrow >= 0) { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
290 | rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
291 | } |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
292 | row = { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
293 | uuid: dataRecord.uuid, |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
294 | type: $('#type').val() |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
295 | }; |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
296 | if (editrow >= 0) { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
297 | $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
298 | } else { |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
299 | $('#jqxgrid').jqxGrid('addrow', null, row); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
300 | } |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
301 | $('#popupWindow').jqxWindow('hide'); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
302 | }); |
f5d05b420732
Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents:
686
diff
changeset
|
303 | createDelElements(); |
699 | 304 | createAddElements(); |
686
372b2442a30f
More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
685
diff
changeset
|
305 | |
685 | 306 | websocket.onmessage = function(evt) { |
307 | var msg = evt.data; | |
308 | var obj = JSON.parse(msg); | |
309 | ||
310 | if (obj.ping) { | |
311 | websocket.send('{"pong":' + obj.ping + '}'); | |
312 | } | |
313 | ||
314 | if (obj.type == 'device') { | |
315 | // Use the message to trigger update. | |
316 | $('#jqxgrid').jqxGrid('updatebounddata'); | |
317 | } | |
318 | } | |
319 | }); |