yunkong2.yr/admin/index_m.html

172 lines
6.8 KiB
HTML
Raw Normal View History

2018-09-22 10:26:24 +08:00
<html>
<head>
<meta charset="UTF-8">
<!-- Materialze style -->
<link rel="stylesheet" type="text/css" href="../../css/adapter.css"/>
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.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="../../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>
<script type="text/javascript">
function fillCities(actualValue) {
$('#location').on('change', function () {
var val = $(this).val();
var url = 'http://www.yr.no/_/websvc/jsonforslagsboks.aspx?s=' + encodeURIComponent(val);
socket.emit('httpGet', {
url: url,
headers: {'Cookie': 'brp=spr=eng'}
}, function (err, res) {
if (!err && res.body) {
var obj = JSON.parse(res.body);
if (!obj[1]) {
console.warn('Invalid answer');
} else {
obj = obj[1];
}
var data = {};
for (var i = 0; i < obj.length; i++) {
var tmp = obj[i];
data[tmp[1].substr(7, tmp[1].length - 8)] = null;
}
$('#location').mautocomplete('updateData', data);
} else {
err && console.error(err);
showToast(null, _('Cannot fetch cities!'));
}
});
}).on('keyup', function () {
$(this).trigger('change');
}).mautocomplete({
data: {}
});
}
function load(settings, onChange) {
var $language = $('#language');
$('#location')
.val(settings.location)
.on('change', onChange)
.on('keyup', onChange);
$language
.val(settings.language)
.on('change', onChange).select();
if (settings.sendTranslations === undefined) {
settings.sendTranslations = true;
}
$('#sendTranslations')
.prop('checked', settings.sendTranslations)
.on('change', onChange);
onChange(false);
// Setup default language
if (!settings.language){
$language
.val(systemLang)
.trigger('change').select();
}
fillCities(settings.location);
M.updateTextFields();
if (!settings.location) {
socket.emit('getObject', 'system.config', function (err, config) {
if (config && config.common) {
if (config.common.tempUnit.indexOf('F') !== -1) {
$('#nonMetric').prop('checked', true).trigger('change');
}
}
if (config && config.common && config.common.country && config.common.city) {
var url = 'http://www.yr.no/_/websvc/jsonforslagsboks.aspx?s=' + encodeURIComponent(config.common.city);
socket.emit('httpGet', {
url: url,
headers: {'Cookie': 'brp=spr=eng'}
}, function (err, res) {
if (!err && res.body) {
var obj = JSON.parse(res.body);
if (!obj[1]) {
console.warn('Invalid answer');
} else {
obj = obj[1];
}
var data = {};
for (var i = 0; i < obj.length; i++) {
var tmp = obj[i];
var place = tmp[1].substr(7, tmp[1].length - 8);
if (place.indexOf(config.common.country) !== -1) {
$('#location').val(place).trigger('change');
M.updateTextFields();
break;
}
}
}
});
}
});
}
}
function save(callback) {
callback({
location: $('#location').val(),
language: $('#language').val(),
sendTranslations: $('#sendTranslations').prop('checked')
});
}
</script>
</head>
<body>
<div id="adapter-container">
<div class="m adapter-container">
<div class="row">
<div class="col s12 m4 l2">
<img src="yr.png" class="logo">
</div>
</div>
<div class="row">
<div class="input-field col s12 m4">
<input class="value autocomplete" id="location" type="text"/>
<label for="location" class="translate">Place</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m4">
<select class="value" id="language">
<option value="en">English</option>
<option value="de">Deutsch</option>
<option value="ru">русский</option>
</select>
<label for="language" class="translate">Language</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m4">
<input class="value" type="checkbox" id="nonMetric"/>
<span for="nonMetric" class="translate">Use english metric system</span>
</div>
</div>
<div class="row">
<div class="input-field col s12 m4">
<input class="value" type="checkbox" id="sendTranslations"/>
<span for="sendTranslations" class="translate">Send missing translations to yunkong2.net</span>
</div>
</div>
<div class="row">
<div class="col s12 m4">
<span style="padding-left: 12px; font-size: 16px" class="translate">yrDescription</span>
</div>
</div>
</div>
</body>
</html>