220 lines
8.2 KiB
HTML
220 lines
8.2 KiB
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>
|
|
<script type="text/javascript" src="../../lib/js/ace-1.2.0/ace.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 .select-wrapper+label {
|
|
top: -26px;
|
|
}
|
|
.m span {
|
|
font-size: 12px;
|
|
}
|
|
#wrapperConfig {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
#tab-json>.row {
|
|
height: calc(100% - 20px);
|
|
}
|
|
#tab-json .col {
|
|
height: 100%;
|
|
}
|
|
.adapter-container>.row {
|
|
height: 100%;
|
|
}
|
|
.m .page {
|
|
height: calc(100% - 50px);
|
|
}
|
|
</style>
|
|
<!-- you have to define 2 functions in the global scope: -->
|
|
<script type="text/javascript">
|
|
var editor;
|
|
var wrapperConfig;
|
|
|
|
function initEditor(onChange) {
|
|
if (!editor) {
|
|
setTimeout(function () {
|
|
if ($('#wrapperConfig').is(':visible')) {
|
|
editor = ace.edit('wrapperConfig');
|
|
editor.getSession().setMode('ace/mode/json');
|
|
editor.$blockScrolling = true;
|
|
editor.setValue(wrapperConfig);
|
|
editor.getSession().on('change', function() {
|
|
onChange();
|
|
});
|
|
} else {
|
|
initEditor(onChange);
|
|
}
|
|
}, 200);
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
if (settings.characteristicPollingInterval === undefined) settings.characteristicPollingInterval = 0;
|
|
$('.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();
|
|
});
|
|
}
|
|
});
|
|
$('.tab-json').on('click', function (e) {
|
|
initEditor(onChange);
|
|
});
|
|
|
|
$('#useGlobalHomebridge').on('change', function () {
|
|
if ($(this).prop('checked')) {
|
|
$('.global').show();
|
|
$('.local').hide();
|
|
$('.tab-json').addClass('disabled');
|
|
} else {
|
|
$('.global').hide();
|
|
$('.local').show();
|
|
$('.tab-json').removeClass('disabled');
|
|
}
|
|
}).trigger('change');
|
|
|
|
wrapperConfig = JSON.stringify(settings.wrapperConfig || '{}', null, 2);
|
|
|
|
list2chips('.libraries', settings.libraries || '', onChange);
|
|
|
|
onChange(false);
|
|
M.updateTextFields(); // function Materialize.updateTextFields(); to reinitialize all the Materialize labels on the page if you are dynamically adding inputs.
|
|
}
|
|
|
|
function list2chips(selector, list, onChange) {
|
|
var chips = list.split(/[,;\s]+/);
|
|
var data = [];
|
|
for (var c = 0; c < chips.length; c++) {
|
|
if (chips[c] && chips[c].trim()) {
|
|
data.push({tag: chips[c].trim()});
|
|
}
|
|
}
|
|
$(selector).chips({
|
|
data: data,
|
|
placeholder: _('Module names'),
|
|
secondaryPlaceholder: _('Add module'),
|
|
onChipAdd: onChange,
|
|
onChipDelete: onChange
|
|
});
|
|
}
|
|
|
|
function chips2list(selector) {
|
|
var data = $(selector).chips('getData');
|
|
var text = [];
|
|
for (var lib = 0; lib < data.length; lib++) {
|
|
text.push(data[lib].tag);
|
|
}
|
|
return text.join(' ');
|
|
}
|
|
|
|
// ... 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();
|
|
}
|
|
});
|
|
obj.libraries = chips2list('.libraries');
|
|
wrapperConfig = editor ? editor.getValue() : wrapperConfig;
|
|
|
|
var _obj;
|
|
try {
|
|
_obj = JSON.parse(wrapperConfig);
|
|
} catch (e) {
|
|
showError(e, _('Parse error'), 'error_outline');
|
|
return false;
|
|
}
|
|
obj.wrapperConfig = _obj;
|
|
|
|
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">
|
|
<div class="col s12">
|
|
<ul class="tabs">
|
|
<li class="tab col s4"><a href="#tab-main" class="translate active">Main settings</a></li>
|
|
<li class="tab col s4 tab-json"><a href="#tab-json" class="translate">Configuration file</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="tab-main" class="col s12 page">
|
|
<div class="row">
|
|
<div class="col s6 m4 l2">
|
|
<img src="ham.png" class="logo">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="input-field col s12 m6 l4 xl3">
|
|
<input id="useGlobalHomebridge" type="checkbox" class="value" />
|
|
<span for="useGlobalHomebridge" class="translate">useGlobalHomebridge</span>
|
|
</div>
|
|
</div>
|
|
<div class="row global">
|
|
<div class="input-field col s12 m6 l4 xl3">
|
|
<input class="value" id="globalHomebridgeBasePath" type="text">
|
|
<label for="globalHomebridgeBasePath">Global Homebridge Path</label>
|
|
<span class="translate">Global Homebridge Path</span>
|
|
</div>
|
|
<div class="input-field col s12 m6 l4 xl3">
|
|
<input class="value" id="globalHomebridgeConfigPath" type="text">
|
|
<label for="globalHomebridgeConfigPath">Global Homebridge Config Directory Path</label>
|
|
<span class="translate">Global Homebridge Config Directory Path</span>
|
|
</div>
|
|
</div>
|
|
<div class="row local">
|
|
<div class="col s12">
|
|
<label class="translate">Additional npm modules:</label>
|
|
<div class="chips libraries"></div>
|
|
</div>
|
|
</div>
|
|
<div class="row local">
|
|
<div class="input-field col s4 ">
|
|
<input class="value" id="characteristicPollingInterval" type="number" min="0" max="1000000"/>s
|
|
<label for="characteristicPollingInterval">Value Polling Interval</label>
|
|
<span class="translate">Value Polling Interval</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="tab-json" class="col s12 page">
|
|
<div id="wrapperConfig">Wrapper-Konfiguration (Non-Global-Homebridge)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|