Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1631 lines
47 KiB

8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
6 years ago
8 years ago
  1. var websock;
  2. var password = false;
  3. var maxNetworks;
  4. var maxSchedules;
  5. var messages = [];
  6. var free_size = 0;
  7. var urls = {};
  8. var numChanged = 0;
  9. var numReboot = 0;
  10. var numReconnect = 0;
  11. var numReload = 0;
  12. var useWhite = false;
  13. var useCCT = false;
  14. var now = 0;
  15. var ago = 0;
  16. <!-- removeIf(!rfm69)-->
  17. var packets;
  18. var filters = [];
  19. <!-- endRemoveIf(!rfm69)-->
  20. // -----------------------------------------------------------------------------
  21. // Messages
  22. // -----------------------------------------------------------------------------
  23. function initMessages() {
  24. messages[1] = "Remote update started";
  25. messages[2] = "OTA update started";
  26. messages[3] = "Error parsing data!";
  27. messages[4] = "The file does not look like a valid configuration backup or is corrupted";
  28. messages[5] = "Changes saved. You should reboot your board now";
  29. messages[7] = "Passwords do not match!";
  30. messages[8] = "Changes saved";
  31. messages[9] = "No changes detected";
  32. messages[10] = "Session expired, please reload page...";
  33. }
  34. <!-- removeIf(!sensor)-->
  35. function sensorName(id) {
  36. var names = [
  37. "DHT", "Dallas", "Emon Analog", "Emon ADC121", "Emon ADS1X15",
  38. "HLW8012", "V9261F", "ECH1560", "Analog", "Digital",
  39. "Events", "PMSX003", "BMX280", "MHZ19", "SI7021",
  40. "SHT3X I2C", "BH1750", "PZEM004T", "AM2320 I2C", "GUVAS12SD",
  41. "TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM",
  42. "NTC", "SonoffSC"
  43. ];
  44. if (1 <= id && id <= names.length) {
  45. return names[id - 1];
  46. }
  47. return null;
  48. }
  49. function magnitudeType(type) {
  50. var types = [
  51. "Temperature", "Humidity", "Pressure",
  52. "Current", "Voltage", "Active Power", "Apparent Power",
  53. "Reactive Power", "Power Factor", "Energy", "Energy (delta)",
  54. "Analog", "Digital", "Event",
  55. "PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UV", "Distance" , "HCHO",
  56. "Local Dose Rate", "Local Dose Rate",
  57. "Count", "Light", "Noise", "Dust", "Movement"
  58. ];
  59. if (1 <= type && type <= types.length) {
  60. return types[type - 1];
  61. }
  62. return null;
  63. }
  64. function magnitudeError(error) {
  65. var errors = [
  66. "OK", "Out of Range", "Warming Up", "Timeout", "Wrong ID",
  67. "Data Error", "I2C Error", "GPIO Error", "Calibration error"
  68. ];
  69. if (0 <= error && error < errors.length) {
  70. return errors[error];
  71. }
  72. return "Error " + error;
  73. }
  74. <!-- endRemoveIf(!sensor)-->
  75. // -----------------------------------------------------------------------------
  76. // Utils
  77. // -----------------------------------------------------------------------------
  78. $.fn.enterKey = function (fnc) {
  79. return this.each(function () {
  80. $(this).keypress(function (ev) {
  81. var keycode = parseInt(ev.keyCode ? ev.keyCode : ev.which, 10);
  82. if (13 === keycode) {
  83. return fnc.call(this, ev);
  84. }
  85. });
  86. });
  87. };
  88. function keepTime() {
  89. $("span[name='ago']").html(ago);
  90. ago++;
  91. if (0 === now) { return; }
  92. var date = new Date(now * 1000);
  93. var text = date.toISOString().substring(0, 19).replace("T", " ");
  94. $("input[name='now']").val(text);
  95. $("span[name='now']").html(text);
  96. now++;
  97. }
  98. function zeroPad(number, positions) {
  99. var zeros = "";
  100. for (var i = 0; i < positions; i++) {
  101. zeros += "0";
  102. }
  103. return (zeros + number).slice(-positions);
  104. }
  105. function loadTimeZones() {
  106. var time_zones = [
  107. -720, -660, -600, -570, -540,
  108. -480, -420, -360, -300, -240,
  109. -210, -180, -120, -60, 0,
  110. 60, 120, 180, 210, 240,
  111. 270, 300, 330, 345, 360,
  112. 390, 420, 480, 510, 525,
  113. 540, 570, 600, 630, 660,
  114. 720, 765, 780, 840
  115. ];
  116. for (var i in time_zones) {
  117. var value = time_zones[i];
  118. var offset = value >= 0 ? value : -value;
  119. var text = "GMT" + (value >= 0 ? "+" : "-") +
  120. zeroPad(parseInt(offset / 60, 10), 2) + ":" +
  121. zeroPad(offset % 60, 2);
  122. $("select[name='ntpOffset']").append(
  123. $("<option></option>").
  124. attr("value",value).
  125. text(text));
  126. }
  127. }
  128. function validateForm(form) {
  129. // http://www.the-art-of-web.com/javascript/validate-password/
  130. // at least one lowercase and one uppercase letter or number
  131. // at least five characters (letters, numbers or special characters)
  132. var re_password = /^(?=.*[A-Z\d])(?=.*[a-z])[\w~!@#$%^&*\(\)<>,.\?;:{}\[\]\\|]{5,}$/;
  133. // password
  134. var adminPass1 = $("input[name='adminPass']", form).first().val();
  135. if (adminPass1.length > 0 && !re_password.test(adminPass1)) {
  136. alert("The password you have entered is not valid, it must have at least 5 characters, 1 lowercase and 1 uppercase or number!");
  137. return false;
  138. }
  139. var adminPass2 = $("input[name='adminPass']", form).last().val();
  140. if (adminPass1 !== adminPass2) {
  141. alert("Passwords are different!");
  142. return false;
  143. }
  144. // RFCs mandate that a hostname's labels may contain only
  145. // the ASCII letters 'a' through 'z' (case-insensitive),
  146. // the digits '0' through '9', and the hyphen.
  147. // Hostname labels cannot begin or end with a hyphen.
  148. // No other symbols, punctuation characters, or blank spaces are permitted.
  149. // Negative lookbehind does not work in Javascript
  150. // var re_hostname = new RegExp('^(?!-)[A-Za-z0-9-]{1,32}(?<!-)$');
  151. var re_hostname = new RegExp('^(?!-)[A-Za-z0-9-]{0,31}[A-Za-z0-9]$');
  152. var hostname = $("input[name='hostname']", form);
  153. var hasChanged = hostname.attr("hasChanged") || 0;
  154. if (0 === hasChanged) {
  155. return true;
  156. }
  157. if (!re_hostname.test(hostname.val())) {
  158. alert("Hostname cannot be empty and may only contain the ASCII letters ('A' through 'Z' and 'a' through 'z'), the digits '0' through '9', and the hyphen ('-')! They can neither start or end with an hyphen.");
  159. return false;
  160. }
  161. return true;
  162. }
  163. function getValue(element) {
  164. if ($(element).attr("type") === "checkbox") {
  165. return $(element).prop("checked") ? 1 : 0;
  166. } else if ($(element).attr("type") === "radio") {
  167. if (!$(element).prop("checked")) {
  168. return null;
  169. }
  170. }
  171. return $(element).val();
  172. }
  173. function addValue(data, name, value) {
  174. // These fields will always be a list of values
  175. var is_group = [
  176. "ssid", "pass", "gw", "mask", "ip", "dns",
  177. "schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC",
  178. "relayBoot", "relayPulse", "relayTime",
  179. "mqttGroup", "mqttGroupInv", "relayOnDisc",
  180. "dczRelayIdx", "dczMagnitude",
  181. "tspkRelay", "tspkMagnitude",
  182. "ledMode",
  183. "adminPass",
  184. "node", "key", "topic"
  185. ];
  186. if (name in data) {
  187. if (!Array.isArray(data[name])) {
  188. data[name] = [data[name]];
  189. }
  190. data[name].push(value);
  191. } else if (is_group.indexOf(name) >= 0) {
  192. data[name] = [value];
  193. } else {
  194. data[name] = value;
  195. }
  196. }
  197. function getData(form) {
  198. var data = {};
  199. // Populate data
  200. $("input,select", form).each(function() {
  201. var name = $(this).attr("name");
  202. var value = getValue(this);
  203. if (null !== value) {
  204. addValue(data, name, value);
  205. }
  206. });
  207. // Post process
  208. addValue(data, "schSwitch", 0xFF);
  209. delete data["filename"];
  210. delete data["rfbcode"];
  211. return data;
  212. }
  213. function randomString(length, chars) {
  214. var mask = "";
  215. if (chars.indexOf("a") > -1) { mask += "abcdefghijklmnopqrstuvwxyz"; }
  216. if (chars.indexOf("A") > -1) { mask += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
  217. if (chars.indexOf("#") > -1) { mask += "0123456789"; }
  218. if (chars.indexOf("@") > -1) { mask += "ABCDEF"; }
  219. if (chars.indexOf("!") > -1) { mask += "~`!@#$%^&*()_+-={}[]:\";'<>?,./|\\"; }
  220. var result = "";
  221. for (var i = length; i > 0; --i) {
  222. result += mask[Math.round(Math.random() * (mask.length - 1))];
  223. }
  224. return result;
  225. }
  226. function generateAPIKey() {
  227. var apikey = randomString(16, "@#");
  228. $("input[name='apiKey']").val(apikey);
  229. return false;
  230. }
  231. function getJson(str) {
  232. try {
  233. return JSON.parse(str);
  234. } catch (e) {
  235. return false;
  236. }
  237. }
  238. // -----------------------------------------------------------------------------
  239. // Actions
  240. // -----------------------------------------------------------------------------
  241. function sendAction(action, data) {
  242. websock.send(JSON.stringify({action: action, data: data}));
  243. }
  244. function sendConfig(data) {
  245. websock.send(JSON.stringify({config: data}));
  246. }
  247. function resetOriginals() {
  248. $("input,select").each(function() {
  249. $(this).attr("original", $(this).val());
  250. });
  251. numReboot = numReconnect = numReload = 0;
  252. }
  253. function doReload(milliseconds) {
  254. setTimeout(function() {
  255. window.location.reload();
  256. }, parseInt(milliseconds, 10));
  257. }
  258. /**
  259. * Check a file object to see if it is a valid firmware image
  260. * The file first byte should be 0xE9
  261. * @param {file} file File object
  262. * @param {Function} callback Function to call back with the result
  263. */
  264. function checkFirmware(file, callback) {
  265. var reader = new FileReader();
  266. reader.onloadend = function(evt) {
  267. if (FileReader.DONE === evt.target.readyState) {
  268. if (0xE9 !== evt.target.result.charCodeAt(0)) callback(false);
  269. if (0x03 !== evt.target.result.charCodeAt(2)) {
  270. var response = window.confirm("Binary image is not using DOUT flash mode. This might cause resets in some devices. Press OK to continue.");
  271. callback(response);
  272. } else {
  273. callback(true);
  274. }
  275. }
  276. };
  277. var blob = file.slice(0, 3);
  278. reader.readAsBinaryString(blob);
  279. }
  280. function doUpgrade() {
  281. var file = $("input[name='upgrade']")[0].files[0];
  282. if (typeof file === "undefined") {
  283. alert("First you have to select a file from your computer.");
  284. return false;
  285. }
  286. if (file.size > free_size) {
  287. alert("Image it too large to fit in the available space for OTA. Consider doing a two-step update.");
  288. return false;
  289. }
  290. checkFirmware(file, function(ok) {
  291. if (!ok) {
  292. alert("The file does not seem to be a valid firmware image.");
  293. return;
  294. }
  295. var data = new FormData();
  296. data.append("upgrade", file, file.name);
  297. $.ajax({
  298. // Your server script to process the upload
  299. url: urls.upgrade.href,
  300. type: "POST",
  301. // Form data
  302. data: data,
  303. // Tell jQuery not to process data or worry about content-type
  304. // You *must* include these options!
  305. cache: false,
  306. contentType: false,
  307. processData: false,
  308. success: function(data, text) {
  309. $("#upgrade-progress").hide();
  310. if ("OK" === data) {
  311. alert("Firmware image uploaded, board rebooting. This page will be refreshed in 5 seconds.");
  312. doReload(5000);
  313. } else {
  314. alert("There was an error trying to upload the new image, please try again (" + data + ").");
  315. }
  316. },
  317. // Custom XMLHttpRequest
  318. xhr: function() {
  319. $("#upgrade-progress").show();
  320. var myXhr = $.ajaxSettings.xhr();
  321. if (myXhr.upload) {
  322. // For handling the progress of the upload
  323. myXhr.upload.addEventListener("progress", function(e) {
  324. if (e.lengthComputable) {
  325. $("progress").attr({ value: e.loaded, max: e.total });
  326. }
  327. } , false);
  328. }
  329. return myXhr;
  330. }
  331. });
  332. });
  333. return false;
  334. }
  335. function doUpdatePassword() {
  336. var form = $("#formPassword");
  337. if (validateForm(form)) {
  338. sendConfig(getData(form));
  339. }
  340. return false;
  341. }
  342. function checkChanges() {
  343. if (numChanged > 0) {
  344. var response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
  345. if (response) {
  346. doUpdate();
  347. }
  348. }
  349. }
  350. function doAction(question, action) {
  351. checkChanges();
  352. if (question) {
  353. var response = window.confirm(question);
  354. if (false === response) {
  355. return false;
  356. }
  357. }
  358. sendAction(action, {});
  359. doReload(5000);
  360. return false;
  361. }
  362. function doReboot(ask) {
  363. var question = (typeof ask === "undefined" || false === ask) ?
  364. null :
  365. "Are you sure you want to reboot the device?";
  366. return doAction(question, "reboot");
  367. }
  368. function doReconnect(ask) {
  369. var question = (typeof ask === "undefined" || false === ask) ?
  370. null :
  371. "Are you sure you want to disconnect from the current WIFI network?";
  372. return doAction(question, "reconnect");
  373. }
  374. function doUpdate() {
  375. var form = $("#formSave");
  376. if (validateForm(form)) {
  377. // Get data
  378. sendConfig(getData(form));
  379. // Empty special fields
  380. $(".pwrExpected").val(0);
  381. $("input[name='pwrResetCalibration']").prop("checked", false);
  382. $("input[name='pwrResetE']").prop("checked", false);
  383. // Change handling
  384. numChanged = 0;
  385. setTimeout(function() {
  386. var response;
  387. if (numReboot > 0) {
  388. response = window.confirm("You have to reboot the board for the changes to take effect, do you want to do it now?");
  389. if (response) { doReboot(false); }
  390. } else if (numReconnect > 0) {
  391. response = window.confirm("You have to reconnect to the WiFi for the changes to take effect, do you want to do it now?");
  392. if (response) { doReconnect(false); }
  393. } else if (numReload > 0) {
  394. response = window.confirm("You have to reload the page to see the latest changes, do you want to do it now?");
  395. if (response) { doReload(0); }
  396. }
  397. resetOriginals();
  398. }, 1000);
  399. }
  400. return false;
  401. }
  402. function doBackup() {
  403. document.getElementById("downloader").src = urls.config.href;
  404. return false;
  405. }
  406. function onFileUpload(event) {
  407. var inputFiles = this.files;
  408. if (typeof inputFiles === "undefined" || inputFiles.length === 0) {
  409. return false;
  410. }
  411. var inputFile = inputFiles[0];
  412. this.value = "";
  413. var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?");
  414. if (!response) {
  415. return false;
  416. }
  417. var reader = new FileReader();
  418. reader.onload = function(e) {
  419. var data = getJson(e.target.result);
  420. if (data) {
  421. sendAction("restore", data);
  422. } else {
  423. window.alert(messages[4]);
  424. }
  425. };
  426. reader.readAsText(inputFile);
  427. return false;
  428. }
  429. function doRestore() {
  430. if (typeof window.FileReader !== "function") {
  431. alert("The file API isn't supported on this browser yet.");
  432. } else {
  433. $("#uploader").click();
  434. }
  435. return false;
  436. }
  437. function doFactoryReset() {
  438. var response = window.confirm("Are you sure you want to restore to factory settings?");
  439. if (response === false) {
  440. return false;
  441. }
  442. sendAction("factory_reset", {});
  443. doReload(5000);
  444. return false;
  445. }
  446. function doToggle(id, value) {
  447. sendAction("relay", {id: id, status: value ? 1 : 0 });
  448. return false;
  449. }
  450. function doScan() {
  451. $("#scanResult").html("");
  452. $("div.scan.loading").show();
  453. sendAction("scan", {});
  454. return false;
  455. }
  456. function doHAConfig() {
  457. $("#haConfig").html("");
  458. sendAction("haconfig", {});
  459. return false;
  460. }
  461. function doDebugCommand() {
  462. var el = $("input[name='dbgcmd']");
  463. var command = el.val();
  464. el.val("");
  465. sendAction("dbgcmd", {command: command});
  466. return false;
  467. }
  468. function doDebugClear() {
  469. $("#weblog").text("");
  470. return false;
  471. }
  472. <!-- removeIf(!rfm69)-->
  473. function doClearCounts() {
  474. sendAction("clear-counts", {});
  475. return false;
  476. }
  477. function doClearMessages() {
  478. packets.clear().draw(false);
  479. return false;
  480. }
  481. function doFilter(e) {
  482. var index = packets.cell(this).index();
  483. if (index == 'undefined') return;
  484. var c = index.column;
  485. var column = packets.column(c);
  486. if (filters[c]) {
  487. filters[c] = false;
  488. column.search("");
  489. $(column.header()).removeClass("filtered");
  490. } else {
  491. filters[c] = true;
  492. var data = packets.row(this).data();
  493. if (e.which == 1) {
  494. column.search('^' + data[c] + '$', true, false );
  495. } else {
  496. column.search('^((?!(' + data[c] + ')).)*$', true, false );
  497. }
  498. $(column.header()).addClass("filtered");
  499. }
  500. column.draw();
  501. return false;
  502. }
  503. function doClearFilters() {
  504. for (var i = 0; i < packets.columns()[0].length; i++) {
  505. if (filters[i]) {
  506. filters[i] = false;
  507. var column = packets.column(i);
  508. column.search("");
  509. $(column.header()).removeClass("filtered");
  510. column.draw();
  511. }
  512. }
  513. return false;
  514. }
  515. <!-- endRemoveIf(!rfm69)-->
  516. // -----------------------------------------------------------------------------
  517. // Visualization
  518. // -----------------------------------------------------------------------------
  519. function toggleMenu() {
  520. $("#layout").toggleClass("active");
  521. $("#menu").toggleClass("active");
  522. $("#menuLink").toggleClass("active");
  523. }
  524. function showPanel() {
  525. $(".panel").hide();
  526. if ($("#layout").hasClass("active")) { toggleMenu(); }
  527. $("#" + $(this).attr("data")).show();
  528. }
  529. // -----------------------------------------------------------------------------
  530. // Relays & magnitudes mapping
  531. // -----------------------------------------------------------------------------
  532. function createRelayList(data, container, template_name) {
  533. var current = $("#" + container + " > div").length;
  534. if (current > 0) { return; }
  535. var template = $("#" + template_name + " .pure-g")[0];
  536. for (var i in data) {
  537. var line = $(template).clone();
  538. $("label", line).html("Switch #" + i);
  539. $("input", line).attr("tabindex", 40 + i).val(data[i]);
  540. line.appendTo("#" + container);
  541. }
  542. }
  543. <!-- removeIf(!sensor)-->
  544. function createMagnitudeList(data, container, template_name) {
  545. var current = $("#" + container + " > div").length;
  546. if (current > 0) { return; }
  547. var template = $("#" + template_name + " .pure-g")[0];
  548. for (var i in data) {
  549. var magnitude = data[i];
  550. var line = $(template).clone();
  551. $("label", line).html(magnitudeType(magnitude.type) + " #" + parseInt(magnitude.index, 10));
  552. $("div.hint", line).html(magnitude.name);
  553. $("input", line).attr("tabindex", 40 + i).val(magnitude.idx);
  554. line.appendTo("#" + container);
  555. }
  556. }
  557. <!-- endRemoveIf(!sensor)-->
  558. // -----------------------------------------------------------------------------
  559. // RFM69
  560. // -----------------------------------------------------------------------------
  561. <!-- removeIf(!rfm69)-->
  562. function addMapping() {
  563. var template = $("#nodeTemplate .pure-g")[0];
  564. var line = $(template).clone();
  565. var tabindex = $("#mapping > div").length * 3 + 50;
  566. $(line).find("input").each(function() {
  567. $(this).attr("tabindex", tabindex++);
  568. });
  569. $(line).find("button").on('click', delMapping);
  570. line.appendTo("#mapping");
  571. }
  572. function delMapping() {
  573. var parent = $(this).parent().parent();
  574. $(parent).remove();
  575. }
  576. <!-- endRemoveIf(!rfm69)-->
  577. // -----------------------------------------------------------------------------
  578. // Wifi
  579. // -----------------------------------------------------------------------------
  580. function delNetwork() {
  581. var parent = $(this).parents(".pure-g");
  582. $(parent).remove();
  583. }
  584. function moreNetwork() {
  585. var parent = $(this).parents(".pure-g");
  586. $(".more", parent).toggle();
  587. }
  588. function addNetwork() {
  589. var numNetworks = $("#networks > div").length;
  590. if (numNetworks >= maxNetworks) {
  591. alert("Max number of networks reached");
  592. return null;
  593. }
  594. var tabindex = 200 + numNetworks * 10;
  595. var template = $("#networkTemplate").children();
  596. var line = $(template).clone();
  597. $(line).find("input").each(function() {
  598. $(this).attr("tabindex", tabindex);
  599. tabindex++;
  600. });
  601. $(line).find(".button-del-network").on("click", delNetwork);
  602. $(line).find(".button-more-network").on("click", moreNetwork);
  603. line.appendTo("#networks");
  604. return line;
  605. }
  606. // -----------------------------------------------------------------------------
  607. // Relays scheduler
  608. // -----------------------------------------------------------------------------
  609. function delSchedule() {
  610. var parent = $(this).parents(".pure-g");
  611. $(parent).remove();
  612. }
  613. function moreSchedule() {
  614. var parent = $(this).parents(".pure-g");
  615. $("div.more", parent).toggle();
  616. }
  617. function addSchedule(event) {
  618. var numSchedules = $("#schedules > div").length;
  619. if (numSchedules >= maxSchedules) {
  620. alert("Max number of schedules reached");
  621. return null;
  622. }
  623. var tabindex = 200 + numSchedules * 10;
  624. var template = $("#scheduleTemplate").children();
  625. var line = $(template).clone();
  626. var type = (1 === event.data.schType) ? "switch" : "light";
  627. template = $("#" + type + "ActionTemplate").children();
  628. var actionLine = template.clone();
  629. $(line).find("#schActionDiv").append(actionLine);
  630. $(line).find("input").each(function() {
  631. $(this).attr("tabindex", tabindex);
  632. tabindex++;
  633. });
  634. $(line).find(".button-del-schedule").on("click", delSchedule);
  635. $(line).find(".button-more-schedule").on("click", moreSchedule);
  636. $(line).find("input[name='schUTC']").prop("id", "schUTC" + (numSchedules + 1))
  637. .next().prop("for", "schUTC" + (numSchedules + 1));
  638. $(line).find("input[name='schEnabled']").prop("id", "schEnabled" + (numSchedules + 1))
  639. .next().prop("for", "schEnabled" + (numSchedules + 1));
  640. line.appendTo("#schedules");
  641. $(line).find("input[type='checkbox']").prop("checked", false);
  642. return line;
  643. }
  644. // -----------------------------------------------------------------------------
  645. // Relays
  646. // -----------------------------------------------------------------------------
  647. function initRelays(data) {
  648. var current = $("#relays > div").length;
  649. if (current > 0) { return; }
  650. var template = $("#relayTemplate .pure-g")[0];
  651. for (var i=0; i<data.length; i++) {
  652. // Add relay fields
  653. var line = $(template).clone();
  654. $(".id", line).html(i);
  655. $(":checkbox", line).prop('checked', data[i]).attr("data", i)
  656. .prop("id", "relay" + i)
  657. .on("change", function (event) {
  658. var id = parseInt($(event.target).attr("data"), 10);
  659. var status = $(event.target).prop("checked");
  660. doToggle(id, status);
  661. });
  662. $("label.toggle", line).prop("for", "relay" + i)
  663. line.appendTo("#relays");
  664. // Populate the relay SELECTs
  665. $("select.isrelay").append(
  666. $("<option></option>").attr("value",i).text("Switch #" + i));
  667. }
  668. }
  669. function createCheckboxes() {
  670. $("input[type='checkbox']").each(function() {
  671. if($(this).prop("name"))$(this).prop("id", $(this).prop("name"));
  672. $(this).parent().addClass("toggleWrapper");
  673. $(this).after('<label for="' + $(this).prop("name") + '" class="toggle"><span class="toggle__handler"></span></label>')
  674. });
  675. }
  676. function initRelayConfig(data) {
  677. var current = $("#relayConfig > div").length;
  678. if (current > 0) { return; }
  679. var template = $("#relayConfigTemplate").children();
  680. for (var i in data) {
  681. var relay = data[i];
  682. var line = $(template).clone();
  683. $("span.gpio", line).html(relay.gpio);
  684. $("span.id", line).html(i);
  685. $("select[name='relayBoot']", line).val(relay.boot);
  686. $("select[name='relayPulse']", line).val(relay.pulse);
  687. $("input[name='relayTime']", line).val(relay.pulse_ms);
  688. $("input[name='mqttGroup']", line).val(relay.group);
  689. $("select[name='mqttGroupInv']", line).val(relay.group_inv);
  690. $("select[name='relayOnDisc']", line).val(relay.on_disc);
  691. line.appendTo("#relayConfig");
  692. }
  693. }
  694. // -----------------------------------------------------------------------------
  695. // Sensors & Magnitudes
  696. // -----------------------------------------------------------------------------
  697. <!-- removeIf(!sensor)-->
  698. function initMagnitudes(data) {
  699. // check if already initialized
  700. var done = $("#magnitudes > div").length;
  701. if (done > 0) { return; }
  702. // add templates
  703. var template = $("#magnitudeTemplate").children();
  704. for (var i in data) {
  705. var magnitude = data[i];
  706. var line = $(template).clone();
  707. $("label", line).html(magnitudeType(magnitude.type) + " #" + parseInt(magnitude.index, 10));
  708. $("div.hint", line).html(magnitude.description);
  709. $("input", line).attr("data", i);
  710. line.appendTo("#magnitudes");
  711. }
  712. }
  713. <!-- endRemoveIf(!sensor)-->
  714. // -----------------------------------------------------------------------------
  715. // Lights
  716. // -----------------------------------------------------------------------------
  717. <!-- removeIf(!light)-->
  718. function initColor(rgb) {
  719. // check if already initialized
  720. var done = $("#colors > div").length;
  721. if (done > 0) { return; }
  722. // add template
  723. var template = $("#colorTemplate").children();
  724. var line = $(template).clone();
  725. line.appendTo("#colors");
  726. // init color wheel
  727. $("input[name='color']").wheelColorPicker({
  728. sliders: (rgb ? "wrgbp" : "whsvp")
  729. }).on("sliderup", function() {
  730. if (rgb) {
  731. var value = $(this).wheelColorPicker("getValue", "css");
  732. sendAction("color", {rgb: value});
  733. } else {
  734. var color = $(this).wheelColorPicker("getColor");
  735. var value = parseInt(color.h * 360, 10) + "," + parseInt(color.s * 100, 10) + "," + parseInt(color.v * 100, 10);
  736. sendAction("color", {hsv: value});
  737. }
  738. });
  739. }
  740. function initCCT() {
  741. // check if already initialized
  742. var done = $("#cct > div").length;
  743. if (done > 0) { return; }
  744. $("#miredsTemplate").children().clone().appendTo("#cct");
  745. $("#mireds").on("change", function() {
  746. var value = $(this).val();
  747. var parent = $(this).parents(".pure-g");
  748. $("span", parent).html(value);
  749. sendAction("mireds", {mireds: value});
  750. });
  751. }
  752. function initChannels(num) {
  753. // check if already initialized
  754. var done = $("#channels > div").length > 0;
  755. if (done) { return; }
  756. // does it have color channels?
  757. var colors = $("#colors > div").length > 0;
  758. // calculate channels to create
  759. var max = num;
  760. if (colors) {
  761. max = num % 3;
  762. if ((max > 0) & useWhite) {
  763. max--;
  764. if (useCCT) {
  765. max--;
  766. }
  767. }
  768. }
  769. var start = num - max;
  770. var onChannelSliderChange = function() {
  771. var id = $(this).attr("data");
  772. var value = $(this).val();
  773. var parent = $(this).parents(".pure-g");
  774. $("span", parent).html(value);
  775. sendAction("channel", {id: id, value: value});
  776. };
  777. // add channel templates
  778. var i = 0;
  779. var template = $("#channelTemplate").children();
  780. for (i=0; i<max; i++) {
  781. var channel_id = start + i;
  782. var line = $(template).clone();
  783. $("span.slider", line).attr("data", channel_id);
  784. $("input.slider", line).attr("data", channel_id).on("change", onChannelSliderChange);
  785. $("label", line).html("Channel #" + channel_id);
  786. line.appendTo("#channels");
  787. }
  788. // Init channel dropdowns
  789. for (i=0; i<num; i++) {
  790. $("select.islight").append(
  791. $("<option></option>").attr("value",i).text("Channel #" + i));
  792. }
  793. // add brightness template
  794. var template = $("#brightnessTemplate").children();
  795. var line = $(template).clone();
  796. line.appendTo("#channels");
  797. // init bright slider
  798. $("#brightness").on("change", function() {
  799. var value = $(this).val();
  800. var parent = $(this).parents(".pure-g");
  801. $("span", parent).html(value);
  802. sendAction("brightness", {value: value});
  803. });
  804. }
  805. <!-- endRemoveIf(!light)-->
  806. // -----------------------------------------------------------------------------
  807. // RFBridge
  808. // -----------------------------------------------------------------------------
  809. <!-- removeIf(!rfbridge)-->
  810. function rfbLearn() {
  811. var parent = $(this).parents(".pure-g");
  812. var input = $("input", parent);
  813. sendAction("rfblearn", {id: input.attr("data-id"), status: input.attr("data-status")});
  814. }
  815. function rfbForget() {
  816. var parent = $(this).parents(".pure-g");
  817. var input = $("input", parent);
  818. sendAction("rfbforget", {id: input.attr("data-id"), status: input.attr("data-status")});
  819. }
  820. function rfbSend() {
  821. var parent = $(this).parents(".pure-g");
  822. var input = $("input", parent);
  823. sendAction("rfbsend", {id: input.attr("data-id"), status: input.attr("data-status"), data: input.val()});
  824. }
  825. function addRfbNode() {
  826. var numNodes = $("#rfbNodes > legend").length;
  827. var template = $("#rfbNodeTemplate").children();
  828. var line = $(template).clone();
  829. var status = true;
  830. $("span", line).html(numNodes);
  831. $(line).find("input").each(function() {
  832. $(this).attr("data-id", numNodes);
  833. $(this).attr("data-status", status ? 1 : 0);
  834. status = !status;
  835. });
  836. $(line).find(".button-rfb-learn").on("click", rfbLearn);
  837. $(line).find(".button-rfb-forget").on("click", rfbForget);
  838. $(line).find(".button-rfb-send").on("click", rfbSend);
  839. line.appendTo("#rfbNodes");
  840. return line;
  841. }
  842. <!-- endRemoveIf(!rfbridge)-->
  843. // -----------------------------------------------------------------------------
  844. // Processing
  845. // -----------------------------------------------------------------------------
  846. function processData(data) {
  847. // title
  848. if ("app_name" in data) {
  849. var title = data.app_name;
  850. if ("app_version" in data) {
  851. title = title + " " + data.app_version;
  852. }
  853. $("span[name=title]").html(title);
  854. if ("hostname" in data) {
  855. title = data.hostname + " - " + title;
  856. }
  857. document.title = title;
  858. }
  859. Object.keys(data).forEach(function(key) {
  860. var i;
  861. var value = data[key];
  862. // ---------------------------------------------------------------------
  863. // Web mode
  864. // ---------------------------------------------------------------------
  865. if ("webMode" === key) {
  866. password = (1 === value);
  867. $("#layout").toggle(!password);
  868. $("#password").toggle(password);
  869. }
  870. // ---------------------------------------------------------------------
  871. // Actions
  872. // ---------------------------------------------------------------------
  873. if ("action" === key) {
  874. if ("reload" === data.action) { doReload(1000); }
  875. return;
  876. }
  877. // ---------------------------------------------------------------------
  878. // RFBridge
  879. // ---------------------------------------------------------------------
  880. <!-- removeIf(!rfbridge)-->
  881. if ("rfbCount" === key) {
  882. for (i=0; i<data.rfbCount; i++) { addRfbNode(); }
  883. return;
  884. }
  885. if ("rfbrawVisible" === key) {
  886. $("input[name='rfbcode']").attr("maxlength", 116);
  887. }
  888. if ("rfb" === key) {
  889. var nodes = data.rfb;
  890. for (i in nodes) {
  891. var node = nodes[i];
  892. $("input[name='rfbcode'][data-id='" + node.id + "'][data-status='" + node.status + "']").val(node.data);
  893. }
  894. return;
  895. }
  896. <!-- endRemoveIf(!rfbridge)-->
  897. // ---------------------------------------------------------------------
  898. // RFM69
  899. // ---------------------------------------------------------------------
  900. <!-- removeIf(!rfm69)-->
  901. if (key == "packet") {
  902. var packet = data.packet;
  903. var d = new Date();
  904. packets.row.add([
  905. d.toLocaleTimeString('en-US', { hour12: false }),
  906. packet.senderID,
  907. packet.packetID,
  908. packet.targetID,
  909. packet.key,
  910. packet.value,
  911. packet.rssi,
  912. packet.duplicates,
  913. packet.missing,
  914. ]).draw(false);
  915. return;
  916. }
  917. if (key == "mapping") {
  918. for (var i in data.mapping) {
  919. // add a new row
  920. addMapping();
  921. // get group
  922. var line = $("#mapping .pure-g")[i];
  923. // fill in the blanks
  924. var mapping = data.mapping[i];
  925. Object.keys(mapping).forEach(function(key) {
  926. var id = "input[name=" + key + "]";
  927. if ($(id, line).length) $(id, line).val(mapping[key]).attr("original", mapping[key]);
  928. });
  929. }
  930. return;
  931. }
  932. <!-- endRemoveIf(!rfm69)-->
  933. // ---------------------------------------------------------------------
  934. // Lights
  935. // ---------------------------------------------------------------------
  936. <!-- removeIf(!light)-->
  937. if ("rgb" === key) {
  938. initColor(true);
  939. $("input[name='color']").wheelColorPicker("setValue", value, true);
  940. return;
  941. }
  942. if ("hsv" === key) {
  943. initColor(false);
  944. // wheelColorPicker expects HSV to be between 0 and 1 all of them
  945. var chunks = value.split(",");
  946. var obj = {};
  947. obj.h = chunks[0] / 360;
  948. obj.s = chunks[1] / 100;
  949. obj.v = chunks[2] / 100;
  950. $("input[name='color']").wheelColorPicker("setColor", obj);
  951. return;
  952. }
  953. if ("brightness" === key) {
  954. $("#brightness").val(value);
  955. $("span.brightness").html(value);
  956. return;
  957. }
  958. if ("channels" === key) {
  959. var len = value.length;
  960. initChannels(len);
  961. for (i in value) {
  962. var ch = value[i];
  963. $("input.slider[data=" + i + "]").val(ch);
  964. $("span.slider[data=" + i + "]").html(ch);
  965. }
  966. return;
  967. }
  968. if ("mireds" === key) {
  969. $("#mireds").val(value);
  970. $("span.mireds").html(value);
  971. return;
  972. }
  973. if ("useWhite" === key) {
  974. useWhite = value;
  975. }
  976. if ("useCCT" === key) {
  977. initCCT();
  978. useCCT = value;
  979. }
  980. <!-- endRemoveIf(!light)-->
  981. // ---------------------------------------------------------------------
  982. // Sensors & Magnitudes
  983. // ---------------------------------------------------------------------
  984. <!-- removeIf(!sensor)-->
  985. if ("magnitudes" === key) {
  986. initMagnitudes(value);
  987. for (i in value) {
  988. var magnitude = value[i];
  989. var error = magnitude.error || 0;
  990. var text = (0 === error) ?
  991. magnitude.value + magnitude.units :
  992. magnitudeError(error);
  993. var element = $("input[name='magnitude'][data='" + i + "']");
  994. element.val(text);
  995. $("div.hint", element.parent().parent()).html(magnitude.description);
  996. }
  997. return;
  998. }
  999. <!-- endRemoveIf(!sensor)-->
  1000. // ---------------------------------------------------------------------
  1001. // WiFi
  1002. // ---------------------------------------------------------------------
  1003. if ("maxNetworks" === key) {
  1004. maxNetworks = parseInt(value, 10);
  1005. return;
  1006. }
  1007. if ("wifi" === key) {
  1008. for (i in value) {
  1009. var wifi = value[i];
  1010. var nwk_line = addNetwork();
  1011. Object.keys(wifi).forEach(function(key) {
  1012. $("input[name='" + key + "']", nwk_line).val(wifi[key]);
  1013. });
  1014. }
  1015. return;
  1016. }
  1017. if ("scanResult" === key) {
  1018. $("div.scan.loading").hide();
  1019. $("#scanResult").show();
  1020. }
  1021. // -----------------------------------------------------------------------------
  1022. // Home Assistant
  1023. // -----------------------------------------------------------------------------
  1024. if ("haConfig" === key) {
  1025. $("#haConfig").show();
  1026. }
  1027. // -----------------------------------------------------------------------------
  1028. // Relays scheduler
  1029. // -----------------------------------------------------------------------------
  1030. if ("maxSchedules" === key) {
  1031. maxSchedules = parseInt(value, 10);
  1032. return;
  1033. }
  1034. if ("schedule" === key) {
  1035. for (i in value) {
  1036. var schedule = value[i];
  1037. var sch_line = addSchedule({ data: {schType: schedule["schType"] }});
  1038. Object.keys(schedule).forEach(function(key) {
  1039. var sch_value = schedule[key];
  1040. $("input[name='" + key + "']", sch_line).val(sch_value);
  1041. $("select[name='" + key + "']", sch_line).prop("value", sch_value);
  1042. $("input[type='checkbox'][name='" + key + "']", sch_line).prop("checked", sch_value);
  1043. });
  1044. }
  1045. return;
  1046. }
  1047. // ---------------------------------------------------------------------
  1048. // Relays
  1049. // ---------------------------------------------------------------------
  1050. if ("relayStatus" === key) {
  1051. initRelays(value);
  1052. for (i in value) {
  1053. $("input[name='relay'][data='" + i + "']").prop("checked", value[i]);
  1054. }
  1055. return;
  1056. }
  1057. // Relay configuration
  1058. if ("relayConfig" === key) {
  1059. initRelayConfig(value);
  1060. return;
  1061. }
  1062. // ---------------------------------------------------------------------
  1063. // Domoticz
  1064. // ---------------------------------------------------------------------
  1065. // Domoticz - Relays
  1066. if ("dczRelays" === key) {
  1067. createRelayList(value, "dczRelays", "dczRelayTemplate");
  1068. return;
  1069. }
  1070. // Domoticz - Magnitudes
  1071. <!-- removeIf(!sensor)-->
  1072. if ("dczMagnitudes" === key) {
  1073. createMagnitudeList(value, "dczMagnitudes", "dczMagnitudeTemplate");
  1074. return;
  1075. }
  1076. <!-- endRemoveIf(!sensor)-->
  1077. // ---------------------------------------------------------------------
  1078. // Thingspeak
  1079. // ---------------------------------------------------------------------
  1080. // Thingspeak - Relays
  1081. if ("tspkRelays" === key) {
  1082. createRelayList(value, "tspkRelays", "tspkRelayTemplate");
  1083. return;
  1084. }
  1085. // Thingspeak - Magnitudes
  1086. <!-- removeIf(!sensor)-->
  1087. if ("tspkMagnitudes" === key) {
  1088. createMagnitudeList(value, "tspkMagnitudes", "tspkMagnitudeTemplate");
  1089. return;
  1090. }
  1091. <!-- endRemoveIf(!sensor)-->
  1092. // ---------------------------------------------------------------------
  1093. // General
  1094. // ---------------------------------------------------------------------
  1095. // Messages
  1096. if ("message" === key) {
  1097. window.alert(messages[value]);
  1098. return;
  1099. }
  1100. // Web log
  1101. if ("weblog" === key) {
  1102. $("#weblog").append(new Text(value));
  1103. $("#weblog").scrollTop($("#weblog")[0].scrollHeight - $("#weblog").height());
  1104. return;
  1105. }
  1106. // Enable options
  1107. var position = key.indexOf("Visible");
  1108. if (position > 0 && position === key.length - 7) {
  1109. var module = key.slice(0,-7);
  1110. $(".module-" + module).css("display", "inherit");
  1111. return;
  1112. }
  1113. if ("deviceip" === key) {
  1114. var a_href = $("span[name='" + key + "']").parent();
  1115. a_href.attr("href", "//" + value);
  1116. a_href.next().attr("href", "telnet://" + value);
  1117. }
  1118. if ("now" === key) {
  1119. now = value;
  1120. return;
  1121. }
  1122. if ("free_size" === key) {
  1123. free_size = parseInt(value, 10);
  1124. }
  1125. // Pre-process
  1126. if ("mqttStatus" === key) {
  1127. value = value ? "CONNECTED" : "NOT CONNECTED";
  1128. }
  1129. if ("ntpStatus" === key) {
  1130. value = value ? "SYNC'D" : "NOT SYNC'D";
  1131. }
  1132. if ("uptime" === key) {
  1133. ago = 0;
  1134. var uptime = parseInt(value, 10);
  1135. var seconds = uptime % 60; uptime = parseInt(uptime / 60, 10);
  1136. var minutes = uptime % 60; uptime = parseInt(uptime / 60, 10);
  1137. var hours = uptime % 24; uptime = parseInt(uptime / 24, 10);
  1138. var days = uptime;
  1139. value = days + "d " + zeroPad(hours, 2) + "h " + zeroPad(minutes, 2) + "m " + zeroPad(seconds, 2) + "s";
  1140. }
  1141. // ---------------------------------------------------------------------
  1142. // Matching
  1143. // ---------------------------------------------------------------------
  1144. var pre;
  1145. var post;
  1146. // Look for INPUTs
  1147. var input = $("input[name='" + key + "']");
  1148. if (input.length > 0) {
  1149. if (input.attr("type") === "checkbox") {
  1150. input.prop("checked", value);
  1151. } else if (input.attr("type") === "radio") {
  1152. input.val([value]);
  1153. } else {
  1154. pre = input.attr("pre") || "";
  1155. post = input.attr("post") || "";
  1156. input.val(pre + value + post);
  1157. }
  1158. }
  1159. // Look for SPANs
  1160. var span = $("span[name='" + key + "']");
  1161. if (span.length > 0) {
  1162. pre = span.attr("pre") || "";
  1163. post = span.attr("post") || "";
  1164. span.html(pre + value + post);
  1165. }
  1166. // Look for SELECTs
  1167. var select = $("select[name='" + key + "']");
  1168. if (select.length > 0) {
  1169. select.val(value);
  1170. }
  1171. });
  1172. // Auto generate an APIKey if none defined yet
  1173. if ($("input[name='apiKey']").val() === "") {
  1174. generateAPIKey();
  1175. }
  1176. resetOriginals();
  1177. }
  1178. function hasChanged() {
  1179. var newValue, originalValue;
  1180. if ($(this).attr("type") === "checkbox") {
  1181. newValue = $(this).prop("checked");
  1182. originalValue = ($(this).attr("original") === "true");
  1183. } else {
  1184. newValue = $(this).val();
  1185. originalValue = $(this).attr("original");
  1186. }
  1187. var hasChanged = $(this).attr("hasChanged") || 0;
  1188. var action = $(this).attr("action");
  1189. if (typeof originalValue === "undefined") { return; }
  1190. if ("none" === action) { return; }
  1191. if (newValue !== originalValue) {
  1192. if (0 === hasChanged) {
  1193. ++numChanged;
  1194. if ("reconnect" === action) { ++numReconnect; }
  1195. if ("reboot" === action) { ++numReboot; }
  1196. if ("reload" === action) { ++numReload; }
  1197. $(this).attr("hasChanged", 1);
  1198. }
  1199. } else {
  1200. if (1 === hasChanged) {
  1201. --numChanged;
  1202. if ("reconnect" === action) { --numReconnect; }
  1203. if ("reboot" === action) { --numReboot; }
  1204. if ("reload" === action) { --numReload; }
  1205. $(this).attr("hasChanged", 0);
  1206. }
  1207. }
  1208. }
  1209. // -----------------------------------------------------------------------------
  1210. // Init & connect
  1211. // -----------------------------------------------------------------------------
  1212. function initUrls(root) {
  1213. var paths = ["ws", "upgrade", "config", "auth"];
  1214. urls["root"] = root;
  1215. paths.forEach(function(path) {
  1216. urls[path] = new URL(path, root);
  1217. urls[path].protocol = root.protocol;
  1218. });
  1219. if (root.protocol == "https:") {
  1220. urls.ws.protocol = "wss:";
  1221. } else {
  1222. urls.ws.protocol = "ws:";
  1223. }
  1224. }
  1225. function connectToURL(url) {
  1226. initUrls(url);
  1227. $.ajax({
  1228. 'method': 'GET',
  1229. 'crossDomain': true,
  1230. 'url': urls.auth.href,
  1231. 'xhrFields': { 'withCredentials': true }
  1232. }).done(function(data) {
  1233. if (websock) { websock.close(); }
  1234. websock = new WebSocket(urls.ws.href);
  1235. websock.onmessage = function(evt) {
  1236. var data = getJson(evt.data.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t"));
  1237. if (data) {
  1238. processData(data);
  1239. }
  1240. };
  1241. }).fail(function() {
  1242. // Nothing to do, reload page and retry
  1243. });
  1244. }
  1245. function connect(host) {
  1246. if (!host.startsWith("http:") && !host.startsWith("https:")) {
  1247. host = "http://" + host;
  1248. }
  1249. connectToURL(new URL(host));
  1250. }
  1251. function connectToCurrentURL() {
  1252. connectToURL(new URL(window.location));
  1253. }
  1254. function getParameterByName(name) {
  1255. var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
  1256. return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
  1257. }
  1258. $(function() {
  1259. initMessages();
  1260. loadTimeZones();
  1261. createCheckboxes();
  1262. setInterval(function() { keepTime(); }, 1000);
  1263. $("#menuLink").on("click", toggleMenu);
  1264. $(".pure-menu-link").on("click", showPanel);
  1265. $("progress").attr({ value: 0, max: 100 });
  1266. $(".button-update").on("click", doUpdate);
  1267. $(".button-update-password").on("click", doUpdatePassword);
  1268. $(".button-reboot").on("click", doReboot);
  1269. $(".button-reconnect").on("click", doReconnect);
  1270. $(".button-wifi-scan").on("click", doScan);
  1271. $(".button-ha-config").on("click", doHAConfig);
  1272. $(".button-dbgcmd").on("click", doDebugCommand);
  1273. $("input[name='dbgcmd']").enterKey(doDebugCommand);
  1274. $(".button-dbg-clear").on("click", doDebugClear);
  1275. $(".button-settings-backup").on("click", doBackup);
  1276. $(".button-settings-restore").on("click", doRestore);
  1277. $(".button-settings-factory").on("click", doFactoryReset);
  1278. $("#uploader").on("change", onFileUpload);
  1279. $(".button-upgrade").on("click", doUpgrade);
  1280. $(".button-apikey").on("click", generateAPIKey);
  1281. $(".button-upgrade-browse").on("click", function() {
  1282. $("input[name='upgrade']")[0].click();
  1283. return false;
  1284. });
  1285. $("input[name='upgrade']").change(function (){
  1286. var file = this.files[0];
  1287. $("input[name='filename']").val(file.name);
  1288. });
  1289. $(".button-add-network").on("click", function() {
  1290. $(".more", addNetwork()).toggle();
  1291. });
  1292. $(".button-add-switch-schedule").on("click", { schType: 1 }, addSchedule);
  1293. <!-- removeIf(!light)-->
  1294. $(".button-add-light-schedule").on("click", { schType: 2 }, addSchedule);
  1295. <!-- endRemoveIf(!light)-->
  1296. <!-- removeIf(!rfm69)-->
  1297. $(".button-add-mapping").on('click', addMapping);
  1298. $(".button-del-mapping").on('click', delMapping);
  1299. $(".button-clear-counts").on('click', doClearCounts);
  1300. $(".button-clear-messages").on('click', doClearMessages);
  1301. $(".button-clear-filters").on('click', doClearFilters);
  1302. $('#packets tbody').on('mousedown', 'td', doFilter);
  1303. packets = $('#packets').DataTable({
  1304. "paging": false
  1305. });
  1306. for (var i = 0; i < packets.columns()[0].length; i++) {
  1307. filters[i] = false;
  1308. }
  1309. <!-- endRemoveIf(!rfm69)-->
  1310. $(document).on("change", "input", hasChanged);
  1311. $(document).on("change", "select", hasChanged);
  1312. // don't autoconnect when opening from filesystem
  1313. if (window.location.protocol === "file:") { return; }
  1314. // Check host param in query string
  1315. if (host = getParameterByName('host')) {
  1316. connect(host);
  1317. } else {
  1318. connectToCurrentURL();
  1319. }
  1320. });