code.js 23 KB

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