code.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // First, checks if it isn't implemented yet.
  2. if (!String.prototype.format) {
  3. String.prototype.format = function() {
  4. var args = arguments;
  5. return this.replace(/{(\d+)}/g, function(match, number) {
  6. return typeof args[number] != 'undefined'
  7. ? args[number]
  8. : match
  9. ;
  10. });
  11. };
  12. }
  13. var releaseURL = 'https://api.github.com/repos/sle118/squeezelite-esp32/releases';
  14. var recovery = false;
  15. var enableAPTimer = true;
  16. var enableStatusTimer = true;
  17. var commandHeader = 'squeezelite -b 500:2000 -d all=info ';
  18. var pname, ver, otapct, otadsc;
  19. var blockAjax = false;
  20. var blockFlashButton = false;
  21. var apList = null;
  22. var selectedSSID = "";
  23. var refreshAPInterval = null;
  24. var checkStatusInterval = null;
  25. var StatusIntervalActive = false;
  26. var RefreshAPIIntervalActive = false;
  27. var output = '';
  28. function stopCheckStatusInterval(){
  29. if(checkStatusInterval != null){
  30. clearTimeout(checkStatusInterval);
  31. checkStatusInterval = null;
  32. }
  33. StatusIntervalActive = false;
  34. }
  35. function stopRefreshAPInterval(){
  36. if(refreshAPInterval != null){
  37. clearTimeout(refreshAPInterval);
  38. refreshAPInterval = null;
  39. }
  40. RefreshAPIIntervalActive = false;
  41. }
  42. function startCheckStatusInterval(){
  43. StatusIntervalActive = true;
  44. checkStatusInterval = setTimeout(checkStatus, 3000);
  45. }
  46. function startRefreshAPInterval(){
  47. RefreshAPIIntervalActive = true;
  48. refreshAPInterval = setTimeout(refreshAP, 2800);
  49. }
  50. function RepeatCheckStatusInterval(){
  51. if(StatusIntervalActive)
  52. startCheckStatusInterval();
  53. }
  54. function RepeatRefreshAPInterval(){
  55. if(RefreshAPIIntervalActive)
  56. startRefreshAPInterval();
  57. }
  58. $(document).ready(function(){
  59. $("#wifi-status").on("click", ".ape", function() {
  60. $( "#wifi" ).slideUp( "fast", function() {});
  61. $( "#connect-details" ).slideDown( "fast", function() {});
  62. });
  63. $("#manual_add").on("click", ".ape", function() {
  64. selectedSSID = $(this).text();
  65. $( "#ssid-pwd" ).text(selectedSSID);
  66. $( "#wifi" ).slideUp( "fast", function() {});
  67. $( "#connect_manual" ).slideDown( "fast", function() {});
  68. $( "#connect" ).slideUp( "fast", function() {});
  69. //update wait screen
  70. $( "#loading" ).show();
  71. $( "#connect-success" ).hide();
  72. $( "#connect-fail" ).hide();
  73. });
  74. $("#wifi-list").on("click", ".ape", function() {
  75. selectedSSID = $(this).text();
  76. $( "#ssid-pwd" ).text(selectedSSID);
  77. $( "#wifi" ).slideUp( "fast", function() {});
  78. $( "#connect_manual" ).slideUp( "fast", function() {});
  79. $( "#connect" ).slideDown( "fast", function() {});
  80. //update wait screen
  81. $( "#loading" ).show();
  82. $( "#connect-success" ).hide();
  83. $( "#connect-fail" ).hide();
  84. });
  85. $("#cancel").on("click", function() {
  86. selectedSSID = "";
  87. $( "#connect" ).slideUp( "fast", function() {});
  88. $( "#connect_manual" ).slideUp( "fast", function() {});
  89. $( "#wifi" ).slideDown( "fast", function() {});
  90. });
  91. $("#manual_cancel").on("click", function() {
  92. selectedSSID = "";
  93. $( "#connect" ).slideUp( "fast", function() {});
  94. $( "#connect_manual" ).slideUp( "fast", function() {});
  95. $( "#wifi" ).slideDown( "fast", function() {});
  96. });
  97. $("#join").on("click", function() {
  98. performConnect();
  99. });
  100. $("#manual_join").on("click", function() {
  101. performConnect($(this).data('connect'));
  102. });
  103. $("#ok-details").on("click", function() {
  104. $( "#connect-details" ).slideUp( "fast", function() {});
  105. $( "#wifi" ).slideDown( "fast", function() {});
  106. });
  107. $("#ok-credits").on("click", function() {
  108. $( "#credits" ).slideUp( "fast", function() {});
  109. $( "#app" ).slideDown( "fast", function() {});
  110. });
  111. $("#acredits").on("click", function(event) {
  112. event.preventDefault();
  113. $( "#app" ).slideUp( "fast", function() {});
  114. $( "#credits" ).slideDown( "fast", function() {});
  115. });
  116. $("#ok-connect").on("click", function() {
  117. $( "#connect-wait" ).slideUp( "fast", function() {});
  118. $( "#wifi" ).slideDown( "fast", function() {});
  119. });
  120. $("#disconnect").on("click", function() {
  121. $( "#connect-details-wrap" ).addClass('blur');
  122. $( "#diag-disconnect" ).slideDown( "fast", function() {});
  123. });
  124. $("#no-disconnect").on("click", function() {
  125. $( "#diag-disconnect" ).slideUp( "fast", function() {});
  126. $( "#connect-details-wrap" ).removeClass('blur');
  127. });
  128. $("#yes-disconnect").on("click", function() {
  129. stopCheckStatusInterval();
  130. selectedSSID = "";
  131. $( "#diag-disconnect" ).slideUp( "fast", function() {});
  132. $( "#connect-details-wrap" ).removeClass('blur');
  133. $.ajax({
  134. url: '/connect.json',
  135. dataType: 'json',
  136. method: 'DELETE',
  137. cache: false,
  138. data: { 'timestamp': Date.now()}
  139. });
  140. startCheckStatusInterval();
  141. $( "#connect-details" ).slideUp( "fast", function() {});
  142. $( "#wifi" ).slideDown( "fast", function() {})
  143. });
  144. $("input#autoexec-cb").on("click", function() {
  145. autoexec = (this.checked)?1:0;
  146. $.ajax({
  147. url: '/config.json',
  148. dataType: 'json',
  149. method: 'POST',
  150. cache: false,
  151. headers: { "X-Custom-autoexec": autoexec },
  152. data: { 'timestamp': Date.now() },
  153. error: function (xhr, ajaxOptions, thrownError) {
  154. console.log(xhr.status);
  155. console.log(thrownError);
  156. if (thrownError != '') showMessage(thrownError);
  157. }
  158. });
  159. console.log('sent config JSON with headers:', autoexec);
  160. console.log('now triggering reboot');
  161. $.ajax({
  162. url: '/reboot.json',
  163. dataType: 'json',
  164. method: 'POST',
  165. cache: false,
  166. data: { 'timestamp': Date.now()},
  167. error: function (xhr, ajaxOptions, thrownError) {
  168. console.log(xhr.status);
  169. console.log(thrownError);
  170. if (thrownError != '') showMessage(thrownError);
  171. }
  172. });
  173. });
  174. $("input#save-autoexec1").on("click", function() {
  175. autoexec1 = $("#autoexec1").val();
  176. $.ajax({
  177. url: '/config.json',
  178. dataType: 'json',
  179. method: 'POST',
  180. cache: false,
  181. headers: { "X-Custom-autoexec1": autoexec1 },
  182. data: { 'timestamp': Date.now() },
  183. error: function (xhr, ajaxOptions, thrownError) {
  184. console.log(xhr.status);
  185. console.log(thrownError);
  186. if (thrownError != '') showMessage(thrownError);
  187. }
  188. });
  189. console.log('sent config JSON with headers:', autoexec1);
  190. });
  191. $("input#save-gpio").on("click", function() {
  192. var headers = {};
  193. $("input.gpio").each(function() {
  194. var id = $(this)[0].id;
  195. var pin = $(this).val();
  196. if (pin != '') {
  197. headers["X-Custom-"+id] = pin;
  198. }
  199. });
  200. $.ajax({
  201. url: '/config.json',
  202. dataType: 'json',
  203. method: 'POST',
  204. cache: false,
  205. headers: headers,
  206. data: { 'timestamp': Date.now() },
  207. error: function (xhr, ajaxOptions, thrownError) {
  208. console.log(xhr.status);
  209. console.log(thrownError);
  210. if (thrownError != '') showMessage(thrownError);
  211. }
  212. });
  213. console.log('sent config JSON with headers:', JSON.stringify(headers));
  214. });
  215. $("#save-nvs").on("click", function() {
  216. var headers = {};
  217. $("input.nvs").each(function() {
  218. var key = $(this)[0].id;
  219. var val = $(this).val();
  220. if (key != '') {
  221. headers["X-Custom-"+key] = val;
  222. }
  223. });
  224. var key = $("#nvs-new-key").val();
  225. var val = $("#nvs-new-value").val();
  226. if (key != '') {
  227. headers["X-Custom-"+key] = val;
  228. }
  229. $.ajax({
  230. url: '/config.json',
  231. dataType: 'json',
  232. method: 'POST',
  233. cache: false,
  234. headers: headers,
  235. data: { 'timestamp': Date.now() },
  236. error: function (xhr, ajaxOptions, thrownError) {
  237. console.log(xhr.status);
  238. console.log(thrownError);
  239. if (thrownError != '') showMessage(thrownError);
  240. }
  241. });
  242. console.log('sent config JSON with headers:', JSON.stringify(headers));
  243. });
  244. $("#flash").on("click", function() {
  245. if (blockFlashButton) return;
  246. blockFlashButton = true;
  247. var url = $("#fwurl").val();
  248. $.ajax({
  249. url: '/config.json',
  250. dataType: 'json',
  251. method: 'POST',
  252. cache: false,
  253. headers: { "X-Custom-fwurl": url },
  254. data: { 'timestamp': Date.now() },
  255. error: function (xhr, ajaxOptions, thrownError) {
  256. console.log(xhr.status);
  257. console.log(thrownError);
  258. if (thrownError != '') showMessage(thrownError);
  259. }
  260. });
  261. enableStatusTimer = true;
  262. });
  263. $("#generate-command").on("click", function() {
  264. var commandLine = commandHeader + '-n ' + $("#player").val();
  265. if (output == 'bt') {
  266. commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -Z 192000';
  267. } else if (output == 'spdif') {
  268. commandLine += ' -o SPDIF -R -Z 192000';
  269. } else {
  270. commandLine += ' -o I2S';
  271. }
  272. if ($("#optional").val() != '') {
  273. commandLine += ' ' + $("#optional").val();
  274. }
  275. $("#autoexec1").val(commandLine);
  276. });
  277. $('[name=audio]').on("click", function(){
  278. if (this.id == 'bt') {
  279. $("#btsinkdiv").show(200);
  280. output = 'bt';
  281. } else if (this.id == 'spdif') {
  282. $("#btsinkdiv").hide(200);
  283. output = 'spdif';
  284. } else {
  285. $("#btsinkdiv").hide(200);
  286. output = 'i2s';
  287. }
  288. });
  289. $('#fwcheck').on("click", function(){
  290. $("#releaseTable").html("");
  291. $.getJSON(releaseURL, function(data) {
  292. var i=0;
  293. data.forEach(function(release) {
  294. var url = '';
  295. release.assets.forEach(function(asset) {
  296. if (asset.name.match(/\.bin$/)) {
  297. url = asset.browser_download_url;
  298. }
  299. });
  300. var [ver, idf, cfg, branch] = release.name.split('#');
  301. var body = release.body;
  302. body = body.replace(/\'/ig, "\"");
  303. body = body.replace(/[\s\S]+(### Revision Log[\s\S]+)### ESP-IDF Version Used[\s\S]+/, "$1");
  304. body = body.replace(/- \(.+?\) /g, "- ");
  305. var [date, time] = release.created_at.split('T');
  306. var trclass = (i++ > 6)?' hide':'';
  307. $("#releaseTable").append(
  308. "<tr class='release"+trclass+"'>"+
  309. "<td data-toggle='tooltip' title='"+body+"'>"+ver+"</td>"+
  310. "<td>"+idf+"</td>"+
  311. "<td>"+date+"</td>"+
  312. "<td>"+cfg+"</td>"+
  313. "<td>"+branch+"</td>"+
  314. "<td><input id='generate-command' type='button' class='btn btn-success' value='Select' data-url='"+url+"' onclick='setURL(this);' /></td>"+
  315. "</tr>"
  316. );
  317. });
  318. if (i > 7) {
  319. $("#releaseTable").append(
  320. "<tr id='showall'>"+
  321. "<td colspan='6'>"+
  322. "<input type='button' id='showallbutton' class='btn btn-info' value='Show older releases' />"+
  323. "</td>"+
  324. "</tr>"
  325. );
  326. $('#showallbutton').on("click", function(){
  327. $("tr.hide").removeClass("hide");
  328. $("tr#showall").addClass("hide");
  329. });
  330. }
  331. $("#searchfw").css("display", "inline");
  332. })
  333. .fail(function() {
  334. alert("failed to fetch release history!");
  335. });
  336. });
  337. $('input#searchinput').on("input", function(){
  338. var s = $('input#searchinput').val();
  339. var re = new RegExp(s, "gi");
  340. if (s.length == 0) {
  341. $("tr.release").removeClass("hide");
  342. } else if (s.length < 3) {
  343. $("tr.release").addClass("hide");
  344. } else {
  345. $("tr.release").addClass("hide");
  346. $("tr.release").each(function(tr){
  347. $(this).find('td').each (function() {
  348. if ($(this).html().match(re)) {
  349. $(this).parent().removeClass('hide');
  350. }
  351. });
  352. });
  353. }
  354. });
  355. //first time the page loads: attempt to get the connection status and start the wifi scan
  356. refreshAP();
  357. getConfig();
  358. //start timers
  359. startCheckStatusInterval();
  360. startRefreshAPInterval();
  361. $('[data-toggle="tooltip"]').tooltip({
  362. html: true,
  363. placement : 'right',
  364. });
  365. });
  366. function setURL(button) {
  367. var url = button.dataset.url;
  368. $("#fwurl").val(url);
  369. $('[data-url^="http"]').addClass("btn-success").removeClass("btn-danger");
  370. $('[data-url="'+url+'"]').addClass("btn-danger").removeClass("btn-success");
  371. }
  372. function performConnect(conntype){
  373. //stop the status refresh. This prevents a race condition where a status
  374. //request would be refreshed with wrong ip info from a previous connection
  375. //and the request would automatically shows as succesful.
  376. stopCheckStatusInterval();
  377. //stop refreshing wifi list
  378. stopRefreshAPInterval();
  379. var pwd;
  380. if (conntype == 'manual') {
  381. //Grab the manual SSID and PWD
  382. selectedSSID=$('#manual_ssid').val();
  383. pwd = $("#manual_pwd").val();
  384. }else{
  385. pwd = $("#pwd").val();
  386. }
  387. //reset connection
  388. $( "#loading" ).show();
  389. $( "#connect-success" ).hide();
  390. $( "#connect-fail" ).hide();
  391. $( "#ok-connect" ).prop("disabled",true);
  392. $( "#ssid-wait" ).text(selectedSSID);
  393. $( "#connect" ).slideUp( "fast", function() {});
  394. $( "#connect_manual" ).slideUp( "fast", function() {});
  395. $( "#connect-wait" ).slideDown( "fast", function() {});
  396. $.ajax({
  397. url: '/connect.json',
  398. dataType: 'json',
  399. method: 'POST',
  400. cache: false,
  401. headers: { 'X-Custom-ssid': selectedSSID, 'X-Custom-pwd': pwd },
  402. data: { 'timestamp': Date.now()},
  403. error: function (xhr, ajaxOptions, thrownError) {
  404. console.log(xhr.status);
  405. console.log(thrownError);
  406. if (thrownError != '') showMessage(thrownError);
  407. }
  408. });
  409. //now we can re-set the intervals regardless of result
  410. startCheckStatusInterval();
  411. startRefreshAPInterval();
  412. }
  413. function rssiToIcon(rssi){
  414. if(rssi >= -60){
  415. return 'w0';
  416. }
  417. else if(rssi >= -67){
  418. return 'w1';
  419. }
  420. else if(rssi >= -75){
  421. return 'w2';
  422. }
  423. else{
  424. return 'w3';
  425. }
  426. }
  427. function refreshAP(){
  428. if (!enableAPTimer) return;
  429. $.getJSON( "/ap.json", function( data ) {
  430. if(data.length > 0){
  431. //sort by signal strength
  432. data.sort(function (a, b) {
  433. var x = a["rssi"]; var y = b["rssi"];
  434. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  435. });
  436. apList = data;
  437. refreshAPHTML(apList);
  438. }
  439. });
  440. }
  441. function refreshAPHTML(data){
  442. var h = "";
  443. data.forEach(function(e, idx, array) {
  444. h += '<div class="ape{0}"><div class="{1}"><div class="{2}">{3}</div></div></div>'.format(idx === array.length - 1?'':' brdb', rssiToIcon(e.rssi), e.auth==0?'':'pw',e.ssid);
  445. h += "\n";
  446. });
  447. $( "#wifi-list" ).html(h)
  448. }
  449. function checkStatus(){
  450. RepeatCheckStatusInterval();
  451. if (!enableStatusTimer) return;
  452. if (blockAjax) return;
  453. blockAjax = true;
  454. $.getJSON( "/status.json", function( data ) {
  455. if (data.hasOwnProperty('ssid') && data['ssid'] != ""){
  456. if (data["ssid"] === selectedSSID){
  457. //that's a connection attempt
  458. if (data["urc"] === 0){
  459. //got connection
  460. $("#connected-to span").text(data["ssid"]);
  461. $("#connect-details h1").text(data["ssid"]);
  462. $("#ip").text(data["ip"]);
  463. $("#netmask").text(data["netmask"]);
  464. $("#gw").text(data["gw"]);
  465. $("#wifi-status").slideDown( "fast", function() {});
  466. $("span#foot-wifi").html(", SSID: <strong>"+data["ssid"]+"</strong>, IP: <strong>"+data["ip"]+"</strong>");
  467. //unlock the wait screen if needed
  468. $( "#ok-connect" ).prop("disabled",false);
  469. //update wait screen
  470. $( "#loading" ).hide();
  471. $( "#connect-success" ).append("<p>Your IP address now is: " + text(data["ip"]) + "</p>");
  472. $( "#connect-success" ).show();
  473. $( "#connect-fail" ).hide();
  474. enableAPTimer = false;
  475. if (!recovery) enableStatusTimer = false;
  476. }
  477. else if (data["urc"] === 1){
  478. //failed attempt
  479. $("#connected-to span").text('');
  480. $("#connect-details h1").text('');
  481. $("#ip").text('0.0.0.0');
  482. $("#netmask").text('0.0.0.0');
  483. $("#gw").text('0.0.0.0');
  484. $("span#foot-wifi").html("");
  485. //don't show any connection
  486. $("#wifi-status").slideUp( "fast", function() {});
  487. //unlock the wait screen
  488. $( "#ok-connect" ).prop("disabled",false);
  489. //update wait screen
  490. $( "#loading" ).hide();
  491. $( "#connect-fail" ).show();
  492. $( "#connect-success" ).hide();
  493. enableAPTimer = true;
  494. enableStatusTimer = true;
  495. }
  496. }
  497. else if (data.hasOwnProperty('urc') && data['urc'] === 0){
  498. //ESP32 is already connected to a wifi without having the user do anything
  499. if( !($("#wifi-status").is(":visible")) ){
  500. $("#connected-to span").text(data["ssid"]);
  501. $("#connect-details h1").text(data["ssid"]);
  502. $("#ip").text(data["ip"]);
  503. $("#netmask").text(data["netmask"]);
  504. $("#gw").text(data["gw"]);
  505. $("#wifi-status").slideDown( "fast", function() {});
  506. $("span#foot-wifi").html(", SSID: <strong>"+data["ssid"]+"</strong>, IP: <strong>"+data["ip"]+"</strong>");
  507. }
  508. enableAPTimer = false;
  509. if (!recovery) enableStatusTimer = false;
  510. }
  511. }
  512. else if (data.hasOwnProperty('urc') && data['urc'] === 2){
  513. //that's a manual disconnect
  514. if($("#wifi-status").is(":visible")){
  515. $("#wifi-status").slideUp( "fast", function() {});
  516. $("span#foot-wifi").html("");
  517. }
  518. enableAPTimer = true;
  519. enableStatusTimer = true;
  520. }
  521. if (data.hasOwnProperty('recovery')) {
  522. if (data["recovery"] === 1) {
  523. recovery = true;
  524. $("#otadiv").show();
  525. $('a[href^="#tab-audio"]').hide();
  526. $('a[href^="#tab-gpio"]').hide();
  527. $('a[href^="#tab-nvs"]').show();
  528. $("footer.footer").removeClass('sl');
  529. $("footer.footer").addClass('recovery');
  530. $("#boot-button").html('Reboot');
  531. $("#boot-form").attr('action', '/reboot.json');
  532. enableStatusTimer = true;
  533. } else {
  534. recovery = false;
  535. $("#otadiv").hide();
  536. $('a[href^="#tab-audio"]').show();
  537. $('a[href^="#tab-gpio"]').show();
  538. $('a[href^="#tab-nvs"]').hide();
  539. $("footer.footer").removeClass('recovery');
  540. $("footer.footer").addClass('sl');
  541. $("#boot-button").html('Recovery');
  542. $("#boot-form").attr('action', '/recovery.json');
  543. enableStatusTimer = false;
  544. }
  545. }
  546. if (data.hasOwnProperty('project_name') && data['project_name'] != ''){
  547. pname = data['project_name'];
  548. }
  549. if (data.hasOwnProperty('version') && data['version'] != ''){
  550. ver = data['version'];
  551. $("span#foot-fw").html("fw: <strong>"+ver+"</strong>, mode: <strong>"+pname+"</strong>");
  552. }
  553. if (data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){
  554. otapct = data['ota_pct'];
  555. $('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct);
  556. $('.progress-bar').html(otapct+'%');
  557. }
  558. if (data.hasOwnProperty('ota_dsc') && data['ota_dsc'] != ''){
  559. otadsc = data['ota_dsc'];
  560. $("span#flash-status").html(otadsc);
  561. if (otadsc.match(/Error:/) || otapct > 95) {
  562. blockFlashButton = false;
  563. enableStatusTimer = true;
  564. }
  565. } else {
  566. $("span#flash-status").html('');
  567. }
  568. if (data.hasOwnProperty('message') && data['message'] != ''){
  569. showMessage(data['message']);
  570. }
  571. blockAjax = false;
  572. })
  573. .fail(function() {
  574. blockAjax = false;
  575. });
  576. }
  577. function getConfig() {
  578. $.getJSON("/config.json", function(data) {
  579. for (var key in data) {
  580. if (data.hasOwnProperty(key)) {
  581. if (key == 'autoexec') {
  582. if (data["autoexec"] === "1") {
  583. $("#autoexec-cb")[0].checked=true;
  584. } else {
  585. $("#autoexec-cb")[0].checked=false;
  586. }
  587. } else if (key == 'autoexec1') {
  588. $("input#autoexec1").val(data["autoexec1"]);
  589. }
  590. $("tbody#nvsTable").append(
  591. "<tr>"+
  592. "<td>"+key+"</td>"+
  593. "<td class='value'>"+
  594. "<input type='text' class='form-control nvs' id='"+key+"'>"+
  595. "</td>"+
  596. "</tr>"
  597. );
  598. $("input#"+key).val(data[key]);
  599. }
  600. }
  601. $("tbody#nvsTable").append(
  602. "<tr>"+
  603. "<td>"+
  604. "<input type='text' class='form-control' id='nvs-new-key' placeholder='new key'>"+
  605. "</td>"+
  606. "<td>"+
  607. "<input type='text' class='form-control' id='nvs-new-value' placeholder='new value'>"+
  608. "</td>"+
  609. "</tr>"
  610. );
  611. })
  612. .fail(function() {
  613. console.log("failed to fetch config!");
  614. });
  615. }
  616. function showMessage(message) {
  617. $('#message').html(message);
  618. $("#content").fadeTo("slow", 0.3, function() {
  619. $("#message").show(500).delay(5000).hide(500, function() {
  620. $("#content").fadeTo("slow", 1.0);
  621. });
  622. });
  623. }