Some small refactoring
This commit is contained in:
parent
edaa23f0f6
commit
5716584772
15 changed files with 161 additions and 68 deletions
|
|
@ -122,9 +122,9 @@
|
|||
<div class="form-group">
|
||||
<label class="control-label">Type:</label>
|
||||
<select class="form-control" name="type">
|
||||
{{#availableEvents}}
|
||||
{{#availableEventConfigClasses}}
|
||||
<option>{{.getName()}}</option>
|
||||
{{/availableEvents}}
|
||||
{{/availableEventConfigClasses}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
|
@ -142,7 +142,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div id="event-data-conf-template" class="hidden">
|
||||
{{#localEventConf}}
|
||||
{{#availableEventObjectConfig}}
|
||||
<div id="{{.clazz.getName()}}">
|
||||
{{#.params}}
|
||||
<div class="form-group">
|
||||
|
|
@ -158,6 +158,6 @@
|
|||
</div>
|
||||
{{/.params}}
|
||||
</div>
|
||||
{{/localEventConf}}
|
||||
{{/availableEventObjectConfig}}
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
///////////////////////////////// Autostart
|
||||
// --------------------------------------------------------
|
||||
// Autostart
|
||||
// --------------------------------------------------------
|
||||
|
||||
$(function(){
|
||||
$(".toggle-switch").bootstrapSwitch();
|
||||
|
||||
$(".timestamp").relTimestamp();
|
||||
});
|
||||
|
||||
////////////////////////////////////// JQuery helper functions
|
||||
// --------------------------------------------------------
|
||||
// JQuery helper functions
|
||||
// --------------------------------------------------------
|
||||
|
||||
// $.attr() # returns all attributes of an element
|
||||
(function(old) {
|
||||
|
|
@ -28,7 +33,11 @@ $(function(){
|
|||
};
|
||||
})($.fn.attr);
|
||||
|
||||
// converts all timestamps to human readable time and date
|
||||
// --------------------------------------------------------
|
||||
// Timestamps
|
||||
// --------------------------------------------------------
|
||||
|
||||
// Converts all timestamps to human readable time and date
|
||||
$.fn.relTimestamp = function() {
|
||||
return this.each(function() {
|
||||
var timestamp = parseInt($(this).text());
|
||||
|
|
@ -45,10 +54,10 @@ $.fn.relTimestamp = function() {
|
|||
});
|
||||
};
|
||||
|
||||
// --------------------------------------------------------
|
||||
// Chart functions
|
||||
// --------------------------------------------------------
|
||||
|
||||
////////////////////////////////////// Hal functions
|
||||
|
||||
////////////// Chart functions
|
||||
function createChart(elementId, url, updateTime=-1){
|
||||
var tickConf = {count: 20};
|
||||
if (updateTime < 60*60*1000)
|
||||
|
|
@ -127,30 +136,33 @@ function getChartData(json){
|
|||
};
|
||||
}
|
||||
|
||||
////////////// Dynamic forms
|
||||
// --------------------------------------------------------
|
||||
// Dynamic forms
|
||||
// --------------------------------------------------------
|
||||
|
||||
var dynamicConf = {};
|
||||
|
||||
function initDynamicModalForm(modalId, formTemplateId = null, templateID = null){
|
||||
// read in all configurations into global variable (to skip naming issues)
|
||||
if (formTemplateId != null) {
|
||||
dynamicConf[formTemplateId] = [];
|
||||
$("#"+templateID+" div").each(function(){
|
||||
$("#" + templateID + " div").each(function(){
|
||||
dynamicConf[formTemplateId][$(this).attr("id")] = $(this).html();
|
||||
});
|
||||
// Update dynamic inputs
|
||||
$("#"+modalId+" select[name=type]").change(function(){
|
||||
$("#"+modalId+" #"+formTemplateId).html(dynamicConf[formTemplateId][$(this).val()]);
|
||||
$("#" + modalId + " select[name=type]").change(function(){
|
||||
$("#" + modalId + " #" + formTemplateId).html(dynamicConf[formTemplateId][$(this).val()]);
|
||||
});
|
||||
}
|
||||
|
||||
// click event
|
||||
$("#"+modalId).on('show.bs.modal', function (event) {
|
||||
$("#" + modalId).on('show.bs.modal', function (event) {
|
||||
var button = $(event.relatedTarget);
|
||||
var modal = $(this);
|
||||
|
||||
// Reset all inputs
|
||||
if (formTemplateId != null)
|
||||
modal.find("#"+formTemplateId).empty(); // clear form div
|
||||
modal.find("#" + formTemplateId).empty(); // clear form div
|
||||
|
||||
// select dynamic form
|
||||
var selector = modal.find("select[name=type]");
|
||||
|
|
@ -169,7 +181,7 @@ function initDynamicModalForm(modalId, formTemplateId = null, templateID = null)
|
|||
if (value=="true") input.attr("checked", "true");
|
||||
else input.removeAttr("checked");
|
||||
// Add default false value as a unchecked checkbox is not included in the post
|
||||
input.parent().prepend("<input type='hidden' name='"+input.attr("name")+"' value='false' />");
|
||||
input.parent().prepend("<input type='hidden' name='" + input.attr("name") + "' value='false' />");
|
||||
} else {
|
||||
input.val(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,9 +224,9 @@
|
|||
<div class="form-group">
|
||||
<label class="control-label">Type:</label>
|
||||
<select class="form-control" name="type">
|
||||
{{#availableSensors}}
|
||||
{{#availableSensorConfigClasses}}
|
||||
<option>{{.getName()}}</option>
|
||||
{{/availableSensors}}
|
||||
{{/availableSensorConfigClasses}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
|
|
@ -251,7 +251,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div id="sensor-data-conf-template" class="hidden">
|
||||
{{#localSensorConf}}
|
||||
{{#availableSensorObjectConfig}}
|
||||
<div id="{{.clazz.getName()}}">
|
||||
{{#.params}}
|
||||
<div class="form-group">
|
||||
|
|
@ -267,7 +267,7 @@
|
|||
</div>
|
||||
{{/.params}}
|
||||
</div>
|
||||
{{/localSensorConf}}
|
||||
{{/availableSensorObjectConfig}}
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue