Device Save implemented.

Tue, 23 Apr 2024 20:45:29 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 23 Apr 2024 20:45:29 +0200
changeset 701
e50a5003c7ac
parent 700
942af738157c
child 702
d77891f8915d

Device Save implemented.

www/getdevices.php file | annotate | diff | comparison | revisions
www/js/set_devices.js file | annotate | diff | comparison | revisions
www/js/set_global.js file | annotate | diff | comparison | revisions
--- a/www/getdevices.php	Tue Apr 23 19:50:05 2024 +0200
+++ b/www/getdevices.php	Tue Apr 23 20:45:29 2024 +0200
@@ -56,6 +56,26 @@
 
 if (isset($_POST['update'])) {
 
+    $cmd  = "DEVICE PUT " . $_POST['uuid'] . "\r\n";
+    $cmd .= "TYPE," . $_POST['type'] . "\r\n";
+    $cmd .= "DIRECTION," . $_POST['direction'] . "\r\n";
+    $cmd .= "VALUE," . $_POST['value'] . "\r\n";		// Only for outputs
+    $cmd .= "OFFSET," . $_POST['offset'] . "\r\n";		// Only analog
+    $cmd .= "PRESENT," . $_POST['present'] . "\r\n";
+    $cmd .= "ADDRESS," . $_POST['address'] . "\r\n";		// Not for auto detected
+    $cmd .= "SUBDEVICE," . $_POST['subdevice'] . "\r\n";	// Not for auto detected
+    $cmd .= "GPIOPIN," . $_POST['gpiopin'] . "\r\n";
+    $cmd .= "DESCRIPTION," . $_POST['description'] . "\r\n";
+    $cmd .= "COMMENT," . $_POST['comment'] . "\r\n";
+    $cmd .= ".";
+    $answer = send_cmd($cmd);
+    $arr = explode("\r\n", $answer);
+    if (! startsWith($arr[0], "219")) {
+	$response['error'] = true;
+	$response['msg'] = $arr[0];
+    }
+    exit(json_encode($response));
+
 } else if (isset($_POST['add'])) {
 
     $answer = send_cmd("DEVICE ADD " . $_POST['type']);
--- a/www/js/set_devices.js	Tue Apr 23 19:50:05 2024 +0200
+++ b/www/js/set_devices.js	Tue Apr 23 20:45:29 2024 +0200
@@ -255,10 +255,8 @@
    // Open a popup to confirm this action.
    $('#eventWindow').jqxWindow('open');
    $('#delOk').click(function() {
-    console.log('Del ' + $('#dev_uuid').val());
     var data,
     data = 'del=true&uuid=' + $('#dev_uuid').val();
-    console.log(data);
     $.ajax({
      dataType: 'json',
      url: url,
@@ -276,8 +274,6 @@
      error: function(jqXHR, textStatus, errorThrown) {}
     });
     $('#jqxgrid').jqxGrid('updatebounddata');
-//    var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
-//    $('#jqxgrid').jqxGrid('deleterow', rowID);
    });
   }
   $('#popupWindow').jqxWindow('hide');
@@ -285,19 +281,38 @@
  $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
  $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
  $('#Save').click(function() {
-  var row, rowID = -1;
-  if (editrow >= 0) {
-   rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
-  }
+  var data,
   row = {
    uuid: dataRecord.uuid,
-   type: $('#type').val()
+   type: $('#dev_type').val(),
+   direction: $('#dev_direction').val(),
+   value: parseInt($('#dev_value').jqxNumberInput('decimal')),
+   offset: parseInt($('#dev_offset').jqxNumberInput('decimal')),
+   present: $('#dev_present').val(),
+   address: $('#dev_address').val(),
+   subdevice: parseInt($('#dev_subdevice').jqxNumberInput('decimal')),
+   gpiopin: parseInt($('#dev_gpiopin').jqxNumberInput('val')),
+   description: $('#dev_description').val(),
+   comment: $('#dev_comment').val()
   };
-  if (editrow >= 0) {
-   $('#jqxgrid').jqxGrid('updaterow', rowID, row);
-  } else {
-   $('#jqxgrid').jqxGrid('addrow', null, row);
-  }
+  data = 'update=true&' + $.param(row);
+  console.log(data);
+  $.ajax({
+   dataType: 'json',
+   url: url,
+   cache: false,
+   data: data,
+   type: 'POST',
+   success: function(data) {
+    if (data.error) {
+     console.log('update: ' + data.msg);
+     alert('Error: ' + data.msg);
+    } else {
+     console.log('update: success');
+    }
+   },
+   error: function(jqXHR, textStatus, errorThrown) {}
+  });
   $('#popupWindow').jqxWindow('hide');
  });
  createDelElements();
--- a/www/js/set_global.js	Tue Apr 23 19:50:05 2024 +0200
+++ b/www/js/set_global.js	Tue Apr 23 20:45:29 2024 +0200
@@ -156,7 +156,7 @@
    success: function(data) {
     if (data.error) {
      console.log('update: ' + data.msg);
-     alert('Fout: ' + data.msg);
+     alert('Error: ' + data.msg);
     } else {
      console.log('update: success');
     }

mercurial