mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
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:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,8 @@ function getTemperature()
|
||||
$unit = 'C';
|
||||
}
|
||||
} else {
|
||||
$unit = 'C';
|
||||
// no value is set in setupVars.conf
|
||||
$unit = '';
|
||||
}
|
||||
|
||||
return array($celsius, $limit, $unit);
|
||||
|
||||
Reference in New Issue
Block a user