Search in sources :

Example 1 with CommitListener

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

the class PreviousHospitalizationsField method editEntry.

@Override
protected void editEntry(PreviousHospitalizationDto entry, boolean create, Consumer<PreviousHospitalizationDto> commitCallback) {
    if (create && entry.getUuid() == null) {
        entry.setUuid(DataHelper.createUuid());
    }
    PreviousHospitalizationEditForm editForm = new PreviousHospitalizationEditForm(create, fieldVisibilityCheckers, fieldAccessCheckers);
    editForm.setValue(entry);
    final CommitDiscardWrapperComponent<PreviousHospitalizationEditForm> editView = new CommitDiscardWrapperComponent<PreviousHospitalizationEditForm>(editForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT), editForm.getFieldGroup());
    editView.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getCaption(PreviousHospitalizationDto.I18N_PREFIX));
    editView.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            if (!editForm.getFieldGroup().isModified()) {
                commitCallback.accept(editForm.getValue());
            }
        }
    });
    if (!isEmpty(entry)) {
        editView.addDeleteListener(new DeleteListener() {

            @Override
            public void onDelete() {
                popupWindow.close();
                PreviousHospitalizationsField.this.removeEntry(entry);
            }
        }, I18nProperties.getCaption(PreviousHospitalizationDto.I18N_PREFIX));
    }
}
Also used : Window(com.vaadin.ui.Window) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DeleteListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Example 2 with CommitListener

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

the class TherapyController method openPrescriptionEditForm.

public void openPrescriptionEditForm(PrescriptionReferenceDto prescriptionReference, Runnable callback, boolean readOnly) {
    PrescriptionDto prescription = FacadeProvider.getPrescriptionFacade().getPrescriptionByUuid(prescriptionReference.getUuid());
    PrescriptionForm form = new PrescriptionForm(false, readOnly, prescription.isPseudonymized());
    form.setValue(prescription);
    final CommitDiscardWrapperComponent<PrescriptionForm> view = new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasUserRight(UserRight.PRESCRIPTION_EDIT), form.getFieldGroup());
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(view, I18nProperties.getString(readOnly ? Strings.entityPrescription : Strings.headingEditPrescription));
    view.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            if (!form.getFieldGroup().isModified()) {
                PrescriptionDto dto = form.getValue();
                FacadeProvider.getPrescriptionFacade().savePrescription(dto);
                popupWindow.close();
                Notification.show(I18nProperties.getString(Strings.messagePrescriptionSaved), Type.TRAY_NOTIFICATION);
                if (callback != null) {
                    callback.run();
                }
            }
        }
    });
    view.addDiscardListener(() -> popupWindow.close());
    if (UserProvider.getCurrent().hasUserRight(UserRight.PRESCRIPTION_DELETE)) {
        view.addDeleteListener(new DeleteListener() {

            @Override
            public void onDelete() {
                FacadeProvider.getPrescriptionFacade().deletePrescription(prescription.getUuid());
                popupWindow.close();
                if (callback != null) {
                    callback.run();
                }
            }
        }, I18nProperties.getString(Strings.entityPrescription));
    }
}
Also used : Window(com.vaadin.ui.Window) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DeleteListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Example 3 with CommitListener

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

the class InfrastructureController method getDistrictEditComponent.

private CommitDiscardWrapperComponent<DistrictEditForm> getDistrictEditComponent(DistrictDto district) {
    boolean isNew = district == null;
    DistrictEditForm editForm = new DistrictEditForm(isNew);
    if (isNew) {
        district = DistrictDto.build();
    }
    editForm.setValue(district);
    final CommitDiscardWrapperComponent<DistrictEditForm> editView = new CommitDiscardWrapperComponent<DistrictEditForm>(editForm, UserProvider.getCurrent().hasUserRight(isNew ? UserRight.INFRASTRUCTURE_CREATE : UserRight.INFRASTRUCTURE_EDIT), editForm.getFieldGroup());
    editView.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            FacadeProvider.getDistrictFacade().save(editForm.getValue());
            Notification.show(I18nProperties.getString(Strings.messageEntryCreated), Type.ASSISTIVE_NOTIFICATION);
            SormasUI.get().getNavigator().navigateTo(DistrictsView.VIEW_NAME);
        }
    });
    if (!isNew) {
        extendEditComponentWithArchiveButton(editView, district.isArchived(), district.getUuid(), InfrastructureType.DISTRICT, null);
    }
    return editView;
}
Also used : CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Example 4 with CommitListener

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

the class InfrastructureController method getCommunityEditComponent.

private CommitDiscardWrapperComponent<CommunityEditForm> getCommunityEditComponent(CommunityDto community) {
    boolean isNew = community == null;
    CommunityEditForm editForm = new CommunityEditForm(isNew);
    if (isNew) {
        community = CommunityDto.build();
    }
    editForm.setValue(community);
    final CommitDiscardWrapperComponent<CommunityEditForm> editView = new CommitDiscardWrapperComponent<CommunityEditForm>(editForm, UserProvider.getCurrent().hasUserRight(isNew ? UserRight.INFRASTRUCTURE_CREATE : UserRight.INFRASTRUCTURE_EDIT), editForm.getFieldGroup());
    editView.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            FacadeProvider.getCommunityFacade().save(editForm.getValue());
            Notification.show(I18nProperties.getString(Strings.messageEntryCreated), Type.ASSISTIVE_NOTIFICATION);
            SormasUI.get().getNavigator().navigateTo(CommunitiesView.VIEW_NAME);
        }
    });
    if (!isNew) {
        extendEditComponentWithArchiveButton(editView, community.isArchived(), community.getUuid(), InfrastructureType.COMMUNITY, null);
    }
    return editView;
}
Also used : CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Example 5 with CommitListener

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

the class ClinicalCourseController method openClinicalVisitCreateForm.

public void openClinicalVisitCreateForm(ClinicalCourseReferenceDto clinicalCourse, String caseUuid, Runnable callback) {
    CaseDataDto caze = FacadeProvider.getCaseFacade().getCaseDataByUuid(caseUuid);
    ClinicalVisitDto clinicalVisit = ClinicalVisitDto.build(clinicalCourse, caze.getDisease());
    ClinicalVisitForm form = new ClinicalVisitForm(true, clinicalVisit.getDisease(), FacadeProvider.getPersonFacade().getPersonByUuid(caze.getPerson().getUuid()), false);
    form.setValue(clinicalVisit);
    final CommitDiscardWrapperComponent<ClinicalVisitForm> view = new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasUserRight(UserRight.CLINICAL_VISIT_CREATE), form.getFieldGroup());
    view.setWidth(100, Unit.PERCENTAGE);
    view.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            if (!form.getFieldGroup().isModified()) {
                ClinicalVisitDto dto = form.getValue();
                dto = FacadeProvider.getClinicalVisitFacade().saveClinicalVisit(dto, caseUuid);
                Notification.show(I18nProperties.getString(Strings.messageClinicalVisitCreated), Type.TRAY_NOTIFICATION);
                if (callback != null) {
                    callback.run();
                }
            }
        }
    });
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(view, I18nProperties.getString(Strings.headingCreateNewClinicalVisit));
    // Clinical visit form is too big for typical screens
    popupWindow.setWidth(form.getWidth() + 90, Unit.PIXELS);
    popupWindow.setHeight(80, Unit.PERCENTAGE);
}
Also used : Window(com.vaadin.ui.Window) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Aggregations

CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)15 CommitListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)15 Window (com.vaadin.ui.Window)8 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 ClinicalVisitDto (de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto)2 PrescriptionDto (de.symeda.sormas.api.therapy.PrescriptionDto)2 TreatmentDto (de.symeda.sormas.api.therapy.TreatmentDto)2 DeleteListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener)2 Notification (com.vaadin.ui.Notification)1 EventDto (de.symeda.sormas.api.event.EventDto)1 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 AdditionalTestDto (de.symeda.sormas.api.sample.AdditionalTestDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 Set (java.util.Set)1