yunkong2.mihome/admin/index_m.html

214 lines
8.3 KiB
HTML
Raw Normal View History

2019-01-16 11:42:54 +08:00
<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-1.11.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="../../js/tableEditor.js"></script>
<script type="text/javascript" src="words.js"></script>
<style>
.m th {
border-radius: 0 !important;
}
</style>
<script type="text/javascript">
'use strict';
var keys = [];
function load(settings, onChange) {
if (!settings) return;
if (!settings.keys) {
settings.keys = [];
}
if (settings.heartbeatTimeout === undefined) {
settings.heartbeatTimeout = 20000;
}
if (settings.restartInterval === undefined) {
settings.restartInterval = 30000;
}
fillSelectIPs('#bind', settings.bind, false, true, function () {
$('#bind').select();
});
$('.value').each(function () {
var key = $(this).attr('id');
var $value = $('#' + key + '.value');
if ($value.attr('type') === 'checkbox') {
$value.prop('checked', settings[key]).on('change', function() {
onChange();
});
} else {
$value.val(settings[key]).on('change', function() {
onChange();
}).keyup(function() {
onChange();
});
}
});
$('#search')/*.button({
label: _('Search'),
icons: {
primary: ' ui-icon-refresh'
}
})*/.click(function () {
$('#search').addClass('disabled');
sendTo(null, 'browse', {port: parseInt($('#port').val(), 10), bind: $('#bind').val()}, function (list) {
$('#search').removeClass('disabled');
keys = table2values('values');
if (list && list.length) {
var changed = false;
for (var i = 0; i < list.length; list++) {
var found = false;
for (var k = 0; k < keys.length; k++) {
if (keys[k].ip.trim() === list[i]) {
found = true;
break;
}
}
if (!found) {
keys.push({ip: list[i], key: ''});
changed = true;
}
}
if (keys.length > 1) {
for (var kk = keys.length - 1; kk >= 0; kk--) {
if (!keys[kk].ip && !keys[kk].key) {
keys.splice(kk, 1);
changed = true;
}
}
}
if (changed) {
onChange();
values2table('values', keys, {onChange: onChange});
}
}
});
});
keys = settings.keys || [];
values2table('values', keys, {onChange: onChange});
getIsAdapterAlive(function (isAlive) {
if (isAlive || common.enabled) {
$('#search').removeClass('disabled');
} else {
$('#search').addClass('disabled');
}
});
onChange(false);
}
function save(callback) {
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();
}
});
obj.interval = parseInt(obj.interval, 10) || 0;
if (obj.interval > 9000) obj.interval = 9000;
// Get edited table
obj.keys = table2values('values');
callback(obj);
}
</script>
</head>
<body>
<div class="adapter-container m">
<div class="row">
<div class="col s12">
<ul class="tabs">
<li class="tab col s2"><a href="#tab-main" class="translate active">Main settings</a></li>
<li class="tab col s2"><a href="#tab-keys" class="translate">Gateway keys</a></li>
</ul>
</div>
<div id="tab-main" class="col s12 page">
<div class="row">
<div class="col s12 m4 l2">
<img src="mihome.png" class="logo">
</div>
</div>
<div class="row">
<div class="col s12 m8 l5">
<select class="value" id="bind"></select>
<label class="translate" for="bind">yunkong2 IP:</label>
</div>
<div class="col s12 m4 l1">
<input class="value" id="port" min="0" max="65565" maxlength="5" type="number"/>
<label class="translate" for="port">yunkong2 Port:</label>
</div>
</div>
<div class="row">
<div class="col s12 m8 l5">
<input class="value" id="heartbeatTimeout" min="0" max="120000" type="number"/>
<label class="translate" for="heartbeatTimeout">heartbeatTimeout</label>
</div>
<div class="col s12 m4 l1">
<input class="value" id="restartInterval" min="1000" max="120000" type="number"/>
<label class="translate" for="restartInterval">restartInterval</label>
</div>
</div>
<div class="row">
<div class="col s12 m8 l5">
<input class="value" id="key" />
<label class="translate" for="key">Default Gateway Key:</label>
</div>
<div class="col s12 m4 l1">
<input class="value" id="interval" min="0" max="9000" maxlength="4" type="number"/>
<label class="translate" for="interval">Double key interval (ms):</label>
</div>
</div>
</div>
<div id="tab-keys" class="col s12 page">
<div id="values">
<div class="row">
<div class="col s12">
<a class="btn-floating waves-effect waves-light table-button-add"><i class="material-icons">add</i></a>
<a class="waves-effect waves-light btn" id="search"><i class="material-icons">search</i><span class="translate">Search</span></a>
</div>
</div>
<div class="row">
<div class="col s12">
<table class="table-values" style="width: 100%;">
<thead>
<tr>
<th data-name="_index" style="width: 40px" class="translate"></th>
<th data-name="ip" style="width: 120px" data-style="width: 120px" class="translate">IP Address</th>
<th data-name="key" style="width: 100%; text-align: left;" data-style="width: 100%" class="translate">Key</th>
<th data-buttons="delete" style="width: 40px"></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>