diff --git a/src/main/java/no/nibio/web/forms/FormSelectOption.java b/src/main/java/no/nibio/web/forms/FormSelectOption.java
index 9f510e37a1c867c7ed60d728575e6b2e6468a4ec..fc356a6ee80efc54c6f267c1324c54cc36f9713d 100755
--- a/src/main/java/no/nibio/web/forms/FormSelectOption.java
+++ b/src/main/java/no/nibio/web/forms/FormSelectOption.java
@@ -19,6 +19,8 @@
package no.nibio.web.forms;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
/**
* Represents an option in a select field
* @copyright 2013 <a href="http://www.nibio.no/">NIBIO</a>
@@ -46,6 +48,7 @@ public class FormSelectOption {
/**
* @return the label
*/
+ @JsonIgnore
public String getLabel() {
return label;
}
@@ -53,6 +56,7 @@ public class FormSelectOption {
/**
* @param label the label to set
*/
+ @JsonIgnore
public void setLabel(String label) {
this.label = label;
}
diff --git a/src/main/webapp/js/forecastConfigurationForm.js b/src/main/webapp/js/forecastConfigurationForm.js
index 6dfca064b7eaeead2c79f3edc75c5dbc6b106417..3d3b9bfbe17adc41b85f64a29861f2c75cfda5e0 100755
--- a/src/main/webapp/js/forecastConfigurationForm.js
+++ b/src/main/webapp/js/forecastConfigurationForm.js
@@ -120,7 +120,7 @@ function fetchModelSpecificFieldValuesCallback(fieldValues)
//console.log(fieldValues[i].forecastModelConfigurationPK.modelConfigParameter + ": " + fieldName);
if(theForm[fieldName] !== null && theForm[fieldName] !== undefined)
{
- theForm[fieldName].value=fieldValues[i].parameterValue;
+ theForm[fieldName].value=fieldValues[i].parameterValue;
}
}
}
@@ -164,6 +164,12 @@ function createFieldHTML(modelId, formId, fieldDefinition)
var inputType = getHTMLInputType(fieldDefinition.dataType);
fieldHTML = '<input type="' + inputType + '" class="form-control" name="' + fieldDefinition.name + '" placeholder="' + getI18nMsg(fieldDefinition.name) + '" onblur="validateField(this,\'' + modelId + '\');" />';
}
+ else if(fieldDefinition.fieldType === fieldTypes.TYPE_SELECT_SINGLE || fieldDefinition.fieldType === fieldTypes.TYPE_SELECT_MULTIPLE)
+ {
+ fieldHTML = '<select class="form-control" name="' + fieldDefinition.name + '"onblur="validateField(this,\'' + modelId + '\')" ' + (fieldDefinition.fieldType === fieldTypes.TYPE_SELECT_MULTIPLE ? ' multiple="multiple"' : '') + '>';
+ fieldHTML += getLocalizedOptionsHTML(fieldDefinition.options);
+ fieldHTML += '</select>';
+ }
return [
replaceParams(FIELD_PREFIX,[fieldDefinition.name, getI18nMsg(fieldDefinition.name)]),
@@ -205,4 +211,4 @@ function getHTMLInputType(dataType)
default:
return "text";
}
-}
\ No newline at end of file
+}
diff --git a/src/main/webapp/js/util.js b/src/main/webapp/js/util.js
index 382314a03733ac00c4f2db4f687366bccd530939..74c3f49d49d602f7e47fd1adcf4a010fb2d2bf0d 100755
--- a/src/main/webapp/js/util.js
+++ b/src/main/webapp/js/util.js
@@ -112,7 +112,7 @@ function getLocalizedOrganismName(organism, language)
}
/**
- * Depends on the value of currentLanguage and defaultLanguage in /currentLanguage.js
+ * Depends on the value of currentLanguage and defaultLanguage in /js/environment.js
* @param cropCategory
* @returns {String}
*/
@@ -146,6 +146,35 @@ function getLocalizedCropCategoryName(cropCategory)
return "Unnamed";
}
+function getLocalizedOptionsHTML(optionsList) {
+ var translatedOptionsHTML = "";
+ var languages = [environment.currentLanguage, environment.defaultLanguage, "en"];
+
+ for(var i in optionsList){
+ var option = optionsList[i];
+ var label = null;
+ var labelList = option.label;
+ for(var j in languages)
+ {
+ for(var k in labelList)
+ {
+ if(k === languages[j])
+ {
+ label = labelList[k];
+ break;
+ }
+ }
+ if(label !== null)
+ {
+ break;
+ }
+ }
+ translatedOptionsHTML += '<option value="' + option.value + '"' + (option.selected === "true" ? ' selected="selected"' : '') + ">" + label + "</option>";
+ }
+
+ return translatedOptionsHTML;
+}
+
/** Ensure that we're able to handle both a unix timestamp and an ISO timestamp
*
* @param {type} ambiguousValue
diff --git a/src/main/webapp/templates/forecastConfigurationForm.ftl b/src/main/webapp/templates/forecastConfigurationForm.ftl
index 637f74c785b5590f0edd79c023f5e52c15a621cb..803f5600cc96fd4fede4fbd35d3b2b0d9494d572 100755
--- a/src/main/webapp/templates/forecastConfigurationForm.ftl
+++ b/src/main/webapp/templates/forecastConfigurationForm.ftl
@@ -26,6 +26,7 @@
<link href="//code.jquery.com/ui/1.10.3/themes/redmond/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript" src="/js/3rdparty/modernizr_custom.js"></script>
<script type="text/javascript" src="/js/3rdparty/moment.min.js"></script>
+ <script type="text/javascript" src="/js/environment.js"></script>
<script type="text/javascript" src="/js/util.js"></script>
<script type="text/javascript">
$(document).ready(function() {
@@ -44,8 +45,11 @@
renderModelSpecificFields("${formId}");
}
-
- initCropCategories();
+
+ if(document.getElementById("cropCategoryIdList") != null)
+ {
+ initCropCategories();
+ }
sortListAlphabetically(document.getElementById("modelId"),1);
});
@@ -60,7 +64,7 @@
}
function renderCropCategories() {
- var cropCategoryIdList = document.getElementById("cropCategoryIdList");
+ var cropCategoryIdList = document.getElementById("cropCategoryIdList");
for(var i in cropCategories)
{
var cropCategory = cropCategories[i];