Search in sources :

Example 16 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class ActionController method create.

/**
 * Show a create form for an action.
 *
 * @param context of the action
 * @param entityRef of the action
 * @param callback on save
 */
public void create(ActionContext context, ReferenceDto entityRef, Runnable callback) {
    ActionEditForm createForm = new ActionEditForm(true);
    createForm.setValue(createNewAction(context, entityRef));
    final CommitDiscardWrapperComponent<ActionEditForm> editView = new CommitDiscardWrapperComponent<>(createForm, UserProvider.getCurrent().hasUserRight(UserRight.ACTION_CREATE), createForm.getFieldGroup());
    editView.addCommitListener(() -> {
        if (!createForm.getFieldGroup().isModified()) {
            ActionDto dto = createForm.getValue();
            FacadeProvider.getActionFacade().saveAction(dto);
            callback.run();
        }
    });
    VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingCreateNewAction));
}
Also used : CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) ActionDto(de.symeda.sormas.api.action.ActionDto)

Example 17 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class ActionController method edit.

/**
 * Show an edit form for an action.
 *
 * @param dto of the action
 * @param callback on save
 */
public void edit(ActionDto dto, Runnable callback) {
    // get fresh data
    ActionDto newDto = FacadeProvider.getActionFacade().getByUuid(dto.getUuid());
    ActionEditForm form = new ActionEditForm(false);
    form.setValue(newDto);
    final CommitDiscardWrapperComponent<ActionEditForm> editView = new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasUserRight(UserRight.ACTION_EDIT), form.getFieldGroup());
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingEditAction));
    editView.addCommitListener(() -> {
        if (!form.getFieldGroup().isModified()) {
            ActionDto dto1 = form.getValue();
            dto1.setLastModifiedBy(FacadeProvider.getUserFacade().getCurrentUser().toReference());
            FacadeProvider.getActionFacade().saveAction(dto1);
            popupWindow.close();
            callback.run();
        }
    });
    // Add delete button if user has role
    if (UserProvider.getCurrent().hasUserRole(UserRole.ADMIN)) {
        editView.addDeleteListener(() -> {
            FacadeProvider.getActionFacade().deleteAction(newDto);
            UI.getCurrent().removeWindow(popupWindow);
            callback.run();
        }, I18nProperties.getString(Strings.entityAction));
    }
    editView.addDiscardListener(popupWindow::close);
}
Also used : Window(com.vaadin.ui.Window) ActionDto(de.symeda.sormas.api.action.ActionDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 18 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class CampaignController method getCampaignFormDataComponent.

public CommitDiscardWrapperComponent<CampaignFormDataEditForm> getCampaignFormDataComponent(CampaignFormDataDto campaignFormData, CampaignReferenceDto campaign, CampaignFormMetaReferenceDto campaignForm, boolean revertFormOnDiscard, boolean showDeleteButton, Runnable commitCallback, Runnable discardCallback) {
    CampaignFormDataEditForm form = new CampaignFormDataEditForm(campaignFormData == null);
    if (campaignFormData == null) {
        final UserDto currentUser = UserProvider.getCurrent().getUser();
        campaignFormData = CampaignFormDataDto.build(campaign, campaignForm, currentUser.getRegion(), currentUser.getDistrict(), currentUser.getCommunity());
        campaignFormData.setCreatingUser(UserProvider.getCurrent().getUserReference());
    }
    form.setValue(campaignFormData);
    final CommitDiscardWrapperComponent<CampaignFormDataEditForm> component = new CommitDiscardWrapperComponent<>(form, form.getFieldGroup());
    component.addCommitListener(() -> {
        if (!form.getFieldGroup().isModified()) {
            try {
                form.validate();
            } catch (InvalidValueException e) {
                Notification.show(I18nProperties.getValidationError(Validations.errorsInForm), Type.ERROR_MESSAGE);
                return;
            }
            CampaignFormDataDto formData = form.getValue();
            FacadeProvider.getCampaignFormDataFacade().saveCampaignFormData(formData);
            if (commitCallback != null) {
                commitCallback.run();
                UI.getCurrent().getNavigator().navigateTo(CampaignDataView.VIEW_NAME + "/?" + CAMPAIGN + "=" + campaign.getUuid());
            }
        }
    });
    component.addDiscardListener(() -> UI.getCurrent().getNavigator().navigateTo(CampaignDataView.VIEW_NAME + "/?" + CAMPAIGN + "=" + campaign.getUuid()));
    if (revertFormOnDiscard) {
        component.addDiscardListener(form::resetFormValues);
    }
    if (discardCallback != null) {
        component.addDiscardListener(discardCallback::run);
    }
    if (showDeleteButton && UserProvider.getCurrent().hasUserRight(UserRight.CAMPAIGN_DELETE)) {
        String campaignFormDataUuid = campaignFormData.getUuid();
        component.addDeleteListener(() -> {
            FacadeProvider.getCampaignFormDataFacade().deleteCampaignFormData(campaignFormDataUuid);
            UI.getCurrent().getNavigator().navigateTo(CampaignFormDataView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityCampaignDataForm));
    }
    return component;
}
Also used : InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) UserDto(de.symeda.sormas.api.user.UserDto) CampaignFormDataEditForm(de.symeda.sormas.ui.campaign.campaigndata.CampaignFormDataEditForm) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 19 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class CampaignController method getCampaignComponent.

public CommitDiscardWrapperComponent<CampaignEditForm> getCampaignComponent(CampaignDto campaignDto, Runnable callback) {
    CampaignEditForm campaignEditForm = new CampaignEditForm(campaignDto);
    boolean isCreate = false;
    if (campaignDto == null) {
        isCreate = true;
        campaignDto = CampaignDto.build();
        campaignDto.setCreatingUser(UserProvider.getCurrent().getUserReference());
    }
    campaignEditForm.setValue(campaignDto);
    final CommitDiscardWrapperComponent<CampaignEditForm> campaignComponent = new CommitDiscardWrapperComponent<CampaignEditForm>(campaignEditForm, UserProvider.getCurrent().hasUserRight(UserRight.CAMPAIGN_EDIT), campaignEditForm.getFieldGroup()) {

        @Override
        public void discard() {
            super.discard();
            campaignEditForm.discard();
        }
    };
    if (UserProvider.getCurrent().hasUserRight(UserRight.CAMPAIGN_DELETE) && !isCreate) {
        CampaignDto finalCampaignDto = campaignDto;
        campaignComponent.addDeleteListener(() -> {
            FacadeProvider.getCampaignFacade().deleteCampaign(finalCampaignDto.getUuid());
            UI.getCurrent().getNavigator().navigateTo(CampaignsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityCampaign));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.CAMPAIGN_ARCHIVE) && !isCreate) {
        final CampaignDto campaign = campaignDto;
        createArchiveButton(campaignComponent, campaign);
    }
    campaignComponent.addCommitListener(() -> {
        if (!campaignEditForm.getFieldGroup().isModified()) {
            CampaignDto dto = campaignEditForm.getValue();
            FacadeProvider.getCampaignFacade().save(dto);
            SormasUI.refreshView();
            callback.run();
        }
    });
    return campaignComponent;
}
Also used : CampaignDto(de.symeda.sormas.api.campaign.CampaignDto) CampaignEditForm(de.symeda.sormas.ui.campaign.campaigns.CampaignEditForm) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 20 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantsController method createEventParticipant.

public EventParticipantDto createEventParticipant(EventReferenceDto eventRef, Consumer<EventParticipantReferenceDto> doneConsumer, EventParticipantDto eventParticipant, boolean navigateOnCommit) {
    EventParticipantCreateForm createForm = new EventParticipantCreateForm(!FacadeProvider.getEventFacade().hasRegionAndDistrict(eventRef.getUuid()));
    createForm.setValue(eventParticipant);
    final CommitDiscardWrapperComponent<EventParticipantCreateForm> createComponent = new CommitDiscardWrapperComponent<>(createForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENTPARTICIPANT_CREATE), createForm.getFieldGroup());
    createComponent.addCommitListener(() -> {
        if (!createForm.getFieldGroup().isModified()) {
            final EventParticipantDto dto = createForm.getValue();
            PersonDto searchedPerson = createForm.getSearchedPerson();
            if (searchedPerson != null) {
                dto.setPerson(searchedPerson);
            }
            if (dto.getPerson() == null) {
                final PersonDto person = PersonDto.build();
                person.setFirstName(createForm.getPersonFirstName());
                person.setLastName(createForm.getPersonLastName());
                person.setSex(createForm.getPersonSex());
                ControllerProvider.getPersonController().selectOrCreatePerson(person, I18nProperties.getString(Strings.infoSelectOrCreatePersonForEventParticipant), selectedPerson -> {
                    if (selectedPerson != null) {
                        if (FacadeProvider.getEventParticipantFacade().exists(selectedPerson.getUuid(), eventRef.getUuid())) {
                            throw new Validator.InvalidValueException(I18nProperties.getString(Strings.messageAlreadyEventParticipant));
                        } else {
                            dto.setPerson(FacadeProvider.getPersonFacade().getPersonByUuid(selectedPerson.getUuid()));
                            EventParticipantDto savedDto = eventParticipantFacade.saveEventParticipant(dto);
                            Notification notification = new Notification(I18nProperties.getString(Strings.messagePersonAddedAsEventParticipant), "", Type.HUMANIZED_MESSAGE);
                            notification.show(Page.getCurrent());
                            Notification.show(I18nProperties.getString(Strings.messageEventParticipantCreated), Type.ASSISTIVE_NOTIFICATION);
                            if (navigateOnCommit) {
                                navigateToData(savedDto.getUuid());
                            } else {
                                SormasUI.refreshView();
                            }
                        }
                    }
                }, true);
            } else {
                if (FacadeProvider.getEventParticipantFacade().exists(dto.getPerson().getUuid(), eventRef.getUuid())) {
                    throw new Validator.InvalidValueException(I18nProperties.getString(Strings.messageAlreadyEventParticipant));
                }
                EventParticipantDto savedDto = eventParticipantFacade.saveEventParticipant(dto);
                Notification.show(I18nProperties.getString(Strings.messageEventParticipantCreated), Type.ASSISTIVE_NOTIFICATION);
                if (navigateOnCommit) {
                    navigateToData(savedDto.getUuid());
                } else {
                    SormasUI.refreshView();
                }
            }
        }
    });
    Window window = VaadinUiUtil.showModalPopupWindow(createComponent, I18nProperties.getString(Strings.headingCreateNewEventParticipant));
    window.addCloseListener(e -> {
        doneConsumer.accept(null);
    });
    return createComponent.getWrappedComponent().getValue();
}
Also used : Window(com.vaadin.ui.Window) PersonDto(de.symeda.sormas.api.person.PersonDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) Notification(com.vaadin.ui.Notification)

Aggregations

CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)101 Window (com.vaadin.ui.Window)34 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)22 EventDto (de.symeda.sormas.api.event.EventDto)17 Button (com.vaadin.ui.Button)16 CommitListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)15 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)13 PersonDto (de.symeda.sormas.api.person.PersonDto)13 ContactDto (de.symeda.sormas.api.contact.ContactDto)12 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)12 Label (com.vaadin.ui.Label)11 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)11 Notification (com.vaadin.ui.Notification)10 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)10 AutomaticDeletionLabel (de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)10 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)9 UserDto (de.symeda.sormas.api.user.UserDto)9 EventSelectionField (de.symeda.sormas.ui.events.eventLink.EventSelectionField)9 AutomaticDeletionInfoDto (de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto)8 SampleDto (de.symeda.sormas.api.sample.SampleDto)8