Added device delete

Tue, 23 Apr 2024 19:50:05 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 23 Apr 2024 19:50:05 +0200
changeset 700
942af738157c
parent 699
35382668a140
child 701
e50a5003c7ac

Added device delete

www/getdevices.php file | annotate | diff | comparison | revisions
www/js/set_devices.js file | annotate | diff | comparison | revisions
--- a/www/getdevices.php	Tue Apr 23 16:52:13 2024 +0200
+++ b/www/getdevices.php	Tue Apr 23 19:50:05 2024 +0200
@@ -68,6 +68,14 @@
 
 } else if (isset($_POST['del'])) {
 
+    $answer = send_cmd("DEVICE DEL " . $_POST['uuid']);
+    $arr = explode("\r\n", $answer);
+    if (! startsWith($arr[0], "211")) {
+        $response['error'] = true;
+        $response['msg'] = $arr[0];
+    }
+    exit(json_encode($response));
+
 } else {
 
     $answer = send_cmd("DEVICE JSON");
--- a/www/js/set_devices.js	Tue Apr 23 16:52:13 2024 +0200
+++ b/www/js/set_devices.js	Tue Apr 23 19:50:05 2024 +0200
@@ -187,6 +187,7 @@
        error: function(jqXHR, textStatus, errorThrown) {
        }
       });
+      $('#jqxgrid').jqxGrid('updatebounddata');
      } else {
       console.log('Add wrong type');
      }
@@ -195,7 +196,8 @@
   },
   columns: [
    { text: 'Address', datafield: 'address', width: 200 },
-   { text: 'Subdevice', datafield: 'subdevice', width: 100 },
+   { text: 'Sub', datafield: 'subdevice', width: 60 },
+   { text: 'Type', datafield: 'type', width: 100 },
    { text: 'Direction', datafield: 'direction', width: 120 },
    { text: 'Value', datafield: 'value', width: 80 },
    { text: 'Description', datafield: 'description' },
@@ -253,8 +255,29 @@
    // Open a popup to confirm this action.
    $('#eventWindow').jqxWindow('open');
    $('#delOk').click(function() {
-    var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
-    $('#jqxgrid').jqxGrid('deleterow', rowID);
+    console.log('Del ' + $('#dev_uuid').val());
+    var data,
+    data = 'del=true&uuid=' + $('#dev_uuid').val();
+    console.log(data);
+    $.ajax({
+     dataType: 'json',
+     url: url,
+     cache: false,
+     data: data,
+     type: 'POST',
+     success: function(data) {
+      if (data.error) {
+       console.log('del: ' + data.msg);
+       alert('Error: ' + data.msg);
+      } else {
+       console.log('del: success');
+      }
+     },
+     error: function(jqXHR, textStatus, errorThrown) {}
+    });
+    $('#jqxgrid').jqxGrid('updatebounddata');
+//    var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
+//    $('#jqxgrid').jqxGrid('deleterow', rowID);
    });
   }
   $('#popupWindow').jqxWindow('hide');

mercurial