Skip to content
Snippets Groups Projects
Commit dc470ef5 authored by Lene Wasskog's avatar Lene Wasskog
Browse files

feat: Make crop/pest dropdowns for timeseries behave similar to app

parent 43815afd
No related branches found
No related tags found
No related merge requests found
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
function showCorrectMap() { function showCorrectMap() {
let locationList = document.getElementById("locationPointOfInterestId"); let locationList = document.getElementById("locationPointOfInterestId");
if (locationList.options[locationList.options.selectedIndex].value == "-1") { if (locationList.options[locationList.options.selectedIndex].value === "-1") {
document.getElementById("poiFormMap").style.display = "block"; document.getElementById("poiFormMap").style.display = "block";
initLocationMap(null); initLocationMap(null);
} else { } else {
...@@ -122,7 +122,6 @@ ...@@ -122,7 +122,6 @@
* form elements in these cases, and rather display the values statically. * form elements in these cases, and rather display the values statically.
*/ */
function displayObservationTimeSeriesInfo(cropOrganismId, organismId, locationPointOfInterestId) { function displayObservationTimeSeriesInfo(cropOrganismId, organismId, locationPointOfInterestId) {
console.log("Display info!")
document.getElementById("cropDisplayName").innerHTML = nameForCropOrganismId(cropOrganismId); document.getElementById("cropDisplayName").innerHTML = nameForCropOrganismId(cropOrganismId);
document.getElementById("pestDisplayName").innerHTML = nameForOrganismId(organismId); document.getElementById("pestDisplayName").innerHTML = nameForOrganismId(organismId);
fetchPOIs(function (allPois) { fetchPOIs(function (allPois) {
...@@ -162,7 +161,6 @@ ...@@ -162,7 +161,6 @@
function renderCropCategories() { function renderCropCategories() {
let cropCategoryIdList = document.getElementById("cropCategoryIdList"); let cropCategoryIdList = document.getElementById("cropCategoryIdList");
console.info("renderCropCategories", cropCategories)
for (let i in cropCategories) { for (let i in cropCategories) {
let cropCategory = cropCategories[i]; let cropCategory = cropCategories[i];
// Best effort getting name for crop category // Best effort getting name for crop category
...@@ -173,8 +171,7 @@ ...@@ -173,8 +171,7 @@
catName = cLocal.localName; catName = cLocal.localName;
} }
} }
let cOption = new Option(catName, cropCategory.cropCategoryId); cropCategoryIdList.options[cropCategoryIdList.options.length] = new Option(catName, cropCategory.cropCategoryId);
cropCategoryIdList.options[cropCategoryIdList.options.length] = cOption;
} }
} }
...@@ -222,22 +219,18 @@ ...@@ -222,22 +219,18 @@
} }
function renderCropList(matchingCropOrganismOptions, theRest) { function renderCropList(matchingCropOrganismOptions, theRest) {
var cropOrganismIdList = document.getElementById("cropOrganismIdList"); let cropOrganismIdList = document.getElementById("cropOrganismIdList");
if (!cropOrganismIdList) { if (!cropOrganismIdList) {
// HTML element does not exist for observations in time series // HTML element does not exist for observations in time series
return; return;
} }
cropOrganismIdList.options.length = 1; cropOrganismIdList.options.length = 1;
for (var i in matchingCropOrganismOptions) { for (let i in matchingCropOrganismOptions) {
cropOrganismIdList.options[cropOrganismIdList.options.length] = matchingCropOrganismOptions[i]; cropOrganismIdList.options[cropOrganismIdList.options.length] = matchingCropOrganismOptions[i];
} }
cropOrganismIdList.options[cropOrganismIdList.options.length] = new Option("----", -1);
for (var i in theRest) {
cropOrganismIdList.options[cropOrganismIdList.options.length] = theRest[i];
}
} }
var cropList = [ let cropList = [
<#if ! observationTimeSeries.observationTimeSeriesId?has_content || user.isSuperUser() || user.isOrganizationAdmin()> <#if ! observationTimeSeries.observationTimeSeriesId?has_content || user.isSuperUser() || user.isOrganizationAdmin()>
{organismId: -10, displayName: "${i18nBundle.missingInDatabase}", hierarchyCategoryId: -1}, {organismId: -10, displayName: "${i18nBundle.missingInDatabase}", hierarchyCategoryId: -1},
<#list allCrops as cropOrganism> <#list allCrops as cropOrganism>
...@@ -260,7 +253,7 @@ ...@@ -260,7 +253,7 @@
</#if> </#if>
]; ];
var organismList = [ let organismList = [
<#list allPests as organism> <#list allPests as organism>
{ {
organismId: ${organism.organismId}, organismId: ${organism.organismId},
...@@ -268,12 +261,13 @@ ...@@ -268,12 +261,13 @@
}, },
</#list> </#list>
]; ];
let updateCropPests = function () {
let theForm = document.getElementById('observationTimeSeriesForm');
theForm["organismId"].options.selectedIndex = -1;
var updateCropPests = function () { let selectedCropId = theForm["cropOrganismId"].options[theForm["cropOrganismId"].options.selectedIndex].value;
var theForm = document.getElementById('observationTimeSeriesForm');
var selectedCropId = theForm["cropOrganismId"].options[theForm["cropOrganismId"].options.selectedIndex].value;
// If this is not a new observation, or the selected crop is not in the database, we keep calm // If this is not a new observation, or the selected crop is not in the database, we keep calm
if (theForm["observationTimeSeriesId"].value !== "-1" || selectedCropId == "-10") { if (theForm["observationTimeSeriesId"].value !== "-1" || selectedCropId === "-10") {
return; return;
} }
$.getJSON("/rest/organism/croppest/" + selectedCropId, function (json) { $.getJSON("/rest/organism/croppest/" + selectedCropId, function (json) {
...@@ -284,40 +278,29 @@ ...@@ -284,40 +278,29 @@
}); });
}; };
var updateCropPestsCallback = function (cropPest) { let updateCropPestsCallback = function (cropPest) {
var pestList = document.getElementById('observationTimeSeriesForm')["organismId"]; let pestList = document.getElementById('observationTimeSeriesForm')["organismId"];
if (cropPest == null) { if (cropPest == null) {
// Need to reorganize pests back to default // Need to reorganize pests back to default
var allPests = []; let allPests = [];
for (var i = 2; i < pestList.options.length; i++) { for (let i = 2; i < pestList.options.length; i++) {
allPests.push(pestList.options[i]); allPests.push(pestList.options[i]);
} }
allPests.sort(compareSelectListOptions); allPests.sort(compareSelectListOptions);
pestList.options.length = 2; // Keeping the top two pestList.options.length = 2; // Keeping the top two
for (var i = 0; i < allPests.length; i++) { for (let i = 0; i < allPests.length; i++) {
pestList.options[pestList.options.length] = allPests[i]; pestList.options[pestList.options.length] = allPests[i];
} }
} else { } else {
var prioritatedPests = []; let prioritizedPests = [];
var unprioritatedPests = [] for (let i = 2; i < pestList.options.length; i++) {
for (var i = 2; i < pestList.options.length; i++) {
if (cropPest.pestOrganismIds.indexOf(parseInt(pestList.options[i].value)) >= 0) { if (cropPest.pestOrganismIds.indexOf(parseInt(pestList.options[i].value)) >= 0) {
//console.log(pestList.options[i].value + " is prioritated"); prioritizedPests.push(pestList.options[i]);
prioritatedPests.push(pestList.options[i]);
} else if (pestList.options[i].value != "-1") // Avoiding the "---" option
{
//console.log(pestList.options[i].value + " is unprioritated");
unprioritatedPests.push(pestList.options[i]);
} }
} }
pestList.options.length = 2; // Keeping the top two pestList.options.length = 2; // Keeping the top two
for (var i = 0; i < prioritatedPests.length; i++) { for (let i = 0; i < prioritizedPests.length; i++) {
pestList.options[pestList.options.length] = prioritatedPests[i]; pestList.options[pestList.options.length] = prioritizedPests[i];
}
pestList.options[pestList.options.length] = new Option("---", "-1");
for (var i = 0; i < unprioritatedPests.length; i++) {
pestList.options[pestList.options.length] = unprioritatedPests[i];
} }
} }
}; };
...@@ -439,7 +422,7 @@ ...@@ -439,7 +422,7 @@
<label for="yearList">${i18nBundle.year}</label> <label for="yearList">${i18nBundle.year}</label>
<select class="form-control" id="yearList" name="year"> <select class="form-control" id="yearList" name="year">
<#if !observationTimeSeries.observationTimeSeriesId?has_content> <#if !observationTimeSeries.observationTimeSeriesId?has_content>
<option value="-1">${i18nBundle.pleaseSelect} ${i18nBundle.year?lower_case}</option> <option value="" disabled selected>${i18nBundle.pleaseSelect} ${i18nBundle.year?lower_case}</option>
</#if> </#if>
<#list years as year> <#list years as year>
<option value="${year}" <#if observationTimeSeries.observationTimeSeriesId?has_content && observationTimeSeries.year == year>selected</#if>>${year}</option> <option value="${year}" <#if observationTimeSeries.observationTimeSeriesId?has_content && observationTimeSeries.year == year>selected</#if>>${year}</option>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment