fix(config): update device list on getway change

Also set the device name as name by default
This commit is contained in:
Pierre CLEMENT
2017-12-31 20:59:38 +01:00
parent 59a79f0cc1
commit 5c27c9ff6e
4 changed files with 125 additions and 65 deletions

View File

@@ -23,10 +23,37 @@
oneditprepare: function() {
var node = this;
// Get the config node id from the select box:
var configNodeID = $('#node-input-gateway').val();
// Get the config node using the ID:
var configNode = RED.nodes.node(configNodeID);
if(node.sid) {
$('#node-input-sid').val(node.sid);
}
function changeGateway(model) {
var configNodeID = $('#node-input-gateway').val();
if (configNodeID) {
var configNode = RED.nodes.node(configNodeID);
if(configNode) {
$('#node-input-sid').empty();
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === model) {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
if(node.sid) {
$('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
}
}
}
}
$("#node-input-sid").change(function () {
if(!this.name) {
$("#node-input-name").val($('#node-input-sid option:selected').text());
}
});
$("#node-input-gateway").change(function () {
changeGateway("sensor_ht");
});
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -38,18 +65,6 @@
$(".node-input-msg").hide();
$("#node-input-output").val(node.output);
$("#node-input-gateway").change(function () {
});
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === "sensor_ht") {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
$('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;
@@ -88,7 +103,7 @@
<input type="text" id="node-input-humidity"/>
</div>
<div class="form-row node-input-msg">
<label for="node-input-pressure"><i class="fa fa-mixcloud"></i> Pressure</label>
<label for="node-input-pressure"><i class="fa fa-tachometer"></i> Pressure</label>
<input type="text" id="node-input-pressure"/>
</div>
<div class="form-row node-input-msg">

View File

@@ -21,10 +21,37 @@
oneditprepare: function() {
var node = this;
// Get the config node id from the select box:
var configNodeID = $('#node-input-gateway').val();
// Get the config node using the ID:
var configNode = RED.nodes.node(configNodeID);
if(node.sid) {
$('#node-input-sid').val(node.sid);
}
function changeGateway(model) {
var configNodeID = $('#node-input-gateway').val();
if (configNodeID) {
var configNode = RED.nodes.node(configNodeID);
if(configNode) {
$('#node-input-sid').empty();
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === model) {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
if(node.sid) {
$('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
}
}
}
}
$("#node-input-sid").change(function () {
if(!this.name) {
$("#node-input-name").val($('#node-input-sid option:selected').text());
}
});
$("#node-input-gateway").change(function () {
changeGateway("magnet");
});
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -33,18 +60,6 @@
$(".node-input-msg").hide();
}
});
$("#node-input-gateway").change(function () {
});
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === "magnet") {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
$('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;

View File

@@ -21,10 +21,37 @@
oneditprepare: function() {
var node = this;
// Get the config node id from the select box:
var configNodeID = $('#node-input-gateway').val();
// Get the config node using the ID:
var configNode = RED.nodes.node(configNodeID);
if(node.sid) {
$('#node-input-sid').val(node.sid);
}
function changeGateway(model) {
var configNodeID = $('#node-input-gateway').val();
if (configNodeID) {
var configNode = RED.nodes.node(configNodeID);
if(configNode) {
$('#node-input-sid').empty();
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === model) {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
if(node.sid) {
$('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
}
}
}
}
$("#node-input-sid").change(function () {
if(!this.name) {
$("#node-input-name").val($('#node-input-sid option:selected').text());
}
});
$("#node-input-gateway").change(function () {
changeGateway("magnet");
});
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -33,18 +60,6 @@
$(".node-input-msg").hide();
}
});
$("#node-input-gateway").change(function () {
});
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === "motion") {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
$('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;

View File

@@ -21,10 +21,37 @@
oneditprepare: function() {
var node = this;
// Get the config node id from the select box:
var configNodeID = $('#node-input-gateway').val();
// Get the config node using the ID:
var configNode = RED.nodes.node(configNodeID);
if(node.sid) {
$('#node-input-sid').val(node.sid);
}
function changeGateway(model) {
var configNodeID = $('#node-input-gateway').val();
if (configNodeID) {
var configNode = RED.nodes.node(configNodeID);
if(configNode) {
$('#node-input-sid').empty();
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === model) {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
if(node.sid) {
$('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
}
}
}
}
$("#node-input-sid").change(function () {
if(!this.name) {
$("#node-input-name").val($('#node-input-sid option:selected').text());
}
});
$("#node-input-gateway").change(function () {
changeGateway("magnet");
});
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -36,18 +63,6 @@
$(".node-input-msg").hide();
$("#node-input-output").val(node.output);
$("#node-input-gateway").change(function () {
});
for (key in configNode.deviceList) {
var device = configNode.deviceList[key];
if (device.model === "switch") {
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
}
}
$('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;