Search in sources :

Example 1 with PersonContactDetailType

use of de.symeda.sormas.api.person.PersonContactDetailType in project SORMAS-Project by hzi-braunschweig.

the class PersonContactDetailEditForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addField(PersonContactDetailDto.THIRD_PARTY, CheckBox.class).setCaption(I18nProperties.getCaption(Captions.personContactDetailThirdParty));
    addField(PersonContactDetailDto.THIRD_PARTY_ROLE, TextField.class);
    addField(PersonContactDetailDto.THIRD_PARTY_NAME, TextField.class);
    addField(PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE);
    addField(PersonContactDetailDto.PHONE_NUMBER_TYPE);
    addField(PersonContactDetailDto.DETAILS, TextField.class);
    addField(PersonContactDetailDto.CONTACT_INFORMATION, TextField.class);
    addField(PersonContactDetailDto.ADDITIONAL_INFORMATION, TextField.class);
    addField(PersonContactDetailDto.PRIMARY_CONTACT, CheckBox.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.THIRD_PARTY_ROLE, PersonContactDetailDto.THIRD_PARTY_NAME), PersonContactDetailDto.THIRD_PARTY, true, true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.DETAILS), PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE, PersonContactDetailType.OTHER, false);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.DETAILS), PersonContactDetailDto.PHONE_NUMBER_TYPE, PhoneNumberType.OTHER, false);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.PHONE_NUMBER_TYPE), PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE, PersonContactDetailType.PHONE, false);
    addFieldListeners(PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE, e -> {
        final Field<?> contactInformationField = getFieldGroup().getField(PersonContactDetailDto.CONTACT_INFORMATION);
        final PersonContactDetailType value = (PersonContactDetailType) e.getProperty().getValue();
        for (Validator validator : contactInformationField.getValidators()) {
            contactInformationField.removeValidator(validator);
        }
        if (value == PersonContactDetailType.PHONE) {
            contactInformationField.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactInformationField.getCaption())));
        } else if (value == PersonContactDetailType.EMAIL) {
            contactInformationField.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactInformationField.getCaption())));
        }
    });
}
Also used : PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) CheckBox(com.vaadin.v7.ui.CheckBox) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Validator(com.vaadin.v7.data.Validator) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator)

Aggregations

Validator (com.vaadin.v7.data.Validator)1 EmailValidator (com.vaadin.v7.data.validator.EmailValidator)1 CheckBox (com.vaadin.v7.ui.CheckBox)1 PersonContactDetailType (de.symeda.sormas.api.person.PersonContactDetailType)1 PhoneNumberValidator (de.symeda.sormas.ui.utils.PhoneNumberValidator)1