use of org.asqatasun.webapp.ui.form.SelectFormField in project Asqatasun by Asqatasun.
the class ContractSortCommandFactory method getInitialisedContractDisplayCommand.
/**
* @param userId
* @param formFieldList
* @return
* An initialised auditCommand object for the given contract. This object
* handles the last values selected by the user
*/
public ContractSortCommand getInitialisedContractDisplayCommand(Long userId, List<FormField> formFieldList) {
ContractSortCommand contractDisplayCommand = new ContractSortCommand();
for (FormField ff : formFieldList) {
if (ff instanceof SelectFormField) {
for (Map.Entry<String, List<SelectElement>> entry : ((SelectFormField) ff).getSelectElementMap().entrySet()) {
for (SelectElement se : entry.getValue()) {
if (se.getDefaultElement() && se.getEnabled()) {
contractDisplayCommand.getSortOptionMap().put(entry.getKey(), se.getValue());
}
}
}
} else if (ff instanceof TextualFormField) {
contractDisplayCommand.getSortOptionMap().put(ff.getI18nKey(), ff.getValue());
}
}
contractDisplayCommand.setUserId(userId);
return contractDisplayCommand;
}
use of org.asqatasun.webapp.ui.form.SelectFormField in project Asqatasun by Asqatasun.
the class SelectFormFieldBuilderImpl method build.
@Override
public SelectFormField build() {
SelectFormField formField = new SelectFormField();
formField.setErrorI18nKey(getErrorI18nKey());
formField.setI18nKey(getI18nKey());
formField.setValue(getValue());
formField.setRestrictionCode(restrictionCode);
formField.setActivationCode(activationCode);
formField.setSelectElementMap(getSelectElementMap());
return formField;
}
use of org.asqatasun.webapp.ui.form.SelectFormField in project Asqatasun by Asqatasun.
the class AuditSetUpFormFieldHelper method applyRestrictionToAuditSetUpFormField.
/**
* A restriction can be applied to an AuditSetUpFormField when an option
* matches with a parameter (by its code). In this case, regarding the type
* of the FormField, the value of the option override the default
*
* @param ap
* @param optionElementSet
*/
public void applyRestrictionToAuditSetUpFormField(AuditSetUpFormField ap, Collection<OptionElementImpl> optionElementSet) {
if (ap.getFormField() instanceof NumericalFormField) {
OptionElementImpl optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
if (optionElement != null) {
((NumericalFormField) ap.getFormField()).setMaxValue(optionElement.getValue());
ap.getFormField().setValue(optionElement.getValue());
}
} else if (ap.getFormField() instanceof SelectFormField) {
activateSelectFormField((SelectFormField) ap.getFormField(), optionElementSet);
} else if (ap.getFormField() instanceof TextualFormField) {
OptionElementImpl optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
if (optionElement != null) {
(ap.getFormField()).setValue(optionElement.getValue());
}
}
}
use of org.asqatasun.webapp.ui.form.SelectFormField in project Asqatasun by Asqatasun.
the class AbstractAuditSetUpController method getFreshRefAndLevelSetUpFormFieldList.
/**
* Create a fresh list of SelectFormField dedicated to the referential and
* level choice.
* The call of the helper method is due to activation mechanism.
* In this case, the activation of the element is done through the referential
* list associated with the contract
*
* @param authorisedReferentialList
* @param auditSetUpFormFieldBuilderList
* @return
*/
protected List<SelectFormField> getFreshRefAndLevelSetUpFormFieldList(Collection<String> authorisedReferentialList, List<SelectFormFieldBuilderImpl> auditSetUpFormFieldBuilderList) {
List<SelectFormField> selectFormFieldList = new LinkedList();
auditSetUpFormFieldBuilderList.forEach(seb -> {
// Create the SelectElement from the builder
SelectFormField selectFormField = seb.build();
// enable-disable elements from the authorised referentials
auditSetUpFormFieldHelper.activateAllowedReferentialField(selectFormField, authorisedReferentialList);
// add the fresh instance to the returned list
selectFormFieldList.add(selectFormField);
});
return selectFormFieldList;
}
use of org.asqatasun.webapp.ui.form.SelectFormField in project Asqatasun by Asqatasun.
the class AbstractAuditSetUpController method displayAuditSetUpView.
/**
* @param viewName
* @param contractId
* @param scenarioId
* @param optionFormFieldBuilderMap
* @param scope
* @param model
* @return
*/
protected String displayAuditSetUpView(String viewName, String contractId, String scenarioId, Map<String, List<AuditSetUpFormFieldBuilder>> optionFormFieldBuilderMap, ScopeEnum scope, Model model) {
Long contractIdValue;
try {
contractIdValue = Long.valueOf(contractId);
} catch (NumberFormatException nfe) {
throw new ForbiddenPageException(getCurrentUser());
}
Contract contract = contractDataService.read(contractIdValue);
if (isUserAllowedToDisplaySetUpPage(contract, viewName)) {
Collection<String> authorisedReferentialList = getAuthorisedReferentialCodeFromContract(contract);
// Get a fresh list of the auditSetUpFormField that handles the choice
// of the referential and its level
List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
String defaultRef = getDefaultReferential(authorisedReferentialList);
auditSetUpFormFieldHelper.selectDefaultLevelFromRefValue(refAndLevelFormFieldList, defaultRef);
// Get a fresh map of auditSetUpFormField. The value of the field is
// them set by Parameter mapping handled by the AuditSetUpCommandObject
Map<String, List<AuditSetUpFormField>> optionFormFieldMap = this.getFreshAuditSetUpFormFieldMap(contract, optionFormFieldBuilderMap);
AuditSetUpCommand asuc;
// instance of AuditSetUpCommand
switch(scope) {
case DOMAIN:
asuc = auditSetUpCommandFactory.getSiteAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
break;
case FILE:
case GROUPOFFILES:
asuc = auditSetUpCommandFactory.getUploadAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
break;
case SCENARIO:
asuc = auditSetUpCommandFactory.getScenarioAuditSetUpCommand(contract, scenarioId, refAndLevelFormFieldList, optionFormFieldMap);
break;
case PAGE:
case GROUPOFPAGES:
default:
asuc = auditSetUpCommandFactory.getPageAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
}
model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, asuc);
model.addAttribute(TgolKeyStore.DEFAULT_PARAM_SET_KEY, asuc.isDefaultParamSet());
this.prepareFormModel(model, contract, refAndLevelFormFieldList, optionFormFieldMap);
return viewName;
} else {
return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
}
}
Aggregations