If no unit is set on setupVars, try to use localstorage value, if exists

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign
2023-01-27 18:05:52 -03:00
parent 4966f01dde
commit d92df4af4c
2 changed files with 26 additions and 8 deletions
+24 -7
View File
@@ -181,8 +181,31 @@ function initCPUtemp() {
}
}
function setSetupvarsTempUnit(unit, showmsg = true) {
var token = encodeURIComponent($("#token").text());
$.getJSON("api.php?setTempUnit=" + unit + "&token=" + token, function (data) {
if (showmsg === true) {
if ("result" in data && data.result === "success") {
utils.showAlert("success", "", "Temperature unit set to " + unit, "");
} else {
utils.showAlert("error", "", "", "Temperature unit not set");
}
}
});
}
// Read the temperature unit from HTML code
var tempunit = $("#tempunit").text();
if (!tempunit) {
// if no value was set in setupVars.conf, tries to retrieve the old config from localstorage
tempunit = localStorage ? localStorage.getItem("tempunit") : null;
if (tempunit === null) {
tempunit = "C";
} else {
// if some value was found on localstorage, set the value in setupVars.conf
setSetupvarsTempUnit(tempunit, false);
}
}
setCPUtemp(tempunit);
@@ -195,13 +218,7 @@ function initCPUtemp() {
setCPUtemp(tempunit);
// store the selected value on setupVars.conf
$.getJSON("api.php?setTempUnit=" + tempunit + "&token=" + token, function (data) {
if ("result" in data && data.result == "success") {
utils.showAlert("success", "", "Temperature unit set to " + tempunit, "");
} else {
utils.showAlert("error", "", "", "Temperature unit not set");
}
});
setSetupvarsTempUnit(tempunit);
});
}
}
+2 -1
View File
@@ -110,7 +110,8 @@ function getTemperature()
$unit = 'C';
}
} else {
$unit = 'C';
// no value is set in setupVars.conf
$unit = '';
}
return array($celsius, $limit, $unit);