'
@@ -203,10 +229,9 @@ function getWiFi(id) {
req.open("GET", "/wifi/scan", true);
req.send()
-
}
-function ClickDay(id, day) {
+function clickDay(id, day) {
value = parameters[id].split('')
day_value = value[day]
day_value = (day_value=='0')?'1':'0'
@@ -217,7 +242,35 @@ function ClickDay(id, day) {
sendUpdate(id);
}
-function ElementHTML(element) {
+function sendTime(id) {
+ var value = document.getElementById('_ui_element_' + id).value
+ if (value) {
+ var date = new Date(value)
+ var timestamp = Math.floor(date.getTime()/1000);
+ sendAction('time',{"timestamp":timestamp})
+ }
+}
+
+function downloadFile(url, name) {
+ const a = document.createElement('a')
+ a.href = url
+ a.download = name?name:url.split('/').pop()
+ document.body.appendChild(a)
+ a.click()
+ document.body.removeChild(a)
+}
+
+function uploadConfig() {
+ var elem = document.getElementById('_config_file')
+ if (elem.value) {
+ var data = elem.files[0]
+ console.log(data)
+ fetch('/config/put', {method:'PUT',body:data});
+ elem.value = null
+ }
+}
+
+function elementHTML(element) {
var value
if (parameters[element.id] || !isNaN(parameters[element.id])) {
value = parameters[element.id]
@@ -230,13 +283,13 @@ function ElementHTML(element) {
case 'hr':
return '
'
case 'button':
- return '
'
+ return '
'
case 'password':
return '
'
- + ''
- + '
👁
'
+ + '
'
+ + '
'
case 'input':
var pattern = ""
if (element.pattern) {
@@ -251,15 +304,15 @@ function ElementHTML(element) {
pattern = ' pattern="' + encode(element.pattern) + '"'
}
return '
'
- + ''
- + '
📶
'
+ + '
'
+ + '
'
+ '
'
+ '
'
+ ''
- + '
'
- + '
'
+ + '
'
+ + '
'
case 'checkbox':
return ''
return days
+ case 'timeset':
+ var now = new Date()
+ now.setMinutes(now.getMinutes() - now.getTimezoneOffset())
+ value = now.toISOString().slice(0, -1);
+ return '
'
+ +''
+ + '
->
'
case 'text':
return '
' + encode(value) + '
'
case 'number':
@@ -299,15 +359,22 @@ function ElementHTML(element) {
+ ''
+ case 'config':
+ return '
'
+ + '
'
+ + ''
+ + ''
+ + ''
+ + '
'
case 'table':
default:
- return '
'
- + encode(element.label)+ '
' + encode(value) + '
'
+ return '
'
+ + encode(element.label)+ '
' + encode(value) + '
'
}
}
-function DrawPage(id) {
+function drawPage(id) {
var idx =0, i=0
for (const page of pages) {
var menu_link = document.getElementById('_ui_pglink_' + page.id)
@@ -324,40 +391,44 @@ function DrawPage(id) {
var page_content = document.getElementById("_ui_page_content");
var content = ''
for (const element of pages[idx].elements) {
- content = content + ElementHTML(element) + '\n'
+ content = content + elementHTML(element) + '\n'
}
page_content.innerHTML = content
window.location.hash = id
}
-function DrawNavigator(project, pages) {
+function drawNavigator(project, pages) {
var menu = document.getElementById('_ui_menu_list');
var list = ''
for (const page of pages) {
list = list + '