www/js/set_devices.js

changeset 699
35382668a140
parent 689
f94b525f7563
child 700
942af738157c
equal deleted inserted replaced
698:92a080c1a5d5 699:35382668a140
40 }); 40 });
41 $('#eventWindow').jqxWindow('hide'); 41 $('#eventWindow').jqxWindow('hide');
42 } 42 }
43 43
44 44
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
45 $(document).ready(function() { 79 $(document).ready(function() {
46 var dataRecord = {}, 80 var dataRecord = {},
81 url = 'getdevices.php',
47 source = { 82 source = {
48 datatype: 'json', 83 datatype: 'json',
49 cache: false, 84 cache: false,
50 datafields: [ 85 datafields: [
51 { name: 'uuid', type: 'string' }, 86 { name: 'uuid', type: 'string' },
61 { name: 'gpiopin', type: 'int' }, 96 { name: 'gpiopin', type: 'int' },
62 { name: 'comment', type: 'string' }, 97 { name: 'comment', type: 'string' },
63 { name: 'timestamp', type: 'int' } 98 { name: 'timestamp', type: 'int' }
64 ], 99 ],
65 id: 'uuid', 100 id: 'uuid',
66 url: 'getdevices.php' 101 url: url
67 }, 102 },
68 dataAdapter = new $.jqx.dataAdapter(source), 103 dataAdapter = new $.jqx.dataAdapter(source),
69 editrow = -1, 104 editrow = -1,
70 tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds 105 tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
71 106
72 // initialize the input fields. 107 // initialize the input fields.
73 $('#dev_uuid').jqxInput({ theme: theme, width: 480, height: 23 }); 108 $('#dev_uuid').jqxInput({ theme: theme, width: 360, height: 23 });
74 $('#dev_description').jqxInput({ theme: theme, width: 800, height: 23 }); 109 $('#dev_description').jqxInput({ theme: theme, width: 800, height: 23 });
75 $('#dev_type').jqxDropDownList({ 110 $('#dev_type').jqxDropDownList({
76 theme: theme, 111 theme: theme,
77 source: DeviceTypeAdapter, 112 source: DeviceTypeAdapter,
78 valueMember: 'mno', 113 valueMember: 'mno',
125 container.append(addButton); 160 container.append(addButton);
126 statusbar.append(container); 161 statusbar.append(container);
127 addButton.jqxButton({ theme: theme, width: 90, height: 17 }); 162 addButton.jqxButton({ theme: theme, width: 90, height: 17 });
128 // add new row. 163 // add new row.
129 addButton.click(function(event) { 164 addButton.click(function(event) {
130 editrow = -1; 165 $('#addType').val('NA');
131 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); 166 $('#addWindow').jqxWindow('open');
132 $('#dev_uuid').val(''); 167 $('#addOk').click(function() {
133 $('#dev_description').val(''); 168 if ($('#addType').val() != 'NA') {
134 $('#dev_type').val('NA'); 169 console.log('Add type ' + $('#addType').val());
135 $('#dev_direction').val('UNDEF'); 170 var data,
136 $('#dev_value').val(0); 171 data = 'add=true&type=' + $('#addType').val();
137 $('#dev_offset').val(0); 172 console.log(data);
138 $('#dev_address').val(''); 173 $.ajax({
139 $('#dev_subdevice').val(0); 174 dataType: 'json',
140 $('#dev_present').val('UNDEF'); 175 url: url,
141 $('#dev_gpiopin').val(-1); 176 cache: false,
142 $('#dev_inuse').val(0); 177 data: data,
143 var now = new Date(); 178 type: 'POST',
144 var date = new Date(now - tzoffset).toISOString().slice(0, 19).replace("T", " "); 179 success: function(data) {
145 $('#dev_timestamp').val(date); 180 if (data.error) {
146 $('#dev_comment').val(''); 181 console.log('add: ' + data.msg);
147 182 alert('Error: ' + data.msg);
148 $('#popupWindow').jqxWindow('open'); 183 } else {
184 console.log('add: success');
185 }
186 },
187 error: function(jqXHR, textStatus, errorThrown) {
188 }
189 });
190 } else {
191 console.log('Add wrong type');
192 }
193 });
149 }); 194 });
150 }, 195 },
151 columns: [ 196 columns: [
152 { text: 'Address', datafield: 'address', width: 200 }, 197 { text: 'Address', datafield: 'address', width: 200 },
153 { text: 'Subdevice', datafield: 'subdevice', width: 100 }, 198 { text: 'Subdevice', datafield: 'subdevice', width: 100 },
231 $('#jqxgrid').jqxGrid('addrow', null, row); 276 $('#jqxgrid').jqxGrid('addrow', null, row);
232 } 277 }
233 $('#popupWindow').jqxWindow('hide'); 278 $('#popupWindow').jqxWindow('hide');
234 }); 279 });
235 createDelElements(); 280 createDelElements();
281 createAddElements();
236 282
237 websocket.onmessage = function(evt) { 283 websocket.onmessage = function(evt) {
238 var msg = evt.data; 284 var msg = evt.data;
239 var obj = JSON.parse(msg); 285 var obj = JSON.parse(msg);
240 286

mercurial