diff -r 92a080c1a5d5 -r 35382668a140 www/js/set_devices.js --- a/www/js/set_devices.js Tue Apr 23 13:06:33 2024 +0200 +++ b/www/js/set_devices.js Tue Apr 23 16:52:13 2024 +0200 @@ -42,8 +42,43 @@ } +function createAddElements() { + $('#addWindow').jqxWindow({ + theme: theme, + position: { x: 400, y: 210 }, + width: 480, + height: 180, + resizable: false, + isModal: true, + modalOpacity: 0.4, + okButton: $('#addOk'), + cancelButton: $('#addCancel'), + initContent: function() { + $('#addType').jqxDropDownList({ + theme: theme, + source: DeviceTypeAdapter, + valueMember: 'mno', + displayMember: 'en', + width: 180, + height: 30, + autoDropDownHeight: true + }); + $("#addType").jqxDropDownList('disableItem', "W1" ); /* These are auto created, so disable. */ + $("#addType").jqxDropDownList('disableItem', "GPIO" ); + $("#addType").jqxDropDownList('disableItem', "SIM" ); + $('#addOk').jqxButton({ template: 'success', width: '65px', theme: theme }); + $('#addCancel').jqxButton({ template: 'primary', width: '65px', theme: theme }); + $('#addCancel').focus(); + } + }); + $('#addWindow').jqxWindow('hide'); +} + + + $(document).ready(function() { var dataRecord = {}, + url = 'getdevices.php', source = { datatype: 'json', cache: false, @@ -63,14 +98,14 @@ { name: 'timestamp', type: 'int' } ], id: 'uuid', - url: 'getdevices.php' + url: url }, dataAdapter = new $.jqx.dataAdapter(source), editrow = -1, tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds // initialize the input fields. - $('#dev_uuid').jqxInput({ theme: theme, width: 480, height: 23 }); + $('#dev_uuid').jqxInput({ theme: theme, width: 360, height: 23 }); $('#dev_description').jqxInput({ theme: theme, width: 800, height: 23 }); $('#dev_type').jqxDropDownList({ theme: theme, @@ -127,25 +162,35 @@ addButton.jqxButton({ theme: theme, width: 90, height: 17 }); // add new row. addButton.click(function(event) { - editrow = -1; - $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); - $('#dev_uuid').val(''); - $('#dev_description').val(''); - $('#dev_type').val('NA'); - $('#dev_direction').val('UNDEF'); - $('#dev_value').val(0); - $('#dev_offset').val(0); - $('#dev_address').val(''); - $('#dev_subdevice').val(0); - $('#dev_present').val('UNDEF'); - $('#dev_gpiopin').val(-1); - $('#dev_inuse').val(0); - var now = new Date(); - var date = new Date(now - tzoffset).toISOString().slice(0, 19).replace("T", " "); - $('#dev_timestamp').val(date); - $('#dev_comment').val(''); - - $('#popupWindow').jqxWindow('open'); + $('#addType').val('NA'); + $('#addWindow').jqxWindow('open'); + $('#addOk').click(function() { + if ($('#addType').val() != 'NA') { + console.log('Add type ' + $('#addType').val()); + var data, + data = 'add=true&type=' + $('#addType').val(); + console.log(data); + $.ajax({ + dataType: 'json', + url: url, + cache: false, + data: data, + type: 'POST', + success: function(data) { + if (data.error) { + console.log('add: ' + data.msg); + alert('Error: ' + data.msg); + } else { + console.log('add: success'); + } + }, + error: function(jqXHR, textStatus, errorThrown) { + } + }); + } else { + console.log('Add wrong type'); + } + }); }); }, columns: [ @@ -233,6 +278,7 @@ $('#popupWindow').jqxWindow('hide'); }); createDelElements(); + createAddElements(); websocket.onmessage = function(evt) { var msg = evt.data;