www/js/set_devices.js

Tue, 23 Apr 2024 16:52:13 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 23 Apr 2024 16:52:13 +0200
changeset 699
35382668a140
parent 689
f94b525f7563
child 700
942af738157c
permissions
-rw-r--r--

Added Add new device.

685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2024
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of mbsePi-apps
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * BrewCloud is distributed in the hope that it will be useful, but
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
45 function createAddElements() {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
46 $('#addWindow').jqxWindow({
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
47 theme: theme,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
48 position: { x: 400, y: 210 },
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
49 width: 480,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
50 height: 180,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
51 resizable: false,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
52 isModal: true,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
53 modalOpacity: 0.4,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
54 okButton: $('#addOk'),
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
55 cancelButton: $('#addCancel'),
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
56 initContent: function() {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
57 $('#addType').jqxDropDownList({
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
58 theme: theme,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
59 source: DeviceTypeAdapter,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
60 valueMember: 'mno',
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
61 displayMember: 'en',
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
62 width: 180,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
63 height: 30,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
64 autoDropDownHeight: true
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
65 });
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
66 $("#addType").jqxDropDownList('disableItem', "W1" ); /* These are auto created, so disable. */
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
67 $("#addType").jqxDropDownList('disableItem', "GPIO" );
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
68 $("#addType").jqxDropDownList('disableItem', "SIM" );
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
69 $('#addOk').jqxButton({ template: 'success', width: '65px', theme: theme });
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
70 $('#addCancel').jqxButton({ template: 'primary', width: '65px', theme: theme });
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
71 $('#addCancel').focus();
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
72 }
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
73 });
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
74 $('#addWindow').jqxWindow('hide');
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
75 }
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
76
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
77
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
78
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
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
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 datatype: 'json',
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 cache: false,
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 datafields: [
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 { name: 'uuid', type: 'string' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 { name: 'type', type: 'string' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 { name: 'address', type: 'string' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 { name: 'subdevice', type: 'int' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 { name: 'inuse', type: 'int' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 { name: 'description', type: 'string' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 { name: 'direction', type: 'string' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 { name: 'timestamp', type: 'int' }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 ],
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 id: 'uuid',
699
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
101 url: url
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
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
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 // initialize jqxGrid
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 $('#jqxgrid').jqxGrid({
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 width: 1280,
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 height: 630,
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 source: dataAdapter,
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
165 $('#addType').val('NA');
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
166 $('#addWindow').jqxWindow('open');
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
167 $('#addOk').click(function() {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
168 if ($('#addType').val() != 'NA') {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
169 console.log('Add type ' + $('#addType').val());
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
170 var data,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
171 data = 'add=true&type=' + $('#addType').val();
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
172 console.log(data);
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
173 $.ajax({
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
174 dataType: 'json',
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
175 url: url,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
176 cache: false,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
177 data: data,
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
178 type: 'POST',
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
179 success: function(data) {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
180 if (data.error) {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
181 console.log('add: ' + data.msg);
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
182 alert('Error: ' + data.msg);
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
183 } else {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
184 console.log('add: success');
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
185 }
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
186 },
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
187 error: function(jqXHR, textStatus, errorThrown) {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
188 }
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
189 });
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
190 } else {
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
191 console.log('Add wrong type');
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
192 }
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
193 });
686
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
194 });
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
195 },
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 columns: [
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 { text: 'Address', datafield: 'address', width: 200 },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 { text: 'Subdevice', datafield: 'subdevice', width: 100 },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 { text: 'Direction', datafield: 'direction', width: 120 },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 { text: 'Value', datafield: 'value', width: 80 },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 { text: 'Description', datafield: 'description' },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 { text: 'Last change', datafield: 'timestamp', width: 200,
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
204 var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " ");
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>';
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 },
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 { 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
209 return 'Edit';
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 }, buttonclick: function(row) {
686
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
211 // 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
212 editrow = row;
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
213 $('#popupWindow').jqxWindow({ position: { x: 110, y: 15 } });
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
214 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
215 $('#dev_uuid').val(dataRecord.uuid);
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
216 $('#dev_description').val(dataRecord.description);
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
217 $('#dev_type').val(dataRecord.type);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
218 $('#dev_direction').val(dataRecord.direction);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
219 $('#dev_value').val(dataRecord.value);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
220 $('#dev_offset').val(dataRecord.offset);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
221 $('#dev_address').val(dataRecord.address);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
222 $('#dev_subdevice').val(dataRecord.subdevice);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
223 $('#dev_present').val(dataRecord.present);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
224 $('#dev_gpiopin').val(dataRecord.gpiopin);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
225 $('#dev_inuse').val(dataRecord.inuse);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
226 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
227 $('#dev_timestamp').val(date);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
228 $('#dev_comment').val(dataRecord.comment);
686
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
229 // show the popup window.
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
230 $('#popupWindow').jqxWindow('open');
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 ],
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 });
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
686
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
236 // initialize the popup window and buttons.
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
237 $('#popupWindow').jqxWindow({
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
238 width: 1050,
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
239 height: 625,
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
240 resizable: false,
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
241 theme: theme,
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
242 isModal: true,
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
243 autoOpen: false,
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
244 cancelButton: $('#Cancel'),
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
245 modalOpacity: 0.40
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
246 });
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
247 $('#popupWindow').on('open', function() {
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
248 $('#dev_description').jqxInput('selectAll');
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
249 });
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
250 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
251 $('#Delete').click(function() {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
252 if (editrow >= 0) {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
253 // Open a popup to confirm this action.
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
254 $('#eventWindow').jqxWindow('open');
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
255 $('#delOk').click(function() {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
256 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
257 $('#jqxgrid').jqxGrid('deleterow', rowID);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
258 });
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
259 }
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
260 $('#popupWindow').jqxWindow('hide');
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
261 });
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
262 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
263 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
264 $('#Save').click(function() {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
265 var row, rowID = -1;
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
266 if (editrow >= 0) {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
267 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
268 }
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
269 row = {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
270 uuid: dataRecord.uuid,
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
271 type: $('#type').val()
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
272 };
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
273 if (editrow >= 0) {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
274 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
275 } else {
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
276 $('#jqxgrid').jqxGrid('addrow', null, row);
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 $('#popupWindow').jqxWindow('hide');
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
279 });
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 686
diff changeset
280 createDelElements();
699
35382668a140 Added Add new device.
Michiel Broek <mbroek@mbse.eu>
parents: 689
diff changeset
281 createAddElements();
686
372b2442a30f More work for devices list and editor.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
282
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 websocket.onmessage = function(evt) {
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 var msg = evt.data;
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 var obj = JSON.parse(msg);
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 if (obj.ping) {
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 websocket.send('{"pong":' + obj.ping + '}');
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 if (obj.type == 'device') {
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 // Use the message to trigger update.
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 $('#jqxgrid').jqxGrid('updatebounddata');
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 }
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 });

mercurial