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

Adding max_hierarchy_category_id to the sorting/filtering of crops

parent b33f8b60
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,8 @@ public class CropCategory implements Serializable {
private Integer[] cropOrganismIds;
@Column(name = "organization_id")
private Integer organizationId;
@Column(name = "max_hierarchy_category_id")
private Integer maxHierarchyCategoryId;
public CropCategory() {
}
......@@ -216,4 +218,18 @@ public class CropCategory implements Serializable {
this.setCropOrganismIds(cropSet.toArray(new Integer[cropSet.size()]));
}
}
/**
* @return the maxHierarchyCategoryId
*/
public Integer getMaxHierarchyCategoryId() {
return maxHierarchyCategoryId;
}
/**
* @param maxHierarchyCategoryId the maxHierarchyCategoryId to set
*/
public void setMaxHierarchyCategoryId(Integer maxHierarchyCategoryId) {
this.maxHierarchyCategoryId = maxHierarchyCategoryId;
}
}
......@@ -96,6 +96,9 @@
</#if>
// Activating chosen plugin
$(".chosen-select").chosen();
// Show all available crops
filterCrops(-1);
});
// Adding selected file name to a box
......@@ -342,32 +345,51 @@
cropCategoryIdList.options[cropCategoryIdList.options.length] = cOption;
}
}
function filterCrops(selectedCropCategoryId)
{
// Searching for selected crop category
for(var i in cropCategories)
if(selectedCropCategoryId < 0)
{
var cropCategory = cropCategories[i];
if(cropCategory.cropCategoryId == parseInt(selectedCropCategoryId))
var cropOptions = [];
for(var j=0;j<cropList.length;j++)
{
//var cropOption = cropOrganismIdList.options[j];
var crop = cropList[j];
var cropOption = new Option(crop.displayName, crop.organismId);
cropOptions.push(cropOption);
}
renderCropList(cropOptions, []);
}
else
{
// Searching for selected crop category
for(var i in cropCategories)
{
// Filter based on match
var matchingCropOrganismOptions = [];
var theRest = [];
var cropOrganismIdList = document.getElementById("cropOrganismIdList");
for(var j=0;j<cropOrganismIdList.length;j++)
var cropCategory = cropCategories[i];
if(cropCategory.cropCategoryId == parseInt(selectedCropCategoryId))
{
var cropOption = cropOrganismIdList.options[j];
if(cropCategory.cropOrganismIds.indexOf(parseInt(cropOption.value)) >= 0)
// Filter based on match
var matchingCropOrganismOptions = [];
var theRest = [];
//var cropOrganismIdList = document.getElementById("cropOrganismIdList");
for(var j=0;j<cropList.length;j++)
{
matchingCropOrganismOptions.push(cropOption);
}
else if(parseInt(cropOption.value) > 0)
{
theRest.push(cropOption);
//var cropOption = cropOrganismIdList.options[j];
var crop = cropList[j];
var cropOption = new Option(crop.displayName, crop.organismId);
if(cropCategory.cropOrganismIds.indexOf(crop.organismId) >= 0 && cropCategory.maxHierarchyCategoryId >= crop.hierarchyCategoryId)
{
matchingCropOrganismOptions.push(cropOption);
}
else if(crop.organismId > 0)
{
theRest.push(cropOption);
}
}
renderCropList(matchingCropOrganismOptions, theRest);
}
renderCropList(matchingCropOrganismOptions, theRest);
}
}
}
......@@ -398,6 +420,19 @@
document.getElementById("observationText").value = registrationOfText;
}
</#if>
var cropList = [
<#if ! observation.observationId?has_content || user.isSuperUser() || user.isOrganizationAdmin()>
<#list allCrops as cropOrganism>
{organismId: ${cropOrganism.organismId}, displayName: "${cropOrganism.getLocalName(currentLocale.language)!""} (${cropOrganism.latinName!""}) ${hierarchyCategories.getName(cropOrganism.hierarchyCategoryId)?upper_case}", hierarchyCategoryId: ${cropOrganism.hierarchyCategoryId}}<#sep>,
</#list>
<#else>
<#list allCrops as cropOrganism>
<#if (observation.cropOrganism?has_content && observation.cropOrganism.organismId == cropOrganism.organismId)>
{organismId: ${cropOrganism.organismId}, displayName: "${cropOrganism.getLocalName(currentLocale.language)!""} (${cropOrganism.latinName!""}) ${hierarchyCategories.getName(cropOrganism.hierarchyCategoryId)?upper_case}", hierarchyCategoryId: ${cropOrganism.hierarchyCategoryId}}
</#if>
</#list>
</#if>
];
</script>
</#macro>
<#macro page_contents>
......@@ -435,19 +470,6 @@
<#if ! observation.observationId?has_content || user.isSuperUser() || user.isOrganizationAdmin()>
<option value="-1">${i18nBundle.pleaseSelect} ${i18nBundle.cropOrganismId?lower_case}</option>
<option value="-10"<#if (observation.cropOrganism?has_content && observation.cropOrganism.organismId == -10)>selected="selected"</#if>>${i18nBundle.missingInDatabase}</option>
<#list allCrops as cropOrganism>
<#if cropOrganism.hierarchyCategoryId <= 121>
<option value="${cropOrganism.organismId}"
<#if (observation.cropOrganism?has_content && observation.cropOrganism.organismId == cropOrganism.organismId)>selected="selected"</#if>
>${cropOrganism.getLocalName(currentLocale.language)!""} (${cropOrganism.latinName!""}) ${hierarchyCategories.getName(cropOrganism.hierarchyCategoryId)?upper_case}</option>
</#if>
</#list>
<#else>
<#list allCrops as cropOrganism>
<#if (observation.cropOrganism?has_content && observation.cropOrganism.organismId == cropOrganism.organismId)>
<option value="${cropOrganism.organismId}" selected="selected">${cropOrganism.getLocalName(currentLocale.language)!""} (${cropOrganism.latinName!""}) ${hierarchyCategories.getName(cropOrganism.hierarchyCategoryId)?upper_case}</option>
</#if>
</#list>
</#if>
</select>
<span class="help-block" id="${formId}_cropOrganismId_validation"></span>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment