www/js/devices.js

changeset 686
372b2442a30f
parent 685
819553a2b97e
child 687
f5d05b420732
equal deleted inserted replaced
685:819553a2b97e 686:372b2442a30f
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
24 function createDelElements() {
25 $('#eventWindow').jqxWindow({
26 theme: theme,
27 position: { x: 490, y: 210 },
28 width: 300,
29 height: 175,
30 resizable: false,
31 isModal: true,
32 modalOpacity: 0.4,
33 okButton: $('#delOk'),
34 cancelButton: $('#delCancel'),
35 initContent: function() {
36 $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme });
37 $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme });
38 $('#delCancel').focus();
39 }
40 });
41 $('#eventWindow').jqxWindow('hide');
42 }
43
44
45 $(document).ready(function() {
46 var dataRecord = {},
47 source = {
48 datatype: 'json',
49 cache: false,
50 datafields: [
51 { name: 'uuid', type: 'string' },
52 { name: 'type', type: 'string' },
53 { name: 'address', type: 'string' },
54 { name: 'subdevice', type: 'int' },
55 { name: 'inuse', type: 'int' },
56 { name: 'description', type: 'string' },
57 { name: 'direction', type: 'string' },
58 { name: 'value', type: 'int' },
59 { name: 'timestamp', type: 'int' }
60 ],
61 id: 'uuid',
62 url: 'getdevices.php'
63 },
64 dataAdapter = new $.jqx.dataAdapter(source),
65 editrow = -1;
66
67 // initialize the input fields.
68 $('#dev_uuid').jqxInput({ theme: theme, width: 640, height: 23 });
69 $('#dev_description').jqxInput({ theme: theme, width: 640, height: 23 });
70 $('#dev_type').jqxDropDownList({
71 theme: theme,
72 source: DeviceTypeAdapter,
73 valueMember: 'mno',
74 displayMember: 'en',
75 width: 180,
76 height: 23,
77 autoDropDownHeight: true
78 });
79 $('#dev_direction').jqxDropDownList({
80 theme: theme,
81 source: DeviceDirectionAdapter,
82 valueMember: 'mno',
83 displayMember: 'en',
84 width: 180,
85 height: 23,
86 autoDropDownHeight: true
87 });
88
89
90 // initialize jqxGrid
91 $('#jqxgrid').jqxGrid({
92 width: 1280,
93 height: 630,
94 source: dataAdapter,
95 theme: theme,
96 showstatusbar: true,
97 renderstatusbar: function(statusbar) {
98 var rowCount = $("#jqxgrid").jqxGrid('getrows').length;
99 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Total items: ' + rowCount + '</div>');
100 var container, addButton, impButton;
101 container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
102 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
103 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>');
104 container.append(addButton);
105 statusbar.append(container);
106 addButton.jqxButton({ theme: theme, width: 90, height: 17 });
107 // add new row.
108 addButton.click(function(event) {
109 editrow = -1;
110 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
111
112 dataRecord.uuid = '';
113 $('#popupWindow').jqxWindow('open');
114 });
115 },
116 columns: [
117 { text: 'Address', datafield: 'address', width: 200 },
118 { text: 'Subdevice', datafield: 'subdevice', width: 100 },
119 { text: 'Direction', datafield: 'direction', width: 120 },
120 { text: 'Value', datafield: 'value', width: 80 },
121 { text: 'Description', datafield: 'description' },
122 { text: 'Last change', datafield: 'timestamp', width: 200,
123 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
124 var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
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>';
127 }
128 },
129 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() {
130 return 'Edit';
131 }, buttonclick: function(row) {
132 // open the popup window when the user clicks a button.
133 editrow = row;
134 $('#popupWindow').jqxWindow({ position: { x: 110, y: 15 } });
135 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
136 $('#dev_uuid').val(dataRecord.uuid);
137 $('#dev_description').val(dataRecord.description);
138 // dev_type
139 // dev_direction
140 // dev_value
141 // dev_offset
142 // dev_address
143 // dev_subdevice
144 // dev_present
145 // dev_gpiopin
146 // dev_inuse
147 // dev_timestamp
148 // dev_comment
149
150 // show the popup window.
151 $('#popupWindow').jqxWindow('open');
152 }
153 }
154 ],
155 });
156
157 // initialize the popup window and buttons.
158 $('#popupWindow').jqxWindow({
159 width: 1050,
160 height: 625,
161 resizable: false,
162 theme: theme,
163 isModal: true,
164 autoOpen: false,
165 cancelButton: $('#Cancel'),
166 modalOpacity: 0.40
167 });
168 $('#popupWindow').on('open', function() {
169 $('#dev_description').jqxInput('selectAll');
170 });
171 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
172
173 websocket.onmessage = function(evt) {
174 var msg = evt.data;
175 var obj = JSON.parse(msg);
176
177 if (obj.ping) {
178 websocket.send('{"pong":' + obj.ping + '}');
179 }
180
181 if (obj.type == 'device') {
182 // Use the message to trigger update.
183 $('#jqxgrid').jqxGrid('updatebounddata');
184 }
185 }
186 });

mercurial