Search in sources :

Example 1 with ContactBulkEditData

use of de.symeda.sormas.api.contact.ContactBulkEditData in project SORMAS-Project by hzi-braunschweig.

the class ContactController method showBulkContactDataEditComponent.

public void showBulkContactDataEditComponent(Collection<? extends ContactIndexDto> selectedContacts, String caseUuid) {
    if (selectedContacts.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoContactsSelected), I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false).show(Page.getCurrent());
        return;
    }
    // Check if cases with multiple districts have been selected
    String districtUuid = null;
    for (ContactIndexDto selectedContact : selectedContacts) {
        String selectedDistrictUuid = selectedContact.getDistrictUuid();
        if (districtUuid == null) {
            districtUuid = selectedDistrictUuid;
        } else if (!districtUuid.equals(selectedDistrictUuid)) {
            districtUuid = null;
            break;
        }
    }
    DistrictReferenceDto district = districtUuid != null ? FacadeProvider.getDistrictFacade().getReferenceByUuid(districtUuid) : null;
    // Create a temporary contact in order to use the CommitDiscardWrapperComponent
    ContactBulkEditData bulkEditData = new ContactBulkEditData();
    BulkContactDataForm form = new BulkContactDataForm(district, selectedContacts);
    form.setValue(bulkEditData);
    final CommitDiscardWrapperComponent<BulkContactDataForm> editView = new CommitDiscardWrapperComponent<BulkContactDataForm>(form, form.getFieldGroup());
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingEditContacts));
    editView.addCommitListener(() -> {
        ContactBulkEditData updatedBulkEditData = form.getValue();
        ContactFacade contactFacade = FacadeProvider.getContactFacade();
        boolean classificationChange = form.getClassificationCheckBox().getValue();
        boolean contactOfficerChange = district != null ? form.getContactOfficerCheckBox().getValue() : false;
        int changedContacts = bulkEdit(selectedContacts, updatedBulkEditData, contactFacade, classificationChange, contactOfficerChange);
        popupWindow.close();
        if (caseUuid == null) {
            overview();
        } else {
            caseContactsOverview(caseUuid);
        }
        if (changedContacts == selectedContacts.size()) {
            Notification.show(I18nProperties.getString(Strings.messageContactsEdited), Type.HUMANIZED_MESSAGE);
        } else {
            NotificationHelper.showNotification(String.format(I18nProperties.getString(Strings.messageContactsEditedExceptArchived), changedContacts), Type.HUMANIZED_MESSAGE, -1);
        }
    });
    editView.addDiscardListener(() -> popupWindow.close());
}
Also used : Window(com.vaadin.ui.Window) ContactFacade(de.symeda.sormas.api.contact.ContactFacade) ContactBulkEditData(de.symeda.sormas.api.contact.ContactBulkEditData) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Notification(com.vaadin.ui.Notification) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto)

Aggregations

Notification (com.vaadin.ui.Notification)1 Window (com.vaadin.ui.Window)1 ContactBulkEditData (de.symeda.sormas.api.contact.ContactBulkEditData)1 ContactFacade (de.symeda.sormas.api.contact.ContactFacade)1 ContactIndexDto (de.symeda.sormas.api.contact.ContactIndexDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)1