More work on single device permissions.
Ylian Saint-Hilaire committed
Mar 26, 2020 at 20:32 UTC
110cf49b482304942372a1432ba0aa3d9bd01cfc
1 file changed
+9
-6
views/default.handlebars
+9
-6
@@ -8408,7 +8408,7 @@
8408
meshserver.send({ action: 'editmesh', meshid: currentMesh._id, flags: flags });
8409
}
8410
8411
- function p20showAddMeshUserDialog(userid) {
8411
+ function p20showAddMeshUserDialog(userid, selected) {
8412
if (xxdialogMode) return false;
8413
var x = '';
8414
if (userid == null) {
@@ -8432,11 +8432,12 @@
8432
for (var i in meshes) { if ((currentUserGroup.links == null) || (currentUserGroup.links[i] == null)) { y += '<option value=' + encodeURIComponent(i) + '>' + EscapeHtml(meshes[i].name) + '</option>'; } }
8433
x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog() id=dp2groupid style=width:100%>' + y + '</select></div>');
8434
} else if (userid === 4) {
8435
- var y = '', firstMeshId = null;
8436
- for (var i in meshes) { y += '<option value=' + encodeURIComponent(meshes[i]._id) + '>' + EscapeHtml(meshes[i].name) + '</option>'; if (firstMeshId == null) { firstMeshId = meshes[i]._id; } }
8435
+ var y = '', selectedMeshId = null, selectedNode = null;
8436
+ if (selected != null) { selectedNode = getNodeFromId(decodeURIComponent(selected)); if (selectedNode != null) { selectedMeshId = selectedNode.meshid; } }
8437
+ for (var i in meshes) { if (selectedMeshId == null) { selectedMeshId = meshes[i]._id; } y += '<option value=' + encodeURIComponent(meshes[i]._id) + ((selectedMeshId == meshes[i]._id)?' selected':' ') + '>' + EscapeHtml(meshes[i].name) + '</option>'; }
8438
x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20changeMeshAddMeshUserDialog(4) id=dp2meshid style=width:100%>' + y + '</select></div>');
8439
y = '';
8439
- for (var i in nodes) { if (nodes[i].meshid == firstMeshId) { y += '<option value=' + encodeURIComponent(nodes[i]._id) + '>' + EscapeHtml(nodes[i].name) + '</option>'; } }
8440
+ for (var i in nodes) { if (nodes[i].meshid == selectedMeshId) { y += '<option value=' + encodeURIComponent(nodes[i]._id) + ((selectedNode == nodes[i])?' selected':' ') + '>' + EscapeHtml(nodes[i].name) + '</option>'; } }
8441
x += addHtmlValue("Device", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog(4) id=dp2nodeid style=width:100%>' + y + '</select></div>');
8442
} else {
8443
userid = decodeURIComponent(userid);
@@ -8482,7 +8483,9 @@
8483
} else if (userid === 3) {
8484
setDialogMode(2, "Add Device Group", 3, p20showAddMeshUserDialogEx, x, userid);
8485
} else if (userid === 4) {
8485
- setDialogMode(2, "Add Device", 3, p20showAddMeshUserDialogEx, x, userid);
8486
+ setDialogMode(2, (selected == null)?"Add Device Permissions":"Edit Device Permissions", 3, p20showAddMeshUserDialogEx, x, userid);
8487
+ QE('dp2meshid', selected == null);
8488
+ QE('dp2nodeid', selected == null);
8489
} else {
8490
if (userid.startsWith('ugrp/')) {
8491
setDialogMode(2, "Edit Device Group Permissions", 7, p20showAddMeshUserDialogEx, x, userid);
@@ -10236,7 +10239,7 @@
10239
var nodename = node?EscapeHtml(node.name):('<i>' + "Unknown Device" + '</i>');
10240
if (r == 0xFFFFFFFF) rights = "Full Device Rights"; else if (r == 0) rights = "No Rights";
10241
if ((currentUser._id != userinfo._id) && ((cr & 2) != 0)) { trash = '<a href=# onclick=\'return p30removeNodeFromUser(event,"' + encodeURIComponent(node._id) + '")\' title=\"' + "Remove user rights to this device group" + '\" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
10239
- x += '<tr ' + (((++count % 2) == 0) ? 'style=background-color:#DDD' : '') + '><td><div title=\"' + "Device" + '\" class=si' + node.icon + '></div><div> ' + nodename + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></td></tr>';
10242
+ x += '<tr ' + (((++count % 2) == 0) ? 'style=background-color:#DDD' : '') + '><td><div style=cursor:pointer onclick=p20showAddMeshUserDialog(4,\"' + encodeURIComponent(node._id) + '\")><div title=\"' + "Device" + '\" class=si' + node.icon + '></div><div> ' + nodename + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></div></td></tr>';
10243
}
10244
}
10245
}