Update sensor configuration to use util function
This commit is contained in:
parent
86cab179a8
commit
a8ed1ef5a9
2 changed files with 25 additions and 38 deletions
7
resource/web/js/hal.js
vendored
7
resource/web/js/hal.js
vendored
|
|
@ -130,8 +130,9 @@ function getChartData(json){
|
||||||
////////////// Dynamic forms
|
////////////// Dynamic forms
|
||||||
var dynamicConf = {};
|
var dynamicConf = {};
|
||||||
|
|
||||||
function initDynamicModalForm(modalId, formTemplateId, templateID){
|
function initDynamicModalForm(modalId, formTemplateId = null, templateID = null){
|
||||||
// read in all configurations into global variable (to skip naming issues)
|
// read in all configurations into global variable (to skip naming issues)
|
||||||
|
if (formTemplateId != null) {
|
||||||
dynamicConf[formTemplateId] = [];
|
dynamicConf[formTemplateId] = [];
|
||||||
$("#"+templateID+" div").each(function(){
|
$("#"+templateID+" div").each(function(){
|
||||||
dynamicConf[formTemplateId][$(this).attr("id")] = $(this).html();
|
dynamicConf[formTemplateId][$(this).attr("id")] = $(this).html();
|
||||||
|
|
@ -140,11 +141,15 @@ function initDynamicModalForm(modalId, formTemplateId, templateID){
|
||||||
$("#"+modalId+" select[name=type]").change(function(){
|
$("#"+modalId+" select[name=type]").change(function(){
|
||||||
$("#"+modalId+" #"+formTemplateId).html(dynamicConf[formTemplateId][$(this).val()]);
|
$("#"+modalId+" #"+formTemplateId).html(dynamicConf[formTemplateId][$(this).val()]);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// click event
|
// click event
|
||||||
$("#"+modalId).on('show.bs.modal', function (event) {
|
$("#"+modalId).on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget);
|
var button = $(event.relatedTarget);
|
||||||
var modal = $(this);
|
var modal = $(this);
|
||||||
|
|
||||||
// Reset all inputs
|
// Reset all inputs
|
||||||
|
if (formTemplateId != null)
|
||||||
modal.find("#"+formTemplateId).empty(); // clear form div
|
modal.find("#"+formTemplateId).empty(); // clear form div
|
||||||
|
|
||||||
// select dynamic form
|
// select dynamic form
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<div class="panel panel-default drop-shadow">
|
<div class="panel panel-default drop-shadow">
|
||||||
<div class="panel-heading">Local Sensors</div>
|
<div class="panel-heading">Local Sensors</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>List of local sensors.</p>
|
<p>This is a local list of sensors connected to this node.</p>
|
||||||
|
|
||||||
<table class="table table-hover table-condensed">
|
<table class="table table-hover table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
<th>Public</th>
|
<th>Public</th>
|
||||||
<th>Configuration</th>
|
<th>Configuration</th>
|
||||||
<th>
|
<th>
|
||||||
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
|
<button class="btn btn-default btn-xs pull-right" data-toggle="modal" data-target="#sensorModal"
|
||||||
data-target="#sensorModal">
|
data-action="create_local_sensor">
|
||||||
<span class="glyphicon glyphicon-plus"></span>
|
<span class="glyphicon glyphicon-plus"></span>
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
|
|
@ -30,8 +30,7 @@
|
||||||
<input type="hidden" name="id" value="{{.getId()}}">
|
<input type="hidden" name="id" value="{{.getId()}}">
|
||||||
|
|
||||||
<div class="btn-toolbar pull-right">
|
<div class="btn-toolbar pull-right">
|
||||||
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
|
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#sensorModal"
|
||||||
data-target="#sensorModal"
|
|
||||||
data-action="modify_local_sensor"
|
data-action="modify_local_sensor"
|
||||||
data-id="{{.getId()}}"
|
data-id="{{.getId()}}"
|
||||||
data-name="{{.getName()}}"
|
data-name="{{.getName()}}"
|
||||||
|
|
@ -78,9 +77,8 @@
|
||||||
<td>{{.getDeviceConfig()}}</td>
|
<td>{{.getDeviceConfig()}}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-toolbar pull-right">
|
<div class="btn-toolbar pull-right">
|
||||||
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
|
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#sensorModal"
|
||||||
data-target="#sensorModal"
|
data-action="create_local_sensor">
|
||||||
data-action="create_local_sensor"
|
|
||||||
data-type="{{.getType()}}"
|
data-type="{{.getType()}}"
|
||||||
{{#.getDeviceConfigurator().getConfiguration()}}
|
{{#.getDeviceConfigurator().getConfiguration()}}
|
||||||
data-{{.getName()}}="{{.getString()}}"
|
data-{{.getName()}}="{{.getString()}}"
|
||||||
|
|
@ -112,8 +110,8 @@
|
||||||
<th>Hostname</th>
|
<th>Hostname</th>
|
||||||
<th>Port</th>
|
<th>Port</th>
|
||||||
<th>
|
<th>
|
||||||
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
|
<button class="btn btn-default btn-xs pull-right" data-toggle="modal" data-target="#userModal"
|
||||||
data-target="#userModal">
|
data-action="create_external_user">
|
||||||
<span class="glyphicon glyphicon-plus"></span>
|
<span class="glyphicon glyphicon-plus"></span>
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
|
|
@ -130,8 +128,7 @@
|
||||||
<input type="hidden" name="id" value="{{.getId()}}">
|
<input type="hidden" name="id" value="{{.getId()}}">
|
||||||
|
|
||||||
<div class="btn-toolbar pull-right">
|
<div class="btn-toolbar pull-right">
|
||||||
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
|
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#userModal"
|
||||||
data-target="#userModal"
|
|
||||||
data-action="modify_external_user"
|
data-action="modify_external_user"
|
||||||
data-id="{{.getId()}}"
|
data-id="{{.getId()}}"
|
||||||
data-hostname="{{.getHostname()}}"
|
data-hostname="{{.getHostname()}}"
|
||||||
|
|
@ -204,22 +201,7 @@
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
initDynamicModalForm("sensorModal", "sensor-data-conf", "sensor-data-conf-template");
|
initDynamicModalForm("sensorModal", "sensor-data-conf", "sensor-data-conf-template");
|
||||||
|
initDynamicModalForm("userModal");
|
||||||
$("#userModal").on('show.bs.modal', function (event) {
|
|
||||||
var button = $(event.relatedTarget);
|
|
||||||
var modal = $(this);
|
|
||||||
modal.find("input[type=text]").val(""); // Reset all inputs
|
|
||||||
if(button.data("id") >= 0){ // edit
|
|
||||||
modal.find("input[name=action]").val("modify_external_user");
|
|
||||||
modal.find("input[name=id]").val(button.data("id"));
|
|
||||||
modal.find("input[name=hostname]").val(button.data("hostname"));
|
|
||||||
modal.find("input[name=port]").val(button.data("port"));
|
|
||||||
}
|
|
||||||
else{ // create
|
|
||||||
modal.find("input[name=action]").val("create_external_user");
|
|
||||||
modal.find("input[name=id]").val(-1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue