Skip to content
Snippets Groups Projects
Commit 7a5cbef1 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Now the script stores calibration values per station

parent c2a98cb1
Branches
No related tags found
No related merge requests found
......@@ -52,7 +52,7 @@
<input type="hidden" name="timeZone" value="Europe/Oslo"/>
<div class="form-group">
<label for="weatherStationId">Målestasjon for årets værdata</label>
<select name="weatherStationId" id="weatherStationId" class="form-control" onblur="validateField(this);">
<select name="weatherStationId" id="weatherStationId" class="form-control" onchange="renderCalibrationForStation();" onblur="validateField(this);">
</select>
<span class="help-block" id="{{ form_id }}_weatherStationId_validation"></span>
</div>
......@@ -174,13 +174,13 @@
{% for i in 4|get_range %}
<tr>
<input type="hidden" name="optimizationInfo" value="" id="optimizationInfo_{{i}}"/>
<td><input type="date" class="form-control" name="observationDate_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationDate_{{i}}':this.value});"></td>
<td><input type="number" class="form-control" name="observationHeight_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationHeight_{{i}}':this.value});"></td>
<td><input type="number" class="form-control" name="observationMSC_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationMSC_{{i}}':this.value});"></td>
<td><input type="number" class="form-control" name="observationFEm_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationFEm_{{i}}':this.value});"></td>
<td><input type="number" class="form-control" name="observationNDF_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationNDF_{{i}}':this.value});"></td>
<td><input type="number" class="form-control" name="observationINDF_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationINDF_{{i}}':this.value});"></td>
<td><input type="number" class="form-control" name="observationRawProtein_{{i}}" size="10" value="" onchange="storeLocalSettings({'observationRawProtein_{{i}}':this.value});"></td>
<td><input type="date" class="form-control" name="observationDate_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
<td><input type="number" class="form-control" name="observationHeight_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
<td><input type="number" class="form-control" name="observationMSC_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
<td><input type="number" class="form-control" name="observationFEm_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
<td><input type="number" class="form-control" name="observationNDF_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
<td><input type="number" class="form-control" name="observationINDF_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
<td><input type="number" class="form-control" name="observationRawProtein_{{i}}" size="10" value="" onchange="storeCalibrationForStation(this.name, this.value);"></td>
</tr>
{% endfor %}
......@@ -381,6 +381,7 @@
<script type="text/javascript" src="{% static "roughage/js/nutrition.js" %}"></script>
<script type="text/javascript" src="{% static "js/weatherStationSelectorMap.js" %}"></script>
<script type="text/javascript">
var calibrationFieldNames = [];
$(document).ready(function() {
initWeatherStations();
......@@ -397,7 +398,7 @@
loadFormDefinition("grassDrying","/static/roughage/formdefinitions/");
// Load stored values for the calibration values
var calibrationFieldNames = [];
var s = "observation";
for(var i=0;i<4;i++)
{
......@@ -413,15 +414,53 @@
calibrationFieldNames = calibrationFieldNames.concat(row);
}
var storedCalibrationValues = getLocalSettings(calibrationFieldNames, false);
var theForm = document.getElementById("{{form_id}}");
for(var key in storedCalibrationValues)
{
theForm[key].value = storedCalibrationValues[key];
}
renderCalibrationForStation();
//console.info(storedCalibrationValues);
});
/**
* Pulls any calibration values from the selected weather station and renders into the form
*/
var renderCalibrationForStation = function()
{
var theForm = document.getElementById("{{form_id}}");
var stationList = theForm.weatherStationId;
var weatherStationId = stationList.options.selectedIndex >= 0 ? stationList.options[stationList.options.selectedIndex].value : "-1";
if(stationList.options.selectedIndex >= 0 && weatherStationId != "-1")
{
var calibrationForStation = getLocalSettings(["calibrationForStation"]) != null ?
JSON.parse(getLocalSettings(["calibrationForStation"])["calibrationForStation"])[weatherStationId]
:{};
for(var i=0; i< calibrationFieldNames.length;i++)
{
var key=calibrationFieldNames[i];
theForm[key].value = calibrationForStation[key] !== undefined ? calibrationForStation[key] : "";
}
}
};
/**
* Add a calibration value for selected weather station to local storage
*/
var storeCalibrationForStation = function(calibrationName, calibrationValue)
{
var theForm = document.getElementById("{{form_id}}");
var weatherStationId = theForm.weatherStationId.selectedIndex >=0 ? theForm.weatherStationId.options[theForm.weatherStationId.selectedIndex].value : "-1";
if(weatherStationId != "-1")
{
var calibrationForStation = getLocalSettings(["calibrationForStation"]) != null ?
JSON.parse(getLocalSettings(["calibrationForStation"])["calibrationForStation"])
: {};
var stationCal = calibrationForStation[weatherStationId] != null ? calibrationForStation[weatherStationId] : {};
stationCal[calibrationName] = calibrationValue;
calibrationForStation[weatherStationId] = stationCal;
storeLocalSettings({"calibrationForStation":JSON.stringify(calibrationForStation)});
}
};
</script>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment