Search in sources :

Example 1 with SelectFormField

use of org.asqatasun.webapp.form.SelectFormField in project Asqatasun by Asqatasun.

the class SelectFormFieldBuilderImpl method build.

@Override
public SelectFormField build() {
    SelectFormField formField = new SelectFormFieldImpl();
    formField.setErrorI18nKey(getErrorI18nKey());
    formField.setI18nKey(getI18nKey());
    formField.setValue(getValue());
    formField.setRestrictionCode(restrictionCode);
    formField.setActivationCode(activationCode);
    formField.setSelectElementMap(getSelectElementMap());
    return formField;
}
Also used : SelectFormFieldImpl(org.asqatasun.webapp.form.SelectFormFieldImpl) SelectFormField(org.asqatasun.webapp.form.SelectFormField)

Example 2 with SelectFormField

use of org.asqatasun.webapp.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 static void applyRestrictionToAuditSetUpFormField(AuditSetUpFormField ap, Collection<OptionElement> optionElementSet) {
    if (ap.getFormField() instanceof NumericalFormField) {
        OptionElement optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
        if (optionElement != null) {
            ((NumericalFormField) ap.getFormField()).setMaxValue(optionElement.getValue());
            ((NumericalFormField) ap.getFormField()).setValue(optionElement.getValue());
        }
    } else if (ap.getFormField() instanceof SelectFormField) {
        activateSelectFormField((SelectFormField) ap.getFormField(), optionElementSet);
    } else if (ap.getFormField() instanceof TextualFormField) {
        OptionElement optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
        if (optionElement != null) {
            ((TextualFormField) ap.getFormField()).setValue(optionElement.getValue());
        }
    }
}
Also used : TextualFormField(org.asqatasun.webapp.form.TextualFormField) OptionElement(org.asqatasun.webapp.entity.option.OptionElement) NumericalFormField(org.asqatasun.webapp.form.NumericalFormField) SelectFormField(org.asqatasun.webapp.form.SelectFormField)

Example 3 with SelectFormField

use of org.asqatasun.webapp.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<AuditSetUpFormFieldBuilderImpl>> optionFormFieldBuilderMap, ScopeEnum scope, Model model) {
    Long contractIdValue;
    try {
        contractIdValue = Long.valueOf(contractId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException(getCurrentUser());
    }
    Contract contract = getContractDataService().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.getInstance().getSiteAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case FILE:
            case GROUPOFFILES:
                asuc = AuditSetUpCommandFactory.getInstance().getUploadAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case SCENARIO:
                asuc = AuditSetUpCommandFactory.getInstance().getScenarioAuditSetUpCommand(contract, scenarioId, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case PAGE:
            case GROUPOFPAGES:
            default:
                asuc = AuditSetUpCommandFactory.getInstance().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;
    }
}
Also used : AuditSetUpCommand(org.asqatasun.webapp.command.AuditSetUpCommand) Contract(org.asqatasun.webapp.entity.contract.Contract) SelectFormField(org.asqatasun.webapp.form.SelectFormField) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 4 with SelectFormField

use of org.asqatasun.webapp.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(((TextualFormField) ff).getI18nKey(), ((TextualFormField) ff).getValue());
        }
    }
    contractDisplayCommand.setUserId(userId);
    return contractDisplayCommand;
}
Also used : SelectElement(org.asqatasun.webapp.form.SelectElement) TextualFormField(org.asqatasun.webapp.form.TextualFormField) List(java.util.List) SelectFormField(org.asqatasun.webapp.form.SelectFormField) FormField(org.asqatasun.webapp.form.FormField) TextualFormField(org.asqatasun.webapp.form.TextualFormField) Map(java.util.Map) ContractSortCommand(org.asqatasun.webapp.command.ContractSortCommand) SelectFormField(org.asqatasun.webapp.form.SelectFormField)

Example 5 with SelectFormField

use of org.asqatasun.webapp.form.SelectFormField in project Asqatasun by Asqatasun.

the class AbstractAuditSetUpController method displayFormWithErrors.

/**
     *
     * @param model
     * @param contract
     * @param auditSetUpCommand
     * @param authorisedReferentialList
     * @param parametersMap
     * @return
     */
private String displayFormWithErrors(Model model, Contract contract, AuditSetUpCommand auditSetUpCommand, Collection<String> authorisedReferentialList, Map<String, List<AuditSetUpFormField>> parametersMap) {
    model.addAttribute(TgolKeyStore.EXPANDED_KEY, TgolKeyStore.EXPANDED_VALUE);
    model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, auditSetUpCommand);
    model.addAttribute(TgolKeyStore.PARAMETERS_MAP_KEY, parametersMap);
    // Get a fresh list of the auditSetUpFormField that handles the choice
    // of the referential and its level
    List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
    // Otherwise it corresponds to the default behaviour;
    // The selection of default level is delegated to the helper.
    // When the form is on error, the default level value corresponds to the 
    // one the user has chosen. 
    AuditSetUpFormFieldHelper.selectDefaultLevelFromLevelValue(refAndLevelFormFieldList, auditSetUpCommand.getLevel());
    model.addAttribute(TgolKeyStore.LEVEL_LIST_KEY, refAndLevelFormFieldList);
    // if the user is authenticated, the url of the form is under
    // /home/contract/. To display error pages, we need to precise the
    // backward relative path and to add the breadCrumb.
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    ScopeEnum auditScope = auditSetUpCommand.getScope();
    switch(auditScope) {
        case DOMAIN:
            return TgolKeyStore.AUDIT_SITE_SET_UP_VIEW_NAME;
        case PAGE:
            return TgolKeyStore.AUDIT_PAGE_SET_UP_VIEW_NAME;
        case FILE:
            return TgolKeyStore.AUDIT_UPLOAD_SET_UP_VIEW_NAME;
    }
    return TgolKeyStore.OUPS_VIEW_NAME;
}
Also used : ScopeEnum(org.asqatasun.webapp.entity.contract.ScopeEnum) SelectFormField(org.asqatasun.webapp.form.SelectFormField)

Aggregations

SelectFormField (org.asqatasun.webapp.form.SelectFormField)6 TextualFormField (org.asqatasun.webapp.form.TextualFormField)2 List (java.util.List)1 Map (java.util.Map)1 AuditSetUpCommand (org.asqatasun.webapp.command.AuditSetUpCommand)1 ContractSortCommand (org.asqatasun.webapp.command.ContractSortCommand)1 Contract (org.asqatasun.webapp.entity.contract.Contract)1 ScopeEnum (org.asqatasun.webapp.entity.contract.ScopeEnum)1 OptionElement (org.asqatasun.webapp.entity.option.OptionElement)1 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)1 FormField (org.asqatasun.webapp.form.FormField)1 NumericalFormField (org.asqatasun.webapp.form.NumericalFormField)1 SelectElement (org.asqatasun.webapp.form.SelectElement)1 SelectFormFieldImpl (org.asqatasun.webapp.form.SelectFormFieldImpl)1 SelectFormFieldBuilderImpl (org.asqatasun.webapp.form.builder.SelectFormFieldBuilderImpl)1