@@ -1728,7 +1725,7 @@
{ text: 'Refresh', callback: function () { refreshMap(true, true); } },
{ text: 'Zoom to fit extent', callback: function () { zoomToFitExtent(); } },
{ text: 'Center map here', callback: function(obj) { xxmap.mapView.animate({ center: obj.coordinate } ); } },
- { text: 'Place a node', callback: function (obj) { placeNode(obj.coordinate); } }
+ { text: 'Place node here', callback: function(obj) { placeNode(obj.coordinate); } }
];
function stringToIntHash(str) {
@@ -2048,33 +2045,24 @@
// Called When Place a node option is clicked from context menu
function placeNode(coords) {
if (xxdialogMode) return;
- clearSelectedNode();
- var x = '
  
';
- x += '
';
- var count = 0;
- var table = updatePlaceNodeTable('', false);
- if (table != 0) { x += table; count = 1; x += '
'; } else { count = 0;}
- if (count == 0) {
- var noNodesFound = '';
- if (!meshExists()) {
- noNodesFound = '
No nodes found. To create a mesh network and add devices, go to My Account page.
';
- } else {
- noNodesFound = '
No nodes found. To add devices, go to My Devices page.
';
- }
- setDialogMode(2, "Select a Node to place marker", 1, null, noNodesFound, null);
- } else {
- setDialogMode(2, "Select a Node to place marker", 18, placeNodeEx, x, coords);
+ var x = '
  
No devices found.
';
+ for (var i in nodes) {
+ x += '
';
+ x += '
' + nodes[i].name + '
';
}
+ setDialogMode(2, "Select a node to place", 3, placeNodeEx, x + '
', coords);
+ onPlaceNodeInputChange();
}
- function placeNodeEx(button, coords){
- for (var i in xxmap.selectedNodes) {
- var node = getNodeFromId(i);
- if (node) {
- var feature = xxmap.markersSource.getFeatureById(i);
- var v = ol.proj.transform(coords, 'EPSG:3857', 'EPSG:4326');
- var vx = [ v[1], v[0] ]; // Flip the coordinates around, lat/long
- if (button == 2) {
+ function placeNodeEx(button, coords) {
+ var elements = document.getElementsByName("PlaceMapDeviceCheckbox");
+ for (var i in elements) {
+ if (elements[i].checked) {
+ var node = getNodeFromId(elements[i].id.substring(0, elements[i].id.length - 8));
+ if (node) {
+ var feature = xxmap.markersSource.getFeatureById(i);
+ var v = ol.proj.transform(coords, 'EPSG:3857', 'EPSG:4326');
+ var vx = [ v[1], v[0] ]; // Flip the coordinates around, lat/long
if (feature) {
feature.getGeometry().setCoordinates(coords);
var activeInteraction = getActiveInteractions(feature);
@@ -2087,117 +2075,47 @@
meshserver.Send({ action: 'changedevice', nodeid: node._id, userloc: vx }); // This Node is not yet added to maps.
}
}
- else if (button == 1) { //Dont send changes to server since its just 'place'
- if (feature) {
- feature.getGeometry().setCoordinates(coords);
- modifyMarkerloc(feature);
- } else {
- //if (map_parseNodeLoc(node.iploc) != null) {
- addFeature(node, v[0], v[1]);
- var newFeature = xxmap.markersSource.getFeatureById(node._id);
- modifyMarkerloc(newFeature);
- //}
- }
- }
}
}
}
- // Close place node dialog
- function closePNDialog(id){
- dialogclose(1);
- switch (id) {
- case 1:
- Q('viewselect').options.selectedIndex = 0;
- onDeviceViewChange();
- break;
- case 2:
- go(2); //Go to My Accounts tab
- break;
- }
+ // Called when the user changes the search box
+ function onPlaceNodeInputChange() {
+ updatePlaceNodeTable(Q('selectnode-search').value.trim().toLowerCase());
}
- // On input search change in Place Node dialogue box
- function onPNSearchInputChange() {
- var inputSearchData = Q('selectnode-search').value;
- QH('placenode', '');
- updatePlaceNodeTable(inputSearchData.trim().toLowerCase(), true);
- }
-
- //Update the place Node Table
- function updatePlaceNodeTable(inputSearch,searchFlag) {
- var x = '
';
- var count = 0;
+ // Update the list of devices in the "place on map" table
+ function updatePlaceNodeTable(inputSearch) {
+ var elements = document.getElementsByName("PlaceMapDeviceCheckbox"), count = 0;
for (var i in nodes) {
- if (nodes[i].mtype == 2) {
- if ((nodes[i].name.toLowerCase().indexOf(inputSearch) >= 0 || inputSearch == '') || (nodes[i].hostl != undefined && nodes[i].hostl.toLowerCase().indexOf(inputSearch) >= 0)) {
- count++;
- x+='
';
- if (searchFlag) { //Flag is true when user searches for a Device using placeNode search input.
- if (count == 0) { //If No Device name is found that matches the search
- QH('placenode', '
'; }
+ QH('placenode', '');
+ */
}
- //On click-change the checkbox class and save selected Device
- function selectNodetoplace(id){
- var imgeElement = Q(id + '-img');
- if (xxmap.selectedNodes[id]) { //If user clicks on already selected Device.
- imgeElement.classList.remove('fa-check-square-o');
- imgeElement.classList.add('fa-square');
- delete xxmap.selectedNodes[id];
- checkSelectedNodes();
- } else {
- imgeElement.classList.remove('fa-square');
- imgeElement.classList.add('fa-check-square-o');
- xxmap.selectedNodes[id] = { color: Q(id+'-rowid').style.backgroundColor};
- QE('idx_dlgPlaceandSave', true);
- QE('idx_dlgPlaceButton', true);
- }
- }
+ // Called when a user clicks on a device to toggle selection for placement on map.
+ function selectNodeToPlace(e, id) {
+ // Toggle checkbox if needed
+ if (e.target.name != 'PlaceMapDeviceCheckbox') { var inputElement = Q(id + '-checkid'); inputElement.checked = !inputElement.checked; }
- function checkSelectedNodes() {
- var c = 0;
- for (var i in xxmap.selectedNodes) { if (xxmap.selectedNodes[i]) { c++; } }
- if (c == 0) { //If no nodes are checked then disable place and Save buttons
- QE('idx_dlgPlaceandSave', false);
- QE('idx_dlgPlaceButton', false);
- }
- }
-
- // Set selected node to null
- function clearSelectedNode() {
- xxmap.selectedNodes = {};
- QE('idx_dlgPlaceandSave', false);
- QE('idx_dlgPlaceButton', false);
- }
-
- // Change radio button on mouseover and out for 'select a node to place dialog'
- function changeRadioImg(name) {
- var index = name.indexOf("mouseout");
- var element = name.split('!#!');
- if (!xxmap.selectedNodes[element[0]]) {
- var imgeElement= Q(element[0]+'-img');
- if (index > -1) {
- imgeElement.classList.remove('fa-square');
- imgeElement.classList.add('fa-square-o');
- } else {
- imgeElement.classList.remove('fa-square-o');
- imgeElement.classList.add('fa-square');
- }
- }
+ // Check button state
+ var elements = document.getElementsByName("PlaceMapDeviceCheckbox"), checkcount = 0;
+ for (var i in elements) { if (elements[i].checked) checkcount++; }
+ QE('idx_dlgOkButton', checkcount > 0);
}
// Add option for available meshes in mesh Dropdown
@@ -4537,16 +4455,12 @@
xxdialogFunc = f;
xxdialogButtons = b;
xxdialogTag = tag;
- QE('idx_dlgPlaceandSave', false);
- QE('idx_dlgPlaceButton', false);
QE('idx_dlgOkButton', true);
QV('idx_dlgOkButton', b & 1);
QV('idx_dlgCancelButton', b & 2);
QV('id_dialogclose', (b & 2) || (b & 8));
QV('idx_dlgDeleteButton', b & 4);
QV('idx_dlgButtonBar', b & 7);
- QV('idx_dlgPlaceButton', (b & 18) && (b%2 == 0));
- QV('idx_dlgPlaceandSave', (b & 18) && (b%2 == 0));
if (y) QH('id_dialogtitle', y);
for (var i = 1; i < 24; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added
QV('dialog', x);