make buttons work

This commit is contained in:
Christian Herzog
2019-09-22 12:01:41 +02:00
parent 7e4ed77af0
commit cbbecfdc6d
3 changed files with 215 additions and 277 deletions

View File

@@ -24,6 +24,7 @@ var StatusIntervalActive = false;
var ConfigIntervalActive = false; var ConfigIntervalActive = false;
var RefreshAPIIntervalActive = false; var RefreshAPIIntervalActive = false;
var output = '';
//TODO check //TODO check
var to = 0, set_int = 0; var to = 0, set_int = 0;
@@ -65,7 +66,7 @@ function RepeatCheckConfigInterval(){
function RepeatRefreshAPInterval(){ function RepeatRefreshAPInterval(){
if(RefreshAPIIntervalActive) if(RefreshAPIIntervalActive)
startRefreshAPInterval() startRefreshAPInterval();
} }
$(document).ready(function(){ $(document).ready(function(){
@@ -175,16 +176,81 @@ $(document).ready(function(){
$( "#wifi" ).slideDown( "fast", function() {}) $( "#wifi" ).slideDown( "fast", function() {})
}); });
$("#update-command").click(function() { $("#autoexec-cb").on("click", function() {
updateAutoexec(); autoexec = (this.checked)?1:0;
$.ajax({
url: '/config.json',
dataType: 'json',
method: 'POST',
cache: false,
headers: { "X-Custom-autoexec": autoexec },
data: { 'timestamp': Date.now() }
});
console.log('sent config JSON with headers:', autoexec);
});
$("#save-autoexec1").on("click", function() {
autoexec1 = $("#autoexec1").val();
$.ajax({
url: '/config.json',
dataType: 'json',
method: 'POST',
cache: false,
headers: { "X-Custom-autoexec1": autoexec1 },
data: { 'timestamp': Date.now() }
});
console.log('sent config JSON with headers:', autoexec1);
});
$("#recovery").on("click", function() {
$.ajax({
url: '/recovery.json',
dataType: 'json',
method: 'POST',
cache: false,
data: { 'timestamp': Date.now()}
});
});
$("#reboot").on("click", function() {
$.ajax({
url: '/reboot.json',
dataType: 'json',
method: 'POST',
cache: false,
data: { 'timestamp': Date.now()}
});
});
$("#generate-command").on("click", function() {
var commandLine = commandHeader + '-n ' + $("#player").val();
if (output == 'bt') {
commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -Z 192000';
} else if (output == 'spdif') {
commandLine += ' -o SPDIF -R -Z 192000';
} else {
commandLine += ' -o I2S';
}
if ($("#optional").val() != '') {
commandLine += ' ' + $("#optional").val();
}
$("#autoexec1").val(commandLine);
}); });
$("#generate-command").click(function() { $('[name=audio]').on("click", function(){
generateCommand(); console.log(this);
}); if (this.id == 'bt') {
$("#btsinkdiv").show(200);
$('[name=audio]').click(function(){ output = 'bt';
selectOutput(this); } else if (this.id == 'spdif') {
$("#btsinkdiv").hide(200);
output = 'spdif';
} else {
$("#btsinkdiv").hide(200);
output = 'i2s';
}
}); });
//first time the page loads: attempt to get the connection status and start the wifi scan //first time the page loads: attempt to get the connection status and start the wifi scan
@@ -240,8 +306,6 @@ function performConnect(conntype){
startRefreshAPInterval(); startRefreshAPInterval();
} }
function rssiToIcon(rssi){ function rssiToIcon(rssi){
if(rssi >= -60){ if(rssi >= -60){
return 'w0'; return 'w0';
@@ -367,7 +431,6 @@ function getConfig() {
} else { } else {
console.log('turn off autoexec'); console.log('turn off autoexec');
$("#autoexec-cb")[0].checked=false; $("#autoexec-cb")[0].checked=false;
$("#autoexec-command").hide(200);
} }
} }
if (data.hasOwnProperty('recovery')) { if (data.hasOwnProperty('recovery')) {
@@ -399,77 +462,8 @@ function getConfig() {
}); });
} }
function updateAutoexec(){
autoexec = ($("#autoexec-cb")[0].checked)?1:0;
autoexec1 = $("#autoexec1").val();
$.ajax({
url: '/config.json',
dataType: 'json',
method: 'POST',
cache: false,
headers: { "X-Custom-autoexec": autoexec, "X-Custom-autoexec1": autoexec1 },
data: { 'timestamp': Date.now() }
});
console.log('sent config JSON with headers:', autoexec, autoexec1);
}
var output = '';
function selectOutput(el) {
if ($(el).attr('id') == 'bt') {
$("#btsinkdiv").show(200);
output = 'bt';
} else if ($(el).attr('id') == 'spdif') {
$("#btsinkdiv").hide(200);
output = 'spdif';
} else {
$("#btsinkdiv").hide(200);
output = 'i2s';
}
}
function generateCommand() {
var commandLine = commandHeader + '-n ' + $("#player").val();
if (output == 'bt') {
commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -Z 192000';
} else if (output == 'spdif') {
commandLine += ' -o SPDIF -R -Z 192000';
} else {
commandLine += ' -o I2S';
}
if ($("#optional").val() != '') {
commandLine += ' ' + $("#optional").val();
}
$("#autoexec1").val(commandLine);
}
function handleClick(item) {
console.log(item);
if (item.id == 'autoexec-cb') {
if (item.checked) {
$("#autoexec-command").show(200);
} else {
$("#autoexec-command").hide(200);
}
} else if (item.id == 'recovery') {
$.ajax({
url: '/recovery.json',
dataType: 'json',
method: 'POST',
cache: false,
data: { 'timestamp': Date.now()}
});
} else if (item.id == 'reboot') {
$.ajax({
url: '/reboot.json',
dataType: 'json',
method: 'POST',
cache: false,
data: { 'timestamp': Date.now()}
});
}
}
//TODO daduke check //TODO daduke check
function file_change() { function file_change() {

View File

@@ -4,19 +4,21 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="stylesheet" href="/test/bootstrap.min.css"> <!-- TODO delete -->
<link rel="stylesheet" href="/bootstrap.css"> <link rel="stylesheet" href="/bootstrap.css">
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
<script src="/jquery.js"></script> <script src="/jquery.js"></script>
<script src="/bootstrap.js"></script> <script src="/bootstrap.js"></script>
<script src="/popper.js"></script> <script src="/popper.js"></script>
<script src="/code.js"></script>
<!-- TODO delete --> <!-- TODO delete -->
<link rel="stylesheet" href="/test/bootstrap.min.css">
<script src="/test/jquery.min.js"></script> <script src="/test/jquery.min.js"></script>
<script src="/test/bootstrap.min.js"></script> <script src="/test/bootstrap.min.js"></script>
<script src="/test/popper.min.js"></script> <script src="/test/popper.min.js"></script>
<script src="/code.js"></script>
<title>esp32-wifi-manager</title> <title>esp32-wifi-manager</title>
</head> </head>
@@ -31,6 +33,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-audio">Audio + LMS</a> <a class="nav-link" data-toggle="tab" href="#tab-audio">Audio + LMS</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-gpio">GPIO</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-system">System</a> <a class="nav-link" data-toggle="tab" href="#tab-system">System</a>
</li> </li>
@@ -67,8 +72,8 @@
<input id="manual_pwd" type="password" placeholder="Password" value=""> <input id="manual_pwd" type="password" placeholder="Password" value="">
</section> </section>
<div class="buttons"> <div class="buttons">
<input id="manual_join" type="button" value="Join" data-connect="manual" /> <input id="manual_join" type="button" class="btn btn-success" value="Join" data-connect="manual" />
<input id="manual_cancel" type="button" value="Cancel"/> <input id="manual_cancel" type="button" class="btn btn-danger" value="Cancel"/>
</div> </div>
</div> </div>
@@ -81,8 +86,8 @@
<input id="pwd" type="password" placeholder="Password" value=""> <input id="pwd" type="password" placeholder="Password" value="">
</section> </section>
<div class="buttons"> <div class="buttons">
<input id="join" type="button" value="Join" /> <input id="join" type="button" class="btn btn-success" value="Join" />
<input id="cancel" type="button" value="Cancel"/> <input id="cancel" type="button" class="btn btn-danger" value="Cancel"/>
</div> </div>
</div> </div>
@@ -105,7 +110,7 @@
</div> </div>
</section> </section>
<div class="buttons"> <div class="buttons">
<input id="ok-connect" type="button" value="OK" class="ctr" /> <input id="ok-connect" type="button" value="OK" class="btn btn-success" />
</div> </div>
</div> </div>
@@ -117,7 +122,7 @@
<h2></h2> <h2></h2>
<section> <section>
<div class="buttons"> <div class="buttons">
<input id="disconnect" type="button" value="Disconnect" class="ctr"/> <input id="disconnect" type="button" value="Disconnect" class="btn btn-danger"/>
</div> </div>
</section> </section>
<h2>IP Address</h2> <h2>IP Address</h2>
@@ -127,15 +132,15 @@
<div class="ape">Default Gateway:<div id="gw" class="fr"></div></div> <div class="ape">Default Gateway:<div id="gw" class="fr"></div></div>
</section> </section>
<div class="buttons"> <div class="buttons">
<input id="ok-details" type="button" value="OK" class="ctr" /> <input id="ok-details" type="button" value="OK" class="btn btn-success" />
</div> </div>
</div> </div>
<div id="diag-disconnect" class="diag-box"> <div id="diag-disconnect" class="diag-box">
<div class="diag-box-win"> <div class="diag-box-win">
<p>Are you sure you would like to disconnect from this wifi?</p> <p>Are you sure you would like to disconnect from this wifi?</p>
<div class="buttons"> <div class="buttons">
<input id="no-disconnect" type="button" value="No" /> <input id="no-disconnect" type="button" value="No" class="btn btn-success" />
<input id="yes-disconnect" type="button" value="Yes" /> <input id="yes-disconnect" type="button" value="Yes" class="btn btn-danger" />
</div> </div>
</div> </div>
</div> </div>
@@ -143,58 +148,70 @@
</div> </div>
<div class="tab-pane fade" id="tab-startup"> <div class="tab-pane fade" id="tab-startup">
<h2>Run squeezelite automatically at boot</h2> <h1>Run squeezelite automatically at boot</h1>
<div id="autoexec" class="toggle">
<label> <div class="custom-control custom-switch">
<input id="autoexec-cb" type="checkbox" checked="checked" onclick='handleClick(this);'/><span class="slider"></span> <input type="checkbox" class="custom-control-input" id="autoexec-cb" checked="checked">
</label> <label class="custom-control-label" for="autoexec-cb"></label>
</div> </div>
</div> </div>
<div class="tab-pane fade" id="tab-audio"> <div class="tab-pane fade" id="tab-audio">
<div id="autoexec-command"> <div id="audioout">
<div id="audioout" class="toggle-buttons"> <h1>Audio output</h1>
<h2>Audio output</h2> <div class="form-group">
<input type="radio" id="i2s" name="audio" checked='checked' /> <div class="custom-control custom-radio">
<label for="i2s">I2S</label> <input type="radio" id="i2s" name="audio" class="custom-control-input" checked='checked' />
<input type="radio" id="spdif" name="audio" /> <label for="i2s" class="custom-control-label">I2S</label>
<label for="spdif">SPDIF</label> </div>
<input type="radio" id="bt" name="audio" /> <div class="custom-control custom-radio">
<label for="bt">Bluetooth</label> <input type="radio" id="spdif" name="audio" class="custom-control-input" />
<label for="spdif" class="custom-control-label">SPDIF</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" id="bt" name="audio" class="custom-control-input" />
<label for="bt" class="custom-control-label">Bluetooth</label>
</div>
</div> </div>
<div id="btsinkdiv">
<input id="btsink" type="text" value="BT sink name" />
</div>
<div>
<h2>Player name</h2>
<input id="player" type="text" value="squeezelite" />
</div>
<div>
<h2>Optional setting (e.g. for LMS IP address)</h2>
<input id="optional" type="text" value="" placeholder="-s 192.168.0.1" />
</div>
<div class="buttons">
<input id="generate-command" type="button" value="Generate" />
</div>
<h2>Squeezelite command to run</h2>
<section id="command-list">
<textarea id="autoexec1" maxlength="120">squeezelite -o I2S -b 500:2000 -d all=info -M esp32</textarea>
</section>
</div> </div>
<div id="btsinkdiv">
<input id="btsink" type="text" value="BT sink name" />
</div>
<div>
<h1>Player name</h1>
<input id="player" type="text" value="squeezelite" />
</div>
<div>
<h1>Optional setting (e.g. for LMS IP address)</h1>
<input id="optional" type="text" value="" placeholder="-s 192.168.0.1" />
</div>
<div class="buttons">
<input id="generate-command" type="button" class="btn btn-success" value="Generate" />
</div>
<h1>Squeezelite command to run</h1>
<section id="command-list">
<textarea id="autoexec1" maxlength="120">squeezelite -o I2S -b 500:2000 -d all=info -M esp32</textarea>
</section>
<div class="buttons">
<input id="save-autoexec1" type="button" class="btn btn-success" value="Save" />
</div>
</div>
<div class="tab-pane fade" id="tab-gpio">
</div> </div>
<div class="tab-pane fade" id="tab-system"> <div class="tab-pane fade" id="tab-system">
<div id="recoverydiv"> <div id="recoverydiv">
<h2>Check for firmware upgrade</h2> <h1>Check for firmware upgrade</h1>
<div class="buttons"> <div class="buttons">
<input type="button" id="fwcheck" value="Check" onclick='handleClick(this);' /> <input type="button" id="fwcheck" class="btn btn-primary" value="Check" />
<p><span id="currentfw">Currently running: 0.1</span> - <span id="latestfw">latest available version: 0.2</span></p> <p><span id="currentfw">Currently running: 0.1</span> - <span id="latestfw">latest available version: 0.2</span></p>
</div> </div>
<h2>Reboot to recovery system to perform firmware upgrade</h2> <h1>Reboot to recovery system to perform firmware upgrade</h1>
<div class="buttons"> <div class="buttons">
<input type="button" id="recovery" value="Recovery" onclick='handleClick(this);' /> <input type="button" id="recovery" class="btn btn-primary" value="Recovery" />
</div> </div>
</div> </div>
<div id="otadiv"> <div id="otadiv">
@@ -205,9 +222,9 @@
<span id="file_info"></span> <span id="file_info"></span>
<input type="submit" id="update" disabled="" value="Upload"> <input type="submit" id="update" disabled="" value="Upload">
</form> </form>
<h2>Reboot system with new firmware</h2> <h1>Reboot system with new firmware</h1>
<div class="buttons"> <div class="buttons">
<input type="button" id="reboot" value="Reboot" onclick='handleClick(this);' /> <input type="button" id="reboot" class="btn btn-primary" value="Reboot" />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,8 +1,6 @@
body { body {
background-color: #eee;
border: 0; border: 0;
margin: 0; margin: 0;
font: 1.1em tahoma, arial, sans-serif;
} }
a { a {
color: darkblue; color: darkblue;
@@ -12,49 +10,12 @@ a {
a:hover { a:hover {
color: red; color: red;
} }
input {
font: 1.1em tahoma, arial, sans-serif;
}
input:focus, input:focus,
select:focus, select:focus,
textarea:focus, textarea:focus,
button:focus { button:focus {
outline: none; outline: none;
} }
input[type="button"] {
padding: 5px;
text-align: center;
display: block;
}
p {
padding: 10px;
}
#credits {
display: none;
}
#app {} #app-wrap {} #disconnect {
width: 150px;
}
.diag-box {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
display: none;
}
.diag-box-win {
position: absolute;
left: 10%;
width: 80%;
text-align: center;
border: 2px outset #888;
background-color: #fff;
border-radius: 10px;
top: 20%;
}
.blur { .blur {
-webkit-filter: blur(2px); -webkit-filter: blur(2px);
-moz-filter: blur(2px); -moz-filter: blur(2px);
@@ -65,29 +26,26 @@ p {
.ape { .ape {
margin-left: 20px; margin-left: 20px;
padding: 10px 0px 10px 10px; padding: 10px 0px 10px 10px;
background-color: #444;
} }
.ape:hover { .ape:hover {
cursor: pointer; cursor: pointer;
} }
.brdb {
border-bottom: 1px solid #888;
}
header { header {
background-color: #fff; border-bottom: 1px solid #000;
border-bottom: 1px solid #888; border-top: 1px solid #000;
border-top: 1px solid #888;
} }
section { section {
background-color: #fff; border-bottom: 1px solid #000;
border-bottom: 1px solid #888; border-top: 1px solid #000;
border-top: 1px solid #888;
} }
h1 { h1 {
display: block;
text-align: center;
margin: 0; margin: 0;
padding: 15px; margin-top: 20px;
font-size: 1.4em padding: 10px;
text-transform: uppercase;
color: #888;
font-size: 1.6em
} }
h2 { h2 {
margin: 0; margin: 0;
@@ -154,9 +112,6 @@ h3 {
#no-disconnect { #no-disconnect {
display: inline-block; display: inline-block;
} }
.ctr {
margin: 0 auto;
}
.tctr { .tctr {
text-align: center; text-align: center;
} }
@@ -248,117 +203,91 @@ h3 {
} }
/* end of SpinKit */ /* end of SpinKit */
.toggle label { /* daduke stuff */
position: relative; input[type='text'], input[type='password'], textarea {
display: inline-block; background: #999;
height: 3.5em; border: 0;
padding: 4px;
} }
.toggle input {
display: none;
.custom-switch, .custom-radio {
padding-left: 2.25rem;
margin-left: 12px;
padding-bottom: 1rem;
} }
.toggle .slider { .custom-checkbox > .custom-control-label {
/* Grundfläche */ padding-top: 0.5rem;
padding-left: 2rem;
position: absolute; padding-bottom: 0.1rem;
cursor: pointer;
top: 1.5em;
left: 8px;
width: 4em;
height: 2em;
background-color: #c32e04;
/* red */
transition: all .3s ease-in-out;
border-radius: 1em;
} }
.toggle .slider:before { .custom-switch .custom-control-label::before {
/* verschiebbarer Button */ left: -2.25rem;
height: 2rem;
position: absolute; width: 3.5rem;
content: ""; pointer-events: all;
height: 1.6em; border-radius: 1rem;
width: 1.6em;
left: 0.2em;
bottom: 0.2em;
background-color: white;
border-radius: 50%;
transition: all .3s ease-in-out;
} }
.toggle input:checked + .slider { .custom-switch .custom-control-label::after {
background-color: #5a9900; top: calc(0.25rem + 2px);
/* green */ left: calc(-2.25rem + 2px);
width: calc(2rem - 4px);
height: calc(2rem - 4px);
background-color: #adb5bd;
border-radius: 2rem;
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-transform 0.15s ease-in-out;
transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-transform 0.15s ease-in-out;
}
@media (prefers-reduced-motion: reduce) {
.custom-switch .custom-control-label::after {
transition: none;
}
} }
.toggle input:focus + .slider { .custom-switch .custom-control-input:checked ~ .custom-control-label::after {
background-color: pink; background-color: #fff;
box-shadow: 0 0 1px #5a9900; -webkit-transform: translateX(1.5rem); //translateX(0.75rem);
transform: translateX(1.5rem); //translateX(0.75rem);
} }
.toggle input:checked + .slider:before {
-webkit-transform: translateX(1.9em);
/* Android 4 */
-ms-transform: translateX(1.9em);
/* IE9 */
transform: translateX(1.9em);
textarea#autoexec1 {
width: 80%;
} }
.text .slider:after { input, textarea {
/* Text vor dem FlipFlop-Schalter */ margin-left: 10px;
border-radius: 3px;
position: absolute; border: 1px solid transparent;
content: "AUS"; border-top: none;
color: #c32e04; border-bottom: 1px solid #DDD;
font-weight: bold; box-shadow: inset 0 1px 2px rgba(0,0,0,.39), 0 -1px 1px #FFF, 0 1px 0 #FFF;
height: 1.6em;
left: -2.5em;
bottom: 0.2em;
} }
.text input:checked + .slider:after { .form-group {
/* Text hinter dem FlipFlop-Schalter */ margin-left: 10px;
position: absolute;
content: "AN";
color: #5a9900;
left: 4.5em;
}
input#autoexec1 {
border: none;
margin-left: 35px;
padding: 10px 0px 10px 10px;
}
input#ota {
margin-top: 5px;
margin-bottom: 5px;
} }
#otadiv { #otadiv {
margin-bottom: 15px; display: none;
}
#btsink, #player, #optional {
margin-left: 13px;
} }
#btsinkdiv { #btsinkdiv {
display: none; display: none;
margin-top: 20px;
}
textarea#autoexec1 {
width: 100%;
} }
/*
.toggle-buttons input[type="radio"] { .toggle-buttons input[type="radio"] {
visibility: hidden; visibility: hidden;
width: 3px; width: 3px;
@@ -376,6 +305,4 @@ textarea#autoexec1 {
box-shadow: none; box-shadow: none;
} }
#otadiv { */
display: none;
}