iobroker.nuki
Version:
ioBroker Nuki Adapter
180 lines (170 loc) • 7.09 kB
HTML
<html>
<head>
<!-- these 4 files always have to be included -->
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.css">
<link rel="stylesheet" type="text/css" href="../../css/adapter.css"/>
<script type="text/javascript" src="../../lib/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
<!-- these files always have to be included -->
<script type="text/javascript" src="../../js/translate.js"></script>
<script type="text/javascript" src="../../lib/js/materialize.js"></script>
<script type="text/javascript" src="../../js/adapter-settings.js"></script>
<script type="text/javascript" src="words.js"></script>
<style>
.m .col .s elect-wrapper+label {
top: -26px;
}
.m span{
font-size: 0.9em;
}
</style>
<!-- you have to define 2 functions in the global scope: -->
<script type="text/javascript">
function showHideSettings() {
if ($('#autoupd').prop('checked')) {
$('._interval').show();
} else {
$('._interval').hide();
}
if ($('#host_cb').prop('checked')) {
$('._host_port').show();
} else {
$('._host_port').hide();
}
if ($('#bridge_type').val() == '1') {
$('._fp_token').show();
} else {
$('._fp_token').hide();
}
}
// the function loadSettings has to exist ...
function load(settings, onChange) {
// example: select elements with id=key and class=value and insert value
if (!settings) return;
$('.value').each(function () {
var $key = $(this);
var id = $key.attr('id');
if ($key.attr('type') === 'checkbox') {
// do not call onChange direct, because onChange could expect some arguments
$key.prop('checked', settings[id]).change(function() {
onChange();
});
} else {
// do not call onChange direct, because onChange could expect some arguments
$key.val(settings[id]).change(function() {
onChange();
}).keyup(function() {
onChange();
});
}
});
showHideSettings();
onChange(false);
M.updateTextFields(); // function Materialize.updateTextFields(); to reinitialize all the Materialize labels on the page if you are dynamically adding inputs.
$('#host_cb').change(function () {
showHideSettings();
});
$('#autoupd').change(function () {
showHideSettings();
});
$('#bridge_type').change(function () {
showHideSettings();
});
}
// ... and the function save has to exist.
// you have to make sure the callback is called with the settings object as first param!
function save(callback) {
// example: select elements with class=value and build settings object
var obj = {};
$('.value').each(function () {
var $this = $(this);
if ($this.attr('type') === 'checkbox') {
obj[$this.attr('id')] = $this.prop('checked');
} else {
obj[$this.attr('id')] = $this.val();
}
});
callback(obj);
}
</script>
</head>
<body>
<!-- you have to put your config page in a div with id adapter-container -->
<div class="m adapter-container">
<div class="row">
<!-- Forms are the standard way to receive user inputted data.
Learn more http://materializecss.com/forms.html-->
<div class="row">
<div class="input-field col s6">
<img src="nuki-logo.png" class="logo">
</div>
</div>
<div class="row">
<div class="input-field col s12 m6 l4">
<input class="value" type="text" id="bridge_name"/>
<label for="bridge_name" class="translate">name</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m6 l4">
<input class="value" type="text" id="bridge_ip"/>
<label for="bridge_ip" class="translate">ip</label>
<span for="bridge_ip" class="translate">ipeg</span>
</div>
<div class="input-field col s12 m6 l4">
<input class="value" type="number" id="bridge_port"/>
<label for="bridge_port" class="translate">bridge_port</label>
</div>
<div class="input-field col s12 m6 l4">
<select class="value" type="number" id="bridge_type">
<option value="1" class="translate">Hardware</option>
<option value="2" class="translate">Software</option>
</select>
<label for="bridge_type" class="translate">bridge_type</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m6 l4">
<input class="value" type="text" id="token" />
<label for="token" class="translate">token</label>
</div>
<!-- </div> -->
<!-- <div class="row _fp_token"> -->
<div class="input-field col s12 m6 l4 _fp_token">
<input class="value" type="checkbox" id="fp_token"/>
<label for="fp_token" class="translate">fp_token</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m4">
<input class="value" type="checkbox" id="host_cb"/>
<label for="host_cb" class="translate">host_cb</label>
</div>
</div>
<div class="row _host_port">
<div class="input-field col s12 m6 l4">
<input class="value" type="number" id="host_port"/>
<label for="host_port" class="translate">host_port</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m4">
<input class="value" type="checkbox" id="autoupd"/>
<label for="autoupd" class="translate">autoupd</label>
</div>
</div>
<div class="row _interval">
<div class="input-field col s12 m6 l4">
<input class="value" type="number" id="interval"/>
<label for="interval" class="translate">interval</label>
</div>
</div>
<div class="row">
<div class="col s12">
<p class="translate">on save adapter restarts with new config immediately</p>
</div>
</div>
</div>
</div>
</body>
</html>