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

Added support for single select lists in model specific form fields

parent e62101ca
Branches
Tags
No related merge requests found
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package no.nibio.web.forms; package no.nibio.web.forms;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* Represents an option in a select field * Represents an option in a select field
* @copyright 2013 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2013 <a href="http://www.nibio.no/">NIBIO</a>
...@@ -46,6 +48,7 @@ public class FormSelectOption { ...@@ -46,6 +48,7 @@ public class FormSelectOption {
/** /**
* @return the label * @return the label
*/ */
@JsonIgnore
public String getLabel() { public String getLabel() {
return label; return label;
} }
...@@ -53,6 +56,7 @@ public class FormSelectOption { ...@@ -53,6 +56,7 @@ public class FormSelectOption {
/** /**
* @param label the label to set * @param label the label to set
*/ */
@JsonIgnore
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
......
...@@ -120,7 +120,7 @@ function fetchModelSpecificFieldValuesCallback(fieldValues) ...@@ -120,7 +120,7 @@ function fetchModelSpecificFieldValuesCallback(fieldValues)
//console.log(fieldValues[i].forecastModelConfigurationPK.modelConfigParameter + ": " + fieldName); //console.log(fieldValues[i].forecastModelConfigurationPK.modelConfigParameter + ": " + fieldName);
if(theForm[fieldName] !== null && theForm[fieldName] !== undefined) 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) ...@@ -164,6 +164,12 @@ function createFieldHTML(modelId, formId, fieldDefinition)
var inputType = getHTMLInputType(fieldDefinition.dataType); var inputType = getHTMLInputType(fieldDefinition.dataType);
fieldHTML = '<input type="' + inputType + '" class="form-control" name="' + fieldDefinition.name + '" placeholder="' + getI18nMsg(fieldDefinition.name) + '" onblur="validateField(this,\'' + modelId + '\');" />'; 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 [ return [
replaceParams(FIELD_PREFIX,[fieldDefinition.name, getI18nMsg(fieldDefinition.name)]), replaceParams(FIELD_PREFIX,[fieldDefinition.name, getI18nMsg(fieldDefinition.name)]),
...@@ -205,4 +211,4 @@ function getHTMLInputType(dataType) ...@@ -205,4 +211,4 @@ function getHTMLInputType(dataType)
default: default:
return "text"; return "text";
} }
} }
\ No newline at end of file
...@@ -112,7 +112,7 @@ function getLocalizedOrganismName(organism, language) ...@@ -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 * @param cropCategory
* @returns {String} * @returns {String}
*/ */
...@@ -146,6 +146,35 @@ function getLocalizedCropCategoryName(cropCategory) ...@@ -146,6 +146,35 @@ function getLocalizedCropCategoryName(cropCategory)
return "Unnamed"; 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 /** Ensure that we're able to handle both a unix timestamp and an ISO timestamp
* *
* @param {type} ambiguousValue * @param {type} ambiguousValue
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<link href="//code.jquery.com/ui/1.10.3/themes/redmond/jquery-ui.css" rel="stylesheet" /> <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/modernizr_custom.js"></script>
<script type="text/javascript" src="/js/3rdparty/moment.min.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" src="/js/util.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
...@@ -44,8 +45,11 @@ ...@@ -44,8 +45,11 @@
renderModelSpecificFields("${formId}"); renderModelSpecificFields("${formId}");
} }
initCropCategories(); if(document.getElementById("cropCategoryIdList") != null)
{
initCropCategories();
}
sortListAlphabetically(document.getElementById("modelId"),1); sortListAlphabetically(document.getElementById("modelId"),1);
}); });
...@@ -60,7 +64,7 @@ ...@@ -60,7 +64,7 @@
} }
function renderCropCategories() { function renderCropCategories() {
var cropCategoryIdList = document.getElementById("cropCategoryIdList"); var cropCategoryIdList = document.getElementById("cropCategoryIdList");
for(var i in cropCategories) for(var i in cropCategories)
{ {
var cropCategory = cropCategories[i]; var cropCategory = cropCategories[i];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment