www/js/set_global.js

changeset 697
685f20ad87ed
child 698
92a080c1a5d5
equal deleted inserted replaced
696:fe042f9484ac 697:685f20ad87ed
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 $(document).ready(function() {
25 var global = {},
26 globalSource = {
27 datatype: 'json',
28 cache: false,
29 datafields: [
30 { name: 'type', type: 'string' },
31 { name: 'name', type: 'string' },
32 { name: 'uuid', type: 'string' },
33 { name: 'node', type: 'string' },
34 { name: 'os' },
35 { name: 'os_version' },
36 { name: 'FW' },
37 { name: 'server_port', type: 'int' },
38 { name: 'websocket_port', type: 'int' },
39 { name: 'thb_temp_uuid', map: 'THB>temperature>uuid' },
40 { name: 'temp_uuid', map: 'THB>temperature>uuid' },
41 { name: 'temp_state', map: 'THB>temperature>state' },
42 { name: 'temp_value', map: 'THB>temperature>value', type: 'int' },
43 { name: 'hum_uuid', map: 'THB>humidity>uuid' },
44 { name: 'hum_state', map: 'THB>humidity>state' },
45 { name: 'hum_value', map: 'THB>humidity>value', type: 'int' },
46 { name: 'temp_hum_idx', map: 'THB>index', type: 'int' },
47 { name: 'lcd_address', map: 'LCD>address' },
48 { name: 'lcd_cols', map: 'LCD>cols', type: 'int' },
49 { name: 'lcd_rows', map: 'LCD>rows', type: 'int' },
50 { name: 'mqtt_host', map: 'MQTT>host' },
51 { name: 'mqtt_port', map: 'MQTT>port', type: 'int' },
52 { name: 'mqtt_username', map: 'MQTT_username' },
53 { name: 'mqtt_password', map: 'MQTT_password' }
54 ],
55 id: 'name',
56 url: 'getglobal.php'
57 },
58 globalData = new $.jqx.dataAdapter(globalSource, {
59 loadComplete: function(records) {
60 global = globalData.records[0];
61 updateScreen();
62 }
63 }),
64 tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
65
66 function updateScreen() {
67 $('#name').val(global.name);
68 $('#uuid').val(global.uuid);
69 $('#node').val(global.node);
70 $('#os').val(global.os + ' ' + global.os_version);
71 $('#FW').val(global.FW);
72 $('#server_port').val(global.server_port);
73 $('#websocket_port').val(global.websocket_port);
74 $('#temp_uuid').val(global.temp_uuid);
75 $('#temp_state').val(global.temp_state);
76 $('#temp_value').val(global.temp_value / 1000.0);
77 $('#hum_uuid').val(global.hum_uuid);
78 $('#hum_state').val(global.hum_state);
79 $('#hum_value').val(global.hum_value / 1000.0);
80 $('#temp_hum_idx').val(global.temp_hum_idx);
81 $('#lcd_address').val(global.lcd_address);
82 $('#lcd_cols').val(global.lcd_cols);
83 $('#lcd_rows').val(global.lcd_rows)
84 $('#mqtt_host').val(global.mqtt_host);
85 $('#mqtt_port').val(global.mqtt_port);
86 $('#mqtt_username').val(global.mqtt_username);
87 $('#mqtt_password').val(global.mqtt_password);
88 }
89
90 // initialize the input fields.
91 $('#name').jqxInput({ theme: theme, width: 240, height: 23 });
92 $('#uuid').jqxInput({ theme: theme, width: 480, height: 23 });
93 $('#node').jqxInput({ theme: theme, width: 240, height: 23 });
94 $('#os').jqxInput({ theme: theme, width: 240, height: 23 });
95 $('#FW').jqxInput({ theme: theme, width: 120, height: 23 });
96 $('#server_port').jqxNumberInput(Spin0dec);
97 $('#websocket_port').jqxNumberInput(Spin0dec);
98 $('#temp_uuid').jqxDropDownList({
99 theme: theme,
100 source: tempsensorlist,
101 valueMember: 'uuid',
102 displayMember: 'name',
103 width: 240,
104 dropDownWidth: 480,
105 autoDropDownHeight: true
106 });
107 $('#temp_state').jqxInput({ theme: theme, width: 120, height: 23 });
108 $('#temp_value').jqxNumberInput(Show1dec);
109 $('#hum_uuid').jqxDropDownList({
110 theme: theme,
111 source: tempsensorlist,
112 valueMember: 'uuid',
113 displayMember: 'name',
114 width: 240,
115 dropDownWidth: 480,
116 autoDropDownHeight: true
117 });
118 $('#hum_state').jqxInput({ theme: theme, width: 120, height: 23 });
119 $('#hum_value').jqxNumberInput(Show1dec);
120 $('#temp_hum_idx').jqxNumberInput(Spin0dec);
121
122 $('#lcd_address').jqxNumberInput(Spin0dec);
123 $('#lcd_cols').jqxNumberInput(GPIOInt);
124 $('#lcd_rows').jqxNumberInput(GPIOInt);
125
126 $('#mqtt_host').jqxInput({ theme: theme, width: 240, height: 23 });
127 $('#mqtt_port').jqxNumberInput(Spin0dec);
128 $('#mqtt_username').jqxInput({ theme: theme, width: 240, height: 23 });
129 $('#mqtt_password').jqxInput({ theme: theme, width: 240, height: 23 });
130
131 globalData.dataBind();
132
133
134 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
135 $('#Save').click(function() {
136 var row, rowID = -1;
137 if (editrow >= 0) {
138 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
139 }
140 row = {
141 uuid: dataRecord.uuid,
142 type: $('#type').val()
143 };
144 // $('#jqxgrid').jqxGrid('updaterow', rowID, row);
145 });
146
147 websocket.onmessage = function(evt) {
148 var msg = evt.data;
149 var obj = JSON.parse(msg);
150
151 if (obj.ping) {
152 websocket.send('{"pong":' + obj.ping + '}');
153 }
154
155 if (obj.type == 'global') {
156 // Use the message to trigger update.
157 // $('#jqxgrid').jqxGrid('updatebounddata');
158 }
159 }
160 });

mercurial