EDocument handling modified for ServiceRecord
authorVásáry Dániel <vasary@elgekko.net>
Tue, 19 Dec 2023 11:01:54 +0000 (12:01 +0100)
committerVásáry Dániel <vasary@elgekko.net>
Tue, 19 Dec 2023 11:01:54 +0000 (12:01 +0100)
27 files changed:
lis-app/src/test/java/hu/user/lis/EventIT.java [new file with mode: 0644]
lis-db/migrations/scripts/017_add_type_reference_id_to_edocument.sql [new file with mode: 0644]
lis-db/src/main/java/hu/user/lis/db/EDocument.java
lis-db/src/main/java/hu/user/lis/db/ServiceRecord.java
lis-db/src/main/java/hu/user/lis/db/repository/EDocumentRepository.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/converter/ByteArrayToAMediaConverter.java
lis-ui/src/main/java/hu/user/lis/ui/data/AssociateSelectorDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/EntityDocumentDataModel.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/editor/ImportInvoiceApproveEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ImportInvoiceAssignEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/common/EditCompletedListener.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/editor/common/Editors.java
lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/event/CancelEntityEditEvent.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityEvent.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityWithAttachmentEvent.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ImportInvoicesSuspendedViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/InvoicesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java
lis-ui/src/main/resources/web/editor/service-record-editor.zul
lis-ui/src/main/resources/web/form/attachment-form.zul [new file with mode: 0644]

diff --git a/lis-app/src/test/java/hu/user/lis/EventIT.java b/lis-app/src/test/java/hu/user/lis/EventIT.java
new file mode 100644 (file)
index 0000000..4d96ecd
--- /dev/null
@@ -0,0 +1,28 @@
+
+/*
+ * Copyright (c) $today.year-$today.month-24.
+ * By elGekko
+ */
+
+package hu.user.lis;
+
+import lombok.extern.log4j.Log4j2;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.test.context.junit4.SpringRunner;
+
+
+@Log4j2
+@RunWith(SpringRunner.class)
+@ComponentScan("hu.user.lis")
+@SpringBootTest
+public class EventIT {
+    @Test
+    public void testSaveEntityEvent() {
+        String data = "";
+    }
+
+
+}
diff --git a/lis-db/migrations/scripts/017_add_type_reference_id_to_edocument.sql b/lis-db/migrations/scripts/017_add_type_reference_id_to_edocument.sql
new file mode 100644 (file)
index 0000000..4ad080e
--- /dev/null
@@ -0,0 +1,22 @@
+-- // add document type, reference_id to edocument
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE edocument
+    ADD COLUMN document_type VARCHAR(50) NOT NULL DEFAULT ''
+    ADD COLUMN reference_id BIGINT
+    ALTER COLUMN created SET NOT NULL;
+
+CALL SYSPROC.ADMIN_CMD('REORG TABLE edocument');
+
+CREATE INDEX IDX_EDOCUMENT_REFERENCE_ID_DOCUMENT_TYPE ON edocument(reference_id, document_type);
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+DROP INDEX IDX_EDOCUMENT_REFERENCE_ID_DOCUMENT_TYPE;
+
+ALTER TABLE edocument
+    DROP COLUMN document_type
+    DROP COLUMN reference_id
+    ALTER COLUMN created DROP NOT NULL;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE edocument');
index e10c0cae016c5c747bd1cf1050c858944ef5c4e1..06a36accad75ba58adb66ee000dce81cfaddc379 100644 (file)
@@ -1,11 +1,9 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
 
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
+import javax.persistence.*;
 import java.io.Serializable;
 import java.util.Date;
 
@@ -18,10 +16,25 @@ import java.util.Date;
 public class EDocument implements Serializable {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
-    Long id;
-    Date created;
-    String name;
-    String description;
-    int size;
-    byte[] file;
+    private Long id;
+
+    @Column(nullable = false)
+    private Long referenceId;
+
+    @Column(nullable = false)
+    private String documentType;
+
+    @Column(updatable = false)
+    @CreationTimestamp
+    private Date created;
+
+    private String description;
+
+    private int size;
+
+    @Column(nullable = false)
+    private byte[] file;
+
+    @Column(nullable = false)
+    private String name;
 }
index b0c1c114a1e3c3a8c18955e0a7a750de3a014dc2..44d9d27852d924e732bf51b6663b407ef2d5a6c6 100644 (file)
@@ -16,19 +16,27 @@ import java.util.Date;
 public class ServiceRecord implements Serializable {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
-    Long id;
+    private Long id;
+
     @ManyToOne
     @JoinColumn(name = "project_id")
     @JsonIncludeProperties({"id"})
-    Project project;
+    private Project project;
+
     @ManyToOne
     @JoinColumn(name = "associate_id")
     @JsonIncludeProperties({"id"})
-    Associate associate;
-    Date workDay;
-    String description;
-    String details;
-    int workHours;
-    double cost;
-    byte[] file;
+    private Associate associate;
+
+    private Date workDay;
+
+    private String description;
+
+    private String details;
+
+    private int workHours;
+
+    private double cost;
+    
+    private byte[] file;
 }
diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/EDocumentRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/EDocumentRepository.java
new file mode 100644 (file)
index 0000000..7b913e3
--- /dev/null
@@ -0,0 +1,11 @@
+package hu.user.lis.db.repository;
+
+import hu.user.lis.db.EDocument;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import java.util.List;
+
+public interface EDocumentRepository extends JpaRepository<EDocument, Long> {
+    List<EDocument> findByReferenceIdAndDocumentType(Long referenceId, String documentType);
+
+}
index 9d600c910985ca8de1b62287217b3573e24eaa96..5a62fcfe42bf020bff80ae3361114cf88294fe6a 100644 (file)
@@ -14,7 +14,7 @@ public class ByteArrayToAMediaConverter implements Converter<AMedia, byte[], Ifr
         if (Objects.isNull(data)) {
             return null;
         }
-        return new AMedia("Számlakép", "pdf", "application/pdf", data);
+        return new AMedia("Attachment", "pdf", "application/pdf", data);
     }
 
     @Override
index 1c0740441ab1bfce77fe2c93dd7409adcce2f253..00037fa130a0a5fbd35234199e369b6d8f8e73c8 100644 (file)
@@ -14,8 +14,8 @@ import org.zkoss.zul.FieldComparator;
 
 import java.util.List;
 
-@Component
 @Log4j2
+@Component
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class AssociateSelectorDataModel extends CachedSpringDataModel<Associate> {
     static private final int SEARCH_LIMIT = 10;
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/EntityDocumentDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/EntityDocumentDataModel.java
new file mode 100644 (file)
index 0000000..8d8443c
--- /dev/null
@@ -0,0 +1,63 @@
+package hu.user.lis.ui.data;
+
+import hu.user.lis.db.EDocument;
+import hu.user.lis.db.repository.EDocumentRepository;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import org.zkoss.zul.ListModelList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Log4j2
+@Component
+@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class EntityDocumentDataModel extends ListModelList<EDocument> {
+    private final List<EDocument> added = new ArrayList<>();
+    private final List<EDocument> removed = new ArrayList<>();
+    @Autowired
+    private EDocumentRepository eDocumentRepository;
+
+
+    public EDocument refresh(Long referenceId, String documentType) {
+        EDocument result = null;
+        clear();
+        List<EDocument> documents = eDocumentRepository.findByReferenceIdAndDocumentType(referenceId, documentType);
+        addAll(documents);
+        if (!documents.isEmpty()) {
+            result = documents.stream().findFirst().get();
+        }
+        return result;
+    }
+
+    public void addNew(EDocument document) {
+        added.add(document);
+//        selectedDocument = document;
+        add(document);
+    }
+
+    public void remove() {
+        Set<EDocument> documents = getSelection();
+        if (documents.isEmpty()) {
+            return;
+        }
+        removed.addAll(documents);
+//        clearSelection();
+//        selectedDocument = null;
+        removeAll(documents);
+    }
+
+    public void save(Long entityId) {
+        eDocumentRepository.deleteAll(removed);
+        added.forEach(d -> d.setReferenceId(entityId));
+        eDocumentRepository.saveAll(added);
+    }
+
+    public boolean isChanged() {
+        return !added.isEmpty() || !removed.isEmpty();
+    }
+}
index ac2d672688c159d3430571012cd12377170d33f7..8e1c4b7c36843e45169f41c199d8b2cf0ccf95d4 100644 (file)
@@ -8,6 +8,7 @@ import hu.user.lis.ui.data.PartnersDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.validator.FormValidator;
 import hu.user.lis.ui.editor.validator.ImportInvoiceApproveFormValidator;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.workflow.invoice.data.InvoiceImportStatus;
 import lombok.Getter;
 import lombok.Setter;
@@ -61,9 +62,16 @@ public class ImportInvoiceApproveEditorModel extends InvoiceEditorModel {
     @Command
     public void onEditPartner() {
         Partner entity = partnersDataModel.clone(getFormDocument().getPartner());
-        Editors.doEdit(Editors.PARTNER, entity, modifiedEntity -> getFormDocument().setPartner(modifiedEntity));
+        Editors.doEdit(Editors.PARTNER, entity, this::handleEntitySaveEvent);
     }
 
+    public void handleEntitySaveEvent(SaveEntityEvent<Partner> event) {
+        if (!event.isCanceled()) {
+            getFormDocument().setPartner(event.getData());
+        }
+    }
+
+
     @Command
     public void onCloseApproveWindow(@BindingParam("target") Window target, @BindingParam("status") InvoiceImportStatus status) {
         if (InvoiceImportStatus.NONE.equals(status)) {
index fdb20f0c6e76016bea3d2f749ef5d94e08d55d09..3c85196be43345edcaa23039d11d13a8aea47558 100644 (file)
@@ -9,6 +9,7 @@ import hu.user.lis.ui.data.PartnersDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.validator.FormValidator;
 import hu.user.lis.ui.editor.validator.ImportInvoiceAssignFormValidator;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.workflow.invoice.data.InvoiceImportStatus;
 import lombok.Getter;
 import lombok.Setter;
@@ -73,7 +74,13 @@ public class ImportInvoiceAssignEditorModel extends InvoiceEditorModel {
     @Command
     public void onEditPartner() {
         Partner entity = partnersDataModel.clone(getFormDocument().getPartner());
-        Editors.doEdit(Editors.PARTNER, entity, modifiedEntity -> getFormDocument().setPartner(modifiedEntity));
+        Editors.doEdit(Editors.PARTNER, entity, this::handleEntitySaveEvent);
+    }
+
+    public void handleEntitySaveEvent(SaveEntityEvent<Partner> event) {
+        if (!event.isCanceled()) {
+            getFormDocument().setPartner(event.getData());
+        }
     }
 
     @Command
index f422f5c3a39681338cd90859014f5bc1117427af..992ef5ea724085dba3b15600d5ef8e74500611b5 100644 (file)
@@ -9,6 +9,7 @@ import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.common.EntityEditorModel;
 import hu.user.lis.ui.editor.validator.FormValidator;
 import hu.user.lis.ui.editor.validator.ProjectFormValidator;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.log4j.Log4j2;
@@ -177,27 +178,37 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     @Command
     public void onAddIncoming() {
         IncomingInvoice entity = invoiceDataModel.createNewIncomingInvoice();
-        Editors.doEdit(Editors.INCOMING_INVOICE, entity, modifiedEntity -> {
+        Editors.doEdit(Editors.INCOMING_INVOICE, entity, this::incomingAdded);
+    }
+
+    @Command
+    public void onEditIncoming() {
+        IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
+        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::incomingModified);
+    }
+
+    private void incomingAdded(SaveEntityEvent<IncomingInvoice> event) {
+        if (!event.isCanceled()) {
+            IncomingInvoice modifiedEntity = event.getData();
             getFormDocument().getIncomingInvoices().add(modifiedEntity);
             selectedIncomingInvoice = modifiedEntity;
             validate();
             BindUtils.postNotifyChange(this, "selectedIncomingInvoice");
             BindUtils.postNotifyChange(getFormDocument(), "incomingInvoices");
-        });
+        }
     }
 
-    @Command
-    public void onEditIncoming() {
-        IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
-        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, modifiedEntity -> {
+    private void incomingModified(SaveEntityEvent<IncomingInvoice> event) {
+        if (!event.isCanceled()) {
             Set<IncomingInvoice> incomingInvoices = getFormDocument().getIncomingInvoices();
             incomingInvoices.remove(selectedIncomingInvoice);
+            IncomingInvoice modifiedEntity = event.getData();
             incomingInvoices.add(modifiedEntity);
             selectedIncomingInvoice = modifiedEntity;
             validate();
             BindUtils.postNotifyChange(this, "selectedIncomingInvoice");
             BindUtils.postNotifyChange(getFormDocument(), "incomingInvoices");
-        });
+        }
     }
 
     @Command
@@ -214,19 +225,29 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     @Command
     public void onAddOutgoing() {
         OutgoingInvoice entity = invoiceDataModel.createNewOutgoingInvoice();
-        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, modifiedEntity -> {
+        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, this::outgoingAdded);
+    }
+
+    @Command
+    public void onEditOutgoing() {
+        OutgoingInvoice entity = invoiceDataModel.clone(selectedOutgoingInvoice);
+        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, this::outgoingModified);
+    }
+
+    private void outgoingAdded(SaveEntityEvent<OutgoingInvoice> event) {
+        if (!event.isCanceled()) {
+            OutgoingInvoice modifiedEntity = event.getData();
             getFormDocument().getOutgoingInvoices().add(modifiedEntity);
             selectedOutgoingInvoice = modifiedEntity;
             validate();
             BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
             BindUtils.postNotifyChange(getFormDocument(), "outgoingInvoices");
-        });
+        }
     }
 
-    @Command
-    public void onEditOutgoing() {
-        OutgoingInvoice entity = invoiceDataModel.clone(selectedOutgoingInvoice);
-        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, modifiedEntity -> {
+    private void outgoingModified(SaveEntityEvent<OutgoingInvoice> event) {
+        if (!event.isCanceled()) {
+            OutgoingInvoice modifiedEntity = event.getData();
             Set<OutgoingInvoice> outgoingInvoices = getFormDocument().getOutgoingInvoices();
             outgoingInvoices.remove(selectedOutgoingInvoice);
             outgoingInvoices.add(modifiedEntity);
@@ -234,7 +255,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
             validate();
             BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
             BindUtils.postNotifyChange(getFormDocument(), "outgoingInvoices");
-        });
+        }
     }
 
     @Command
@@ -251,19 +272,29 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     @Command
     public void onAddTreasury() {
         Treasury entity = treasuryDataModel.createNew();
-        Editors.doEdit(Editors.TREASURY, entity, modifiedEntity -> {
+        Editors.doEdit(Editors.TREASURY, entity, this::treasuryAdded);
+    }
+
+    @Command
+    public void onEditTreasury() {
+        Treasury entity = treasuryDataModel.clone(selectedTreasury);
+        Editors.doEdit(Editors.TREASURY, entity, selectedTreasury, this::treasuryModified);
+    }
+
+    private void treasuryAdded(SaveEntityEvent<Treasury> event) {
+        if (!event.isCanceled()) {
+            Treasury modifiedEntity = event.getData();
             getFormDocument().getTreasuries().add(modifiedEntity);
             selectedTreasury = modifiedEntity;
             validate();
             BindUtils.postNotifyChange(this, "selectedTreasury");
             BindUtils.postNotifyChange(getFormDocument(), "treasuries");
-        });
+        }
     }
 
-    @Command
-    public void onEditTreasury() {
-        Treasury entity = treasuryDataModel.clone(selectedTreasury);
-        Editors.doEdit(Editors.TREASURY, entity, selectedTreasury, modifiedEntity -> {
+    private void treasuryModified(SaveEntityEvent<Treasury> event) {
+        if (!event.isCanceled()) {
+            Treasury modifiedEntity = event.getData();
             Set<Treasury> treasuries = getFormDocument().getTreasuries();
             treasuries.remove(selectedTreasury);
             treasuries.add(modifiedEntity);
@@ -271,7 +302,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
             validate();
             BindUtils.postNotifyChange(this, "selectedTreasury");
             BindUtils.postNotifyChange(getFormDocument(), "treasuries");
-        });
+        }
     }
 
     @Command
index e12e514689da13742a6c3c13bb85158c1b5db99c..944844f7ea0ab0723088a3a0af52d949bbad7a77 100644 (file)
@@ -6,21 +6,20 @@ import hu.user.lis.db.ProjectAssociate;
 import hu.user.lis.db.ServiceRecord;
 import hu.user.lis.ui.auth.CurrentProfile;
 import hu.user.lis.ui.data.ProjectAssociatesDataModel;
-import hu.user.lis.ui.editor.common.EntityEditorModel;
+import hu.user.lis.ui.editor.common.EntityAttachmentEditorModel;
 import hu.user.lis.ui.editor.selector.EntitySelectorModel;
 import hu.user.lis.ui.editor.validator.FormValidator;
 import hu.user.lis.ui.editor.validator.ServiceRecordFormValidator;
+import hu.user.lis.ui.event.CancelEntityEditEvent;
+import hu.user.lis.ui.event.SaveEntityWithAttachmentEvent;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.log4j.Log4j2;
-import org.zkoss.bind.BindContext;
-import org.zkoss.bind.BindUtils;
 import org.zkoss.bind.PropertyChangeEvent;
 import org.zkoss.bind.annotation.*;
 import org.zkoss.zk.ui.Component;
 import org.zkoss.zk.ui.event.Event;
 import org.zkoss.zk.ui.event.Events;
-import org.zkoss.zk.ui.event.UploadEvent;
 import org.zkoss.zk.ui.select.annotation.WireVariable;
 import org.zkoss.zul.Messagebox;
 import org.zkoss.zul.Window;
@@ -33,18 +32,18 @@ import java.util.stream.Collectors;
 @Log4j2
 @Getter
 @Setter
-public class ServiceRecordEditorModel extends EntityEditorModel<ServiceRecord> {
+public class ServiceRecordEditorModel extends EntityAttachmentEditorModel<ServiceRecord> {
     @WireVariable
-    CurrentProfile currentProfile;
+    private CurrentProfile currentProfile;
 
     @WireVariable
-    ProjectAssociatesDataModel projectAssociatesDataModel;
-
-    private EntitySelectorModel<?> projectEntitySelectorModel;
+    private ProjectAssociatesDataModel projectAssociatesDataModel;
 
     @WireVariable
     private ServiceRecordFormValidator serviceRecordFormValidator;
 
+    private EntitySelectorModel<?> projectEntitySelectorModel;
+
     @Override
     public FormValidator<ServiceRecord> getFormValidator() {
         return serviceRecordFormValidator;
@@ -54,6 +53,7 @@ public class ServiceRecordEditorModel extends EntityEditorModel<ServiceRecord> {
     @Override
     public void init() {
         super.init();
+        setSelectedDocument(getEntityDocumentDataModel().refresh(getFormDocument().getId(), ServiceRecord.class.getSimpleName()));
     }
 
     @AfterCompose
@@ -84,27 +84,23 @@ public class ServiceRecordEditorModel extends EntityEditorModel<ServiceRecord> {
     @Override
     public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("save") boolean save) {
         if (save) {
-            Optional<ProjectAssociate> opProjectAssociate = projectAssociatesDataModel.searchByAssociateAndProject(getFormDocument().getAssociate().getId(),
-                    getFormDocument().getProject().getId());
-            if (opProjectAssociate.isPresent()) {
-                doSave(target);
-            } else {
-                Messagebox.show("A munkatárs a kiválasztott projekt résztvevője lesz.", "Megerősítés",
-                        Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, e -> {
-                            if (!e.getName().equals("onCancel")) {
-                                projectAssociatesDataModel.addProjectAssociate(getFormDocument().getProject(), getFormDocument().getAssociate());
-                                doSave(target);
-                            }
-                        });
+            if (isSaveEnabled()) {
+                Optional<ProjectAssociate> opProjectAssociate = projectAssociatesDataModel.searchByAssociateAndProject(getFormDocument().getAssociate().getId(),
+                        getFormDocument().getProject().getId());
+                if (opProjectAssociate.isPresent()) {
+                    Events.postEvent(new SaveEntityWithAttachmentEvent<>(getFormDocument(), getEntityDocumentDataModel(), target));
+                } else {
+                    Messagebox.show("A munkatárs a kiválasztott projekt résztvevője lesz.", "Megerősítés",
+                            Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, e -> {
+                                if (!e.getName().equals("onCancel")) {
+                                    projectAssociatesDataModel.addProjectAssociate(getFormDocument().getProject(), getFormDocument().getAssociate());
+                                    Events.postEvent(new SaveEntityWithAttachmentEvent<>(getFormDocument(), getEntityDocumentDataModel(), target));
+                                }
+                            });
+                }
             }
         } else {
-            Events.postEvent(new Event("onClose", target, null));
-        }
-    }
-
-    private void doSave(Window target) {
-        if (isSaveEnabled()) {
-            Events.postEvent(new Event("onClose", target, getFormDocument()));
+            Events.postEvent(new CancelEntityEditEvent<>(target));
         }
     }
 
@@ -115,30 +111,6 @@ public class ServiceRecordEditorModel extends EntityEditorModel<ServiceRecord> {
         return Collections.emptyList();
     }
 
-    @Override
-    protected boolean canSave(ServiceRecord entity) {
-        return serviceRecordFormValidator.validate(entity);
-    }
-
-    @Command
-    public void onUploadFile(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
-        UploadEvent evt = (UploadEvent) ctx.getTriggerEvent();
-        if (!evt.getMedia().getName().toLowerCase().endsWith(".pdf")) {
-            Messagebox.show("Csak PDF állomány feltöltése támogatott.", "Error", Messagebox.OK, Messagebox.ERROR);
-            return;
-        }
-        getFormDocument().setFile(evt.getMedia().getByteData());
-        BindUtils.postNotifyChange(getFormDocument(), "file");
-        validate();
-    }
-
-    @Command
-    public void onRemoveFile() {
-        getFormDocument().setFile(null);
-        BindUtils.postNotifyChange(getFormDocument(), "file");
-        validate();
-    }
-
     @Override
     public void onEvent(Event evt) {
         if (isEventForCurrentDocument(evt)) {
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EditCompletedListener.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EditCompletedListener.java
new file mode 100644 (file)
index 0000000..e8e200b
--- /dev/null
@@ -0,0 +1,9 @@
+package hu.user.lis.ui.editor.common;
+
+import hu.user.lis.ui.event.SaveEntityEvent;
+
+public interface EditCompletedListener<E> {
+
+    void handle(SaveEntityEvent<E> entity);
+
+}
index f904d580ef261733586f0895acddb0f7013a4e99..7c9ef941679538d787599c8b1066df0a8b6762e6 100644 (file)
@@ -1,12 +1,15 @@
 package hu.user.lis.ui.editor.common;
 
 import com.google.common.collect.ImmutableMap;
+import hu.user.lis.ui.event.SaveEntityEvent;
+import lombok.extern.log4j.Log4j2;
 import org.zkoss.zk.ui.Executions;
 import org.zkoss.zul.Window;
 
 import java.util.Map;
 import java.util.Objects;
 
+@Log4j2
 public class Editors {
     public static final String SERVICE_RECORD = "~./editor/service-record-editor.zul";
     public static final String INCOMING_INVOICE = "~./editor/incoming-invoice-editor.zul";
@@ -21,11 +24,11 @@ public class Editors {
     public static final String INVOICE_PAYMENT = "~./invoice-payment.zul";
     public static final String POPUP_EDITOR = "~./editor/popup-editor.zul";
 
-    public static <E> void doEdit(String page, E entity, EditCompleted<E> editCompleted) {
+    public static <E> void doEdit(String page, E entity, EditCompletedListener<E> editCompleted) {
         doEdit(page, entity, null, editCompleted);
     }
 
-    public static <E> void doEdit(String page, E entity, E original, EditCompleted<E> editCompleted) {
+    public static <E> void doEdit(String page, E entity, E original, EditCompletedListener<E> editCompleted) {
         Map<String, Object> arg;
         if (Objects.isNull(entity)) {
             //header double click
@@ -41,14 +44,17 @@ public class Editors {
         doShowEdit(page, arg, editCompleted);
     }
 
-    public static <E> void doShowEdit(String page, Map<String, Object> arg, EditCompleted<E> editCompleted) {
+    public static <E> void doShowEdit(String page, Map<String, Object> arg, EditCompletedListener<E> editCompleted) {
         Window editorWindow = (Window) Executions.createComponents(page, null, arg);
         editorWindow.addEventListener("onClose", e -> {
-            if (e.getData() != null) {
-                editCompleted.done((E) e.getData());
+            if (e instanceof SaveEntityEvent) {
+                editCompleted.handle((SaveEntityEvent<E>) e);
+            } else {
+                log.error("Internal error! Expected event type is SaveEntityEvent");
             }
         });
         editorWindow.doModal();
         editorWindow.setFocus(true);
     }
+
 }
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java
new file mode 100644 (file)
index 0000000..5745676
--- /dev/null
@@ -0,0 +1,79 @@
+package hu.user.lis.ui.editor.common;
+
+import hu.user.lis.db.EDocument;
+import hu.user.lis.ui.data.EntityDocumentDataModel;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.extern.log4j.Log4j2;
+import org.zkoss.bind.BindContext;
+import org.zkoss.bind.BindUtils;
+import org.zkoss.bind.annotation.Command;
+import org.zkoss.bind.annotation.ContextParam;
+import org.zkoss.bind.annotation.ContextType;
+import org.zkoss.lang.Strings;
+import org.zkoss.zk.ui.event.UploadEvent;
+import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zul.Messagebox;
+
+import java.io.Serializable;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+@Log4j2
+public class EntityAttachmentEditorModel<T extends Serializable> extends EntityEditorModel<T> {
+
+    @Getter
+    @WireVariable
+    private EntityDocumentDataModel entityDocumentDataModel;
+
+    @Getter
+    @Setter
+    private EDocument selectedDocument;
+
+    protected boolean canSave(T entity) {
+        return true;
+    }
+
+    @Command
+    public void onUploadFile(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
+        UploadEvent evt = (UploadEvent) ctx.getTriggerEvent();
+        if (!evt.getMedia().getName().toLowerCase().endsWith(".pdf")) {
+            Messagebox.show("Csak PDF állomány feltöltése támogatott.", "Error", Messagebox.OK, Messagebox.ERROR);
+            return;
+        }
+        String documentType = Strings.EMPTY;
+        Type[] actualTypeArguments = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();
+        if (actualTypeArguments.length > 0) {
+            documentType = ((Class<?>) actualTypeArguments[0]).getSimpleName();
+        }
+        EDocument document = EDocument.builder()
+                .documentType(documentType)
+                .file(evt.getMedia().getByteData())
+                .size(evt.getMedia().getByteData().length)
+                .name(evt.getMedia().getName())
+                .build();
+        entityDocumentDataModel.addNew(document);
+        BindUtils.postNotifyChange(entityDocumentDataModel, "*");
+        validate();
+    }
+
+    @Command
+    public void onRemoveFile() {
+        entityDocumentDataModel.remove();
+        BindUtils.postNotifyChange(entityDocumentDataModel, "*");
+        validate();
+    }
+
+//    @Command
+//    public void onSelectFile(@BindingParam("selectedDocument") EDocument selectedDocument) {
+//        entityDocumentDataModel.clearSelection();
+//        entityDocumentDataModel.addToSelection(selectedDocument);
+//        entityDocumentDataModel.setSelectedDocument(selectedDocument);
+//    }
+
+    @Override
+    protected boolean areDifferent(T entity) {
+        return super.areDifferent(entity) || entityDocumentDataModel.isChanged();
+    }
+
+}
index 417fc2ca98f671b4abe81d48c4eb745609268d5b..0b0cb2f3ec64b3ad5501acb1f79aa61c7ab12a53 100644 (file)
@@ -3,7 +3,9 @@ package hu.user.lis.ui.editor.common;
 import hu.user.lis.service.data.EntityDataService;
 import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
 import hu.user.lis.ui.editor.validator.FormValidator;
+import hu.user.lis.ui.event.CancelEntityEditEvent;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.log4j.Log4j2;
@@ -62,10 +64,10 @@ public abstract class EntityEditorModel<T extends Serializable> extends Abstract
     public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("save") boolean save) {
         if (save) {
             if (saveEnabled) {
-                Events.postEvent(new Event("onClose", target, formDocument));
+                Events.postEvent(new SaveEntityEvent<>(formDocument, target));
             }
         } else {
-            Events.postEvent(new Event("onClose", target, null));
+            Events.postEvent(new CancelEntityEditEvent<>(target));
         }
     }
 
@@ -80,9 +82,7 @@ public abstract class EntityEditorModel<T extends Serializable> extends Abstract
         eventBus.registerForBinding(this);
         origDocument = (T) Executions.getCurrent().getArg().get("origDocument");
         formDocument = (T) Executions.getCurrent().getArg().get("formDocument");
-        if (Objects.nonNull(getFormValidator()) && Objects.nonNull(getFormDocument())) {
-            getFormValidator().validate(getFormDocument());
-        }
+        validate(formDocument);
     }
 
     @Override
@@ -98,7 +98,13 @@ public abstract class EntityEditorModel<T extends Serializable> extends Abstract
         }
     }
 
-    protected abstract boolean canSave(T entity);
+    protected boolean canSave(T entity) {
+        boolean result = false;
+        if (Objects.nonNull(getFormValidator())) {
+            getFormValidator().validate(entity);
+        }
+        return result;
+    }
 
     protected boolean areDifferent(T entity) {
         return entityDataService.areDifferent(origDocument, entity);
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/event/CancelEntityEditEvent.java b/lis-ui/src/main/java/hu/user/lis/ui/event/CancelEntityEditEvent.java
new file mode 100644 (file)
index 0000000..2eaba35
--- /dev/null
@@ -0,0 +1,12 @@
+package hu.user.lis.ui.event;
+
+import lombok.Getter;
+import org.zkoss.zul.Window;
+
+@Getter
+public class CancelEntityEditEvent<T> extends SaveEntityEvent<T> {
+
+    public CancelEntityEditEvent(Window target) {
+        super(null, target);
+    }
+}
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityEvent.java b/lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityEvent.java
new file mode 100644 (file)
index 0000000..bfe8f8a
--- /dev/null
@@ -0,0 +1,27 @@
+package hu.user.lis.ui.event;
+
+import org.zkoss.zk.ui.event.Event;
+import org.zkoss.zul.Window;
+
+public class SaveEntityEvent<T> extends Event {
+
+    public SaveEntityEvent(T data, Window target) {
+        super("onClose", target, data);
+    }
+
+    @Override
+    public T getData() {
+        return (T) super.getData();
+    }
+
+    public boolean isCanceled() {
+        return this instanceof CancelEntityEditEvent;
+    }
+
+    public SaveEntityWithAttachmentEvent<T> withAttachment() {
+        if (this instanceof SaveEntityWithAttachmentEvent) {
+            return (SaveEntityWithAttachmentEvent<T>) this;
+        }
+        return null;
+    }
+}
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityWithAttachmentEvent.java b/lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityWithAttachmentEvent.java
new file mode 100644 (file)
index 0000000..a526d63
--- /dev/null
@@ -0,0 +1,16 @@
+package hu.user.lis.ui.event;
+
+import hu.user.lis.ui.data.EntityDocumentDataModel;
+import lombok.Getter;
+import org.zkoss.zul.Window;
+
+@Getter
+public class SaveEntityWithAttachmentEvent<T> extends SaveEntityEvent<T> {
+
+    private final EntityDocumentDataModel entityDocumentDataModel;
+
+    public SaveEntityWithAttachmentEvent(T data, EntityDocumentDataModel entityDocumentDataModel, Window target) {
+        super(data, target);
+        this.entityDocumentDataModel = entityDocumentDataModel;
+    }
+}
index 8163e596cbee0421f4b6d98ca85030a8370617a3..5714f419a6cd7b32ccaade44f4f812450347f2da 100644 (file)
@@ -6,6 +6,7 @@ import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.AssociatesDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.FilterActiveViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
@@ -60,20 +61,22 @@ public class AssociatesViewModel extends FilterActiveViewModel<Associate> {
     @Command
     public void onAdd() {
         Associate entity = associatesDataModel.createNew();
-        Editors.doEdit(Editors.ASSOCIATE, entity, modifiedEntity -> {
-            associatesDataModel.save(modifiedEntity);
-            refresh();
-            associatesDataModel.addToSelection(modifiedEntity);
-        });
+        Editors.doEdit(Editors.ASSOCIATE, entity, this::saveAssociate);
     }
 
     @Command
     public void onEdit() {
         Associate entity = associatesDataModel.clone(getSelectedEntity());
-        Editors.doEdit(Editors.ASSOCIATE, entity, getSelectedEntity(), modifiedEntity -> {
+        Editors.doEdit(Editors.ASSOCIATE, entity, getSelectedEntity(), this::saveAssociate);
+    }
+
+    private void saveAssociate(SaveEntityEvent<Associate> event) {
+        if (!event.isCanceled()) {
+            Associate modifiedEntity = event.getData();
             associatesDataModel.save(modifiedEntity);
             refresh();
-        });
+            associatesDataModel.addToSelection(modifiedEntity);
+        }
     }
 
     @Command
index 4c76dbd41d76d510caa30156f0962c596003f65f..633309bd110057d6dfe5ec4a7fc77eb0d0b31aed 100644 (file)
@@ -12,6 +12,7 @@ import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.EntityViewModel;
 import hu.user.lis.workflow.invoice.service.WorkflowManagerService;
 import lombok.Getter;
@@ -144,19 +145,29 @@ public class ImportInvoicesSuspendedViewModel extends EntityViewModel<Invoice> i
     public void onEditIncoming() {
         IncomingInvoice selectedIncomingInvoice = (IncomingInvoice) getSelectedEntity();
         IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
-        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, modifiedEntity -> {
+        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::saveIncomingInvoice);
+    }
+
+    private void saveIncomingInvoice(SaveEntityEvent<IncomingInvoice> event) {
+        if (!event.isCanceled()) {
+            Invoice modifiedEntity = event.getData();
             invoiceDataModel.save(modifiedEntity);
             refresh();
-        });
+        }
     }
 
     public void onEditOutgoing() {
         OutgoingInvoice selectedOutgoingInvoice = (OutgoingInvoice) getSelectedEntity();
         OutgoingInvoice entity = invoiceDataModel.clone((OutgoingInvoice) getSelectedEntity());
-        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, modifiedEntity -> {
+        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::saveOutgoingInvoice);
+    }
+
+    private void saveOutgoingInvoice(SaveEntityEvent<OutgoingInvoice> event) {
+        if (!event.isCanceled()) {
+            Invoice modifiedEntity = event.getData();
             invoiceDataModel.save(modifiedEntity);
             refresh();
-        });
+        }
     }
 
     @Command
index 71d13e2e0a9411c4f97f584fc141ccb7b7794022..7b3480d626ab148d3db5491b98a0d120e796c9b6 100644 (file)
@@ -11,6 +11,7 @@ import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.EntityViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
@@ -140,31 +141,43 @@ public class InvoicesViewModel extends EntityViewModel<Invoice> implements Event
     public void onEditIncoming() {
         IncomingInvoice selectedIncomingInvoice = (IncomingInvoice) getSelectedEntity();
         IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
-        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, modifiedEntity -> {
+        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::saveIncomingInvoice);
+    }
+
+    private void saveIncomingInvoice(SaveEntityEvent<IncomingInvoice> event) {
+        if (!event.isCanceled()) {
+            Invoice modifiedEntity = event.getData();
             invoiceDataModel.save(modifiedEntity);
             refresh();
-        });
+        }
     }
 
     public void onEditOutgoing() {
         OutgoingInvoice selectedOutgoingInvoice = (OutgoingInvoice) getSelectedEntity();
         OutgoingInvoice entity = invoiceDataModel.clone((OutgoingInvoice) getSelectedEntity());
-        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, modifiedEntity -> {
+        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::saveOutgoingInvoice);
+    }
+
+    private void saveOutgoingInvoice(SaveEntityEvent<OutgoingInvoice> event) {
+        if (!event.isCanceled()) {
+            Invoice modifiedEntity = event.getData();
             invoiceDataModel.save(modifiedEntity);
             refresh();
-        });
+        }
     }
 
     @Command
     public void onChangeProject() {
-        Editors.doEdit(Editors.PROJECT_ATTACH, getSelectedEntity().getProject(), null, modifiedEntity -> {
-            if (modifiedEntity != null) {
-                getSelectedEntity().setProject(modifiedEntity);
-                invoiceDataModel.save(getSelectedEntity());
-                refresh();
-            }
-        });
+        Editors.doEdit(Editors.PROJECT_ATTACH, getSelectedEntity().getProject(), null, this::attachProject);
+    }
 
+    private void attachProject(SaveEntityEvent<Project> event) {
+        if (!event.isCanceled()) {
+            Project modifiedEntity = event.getData();
+            getSelectedEntity().setProject(modifiedEntity);
+            invoiceDataModel.save(getSelectedEntity());
+            refresh();
+        }
     }
 
     @Command
index 97ca9975cb9421e3d7a46add983d150295209b02..0b273bcbfa48b5a5a9682d83df57bec4b76f492f 100644 (file)
@@ -6,6 +6,7 @@ import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.PartnersDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.FilterActiveViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
@@ -59,20 +60,22 @@ public class PartnersViewModel extends FilterActiveViewModel<Partner> {
     @Command
     public void onAdd() {
         Partner entity = partnersDataModel.createNew();
-        Editors.doEdit(Editors.PARTNER, entity, modifiedEntity -> {
-            partnersDataModel.save(modifiedEntity);
-            refresh();
-            partnersDataModel.addToSelection(modifiedEntity);
-        });
+        Editors.doEdit(Editors.PARTNER, entity, this::savePartner);
     }
 
     @Command
     public void onEdit() {
         Partner entity = partnersDataModel.clone(getSelectedEntity());
-        Editors.doEdit(Editors.PARTNER, entity, getSelectedEntity(), modifiedEntity -> {
+        Editors.doEdit(Editors.PARTNER, entity, getSelectedEntity(), this::savePartner);
+    }
+
+    private void savePartner(SaveEntityEvent<Partner> event) {
+        if (!event.isCanceled()) {
+            Partner modifiedEntity = event.getData();
             partnersDataModel.save(modifiedEntity);
             refresh();
-        });
+            partnersDataModel.addToSelection(modifiedEntity);
+        }
     }
 
     @Command
index 7ae3f6f5a4ae6841d4b7253c2fdfecaf65912be3..9509cabd7d9b2e1544099ee04f06ec7341e87eda 100644 (file)
@@ -6,6 +6,7 @@ import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.ProjectsDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.FilterActiveViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
@@ -58,6 +59,10 @@ public class ProjectsViewModel extends FilterActiveViewModel<Project> implements
         ));
     }
 
+    public void saveEntity(SaveEntityEvent<Project> event) {
+
+    }
+
     protected void refresh() {
         projectsDataModel.clearSelection();
         setSelectedEntity(null);
index 82dd620e5d8e6d44da089b024798b0c38d208635..c82bd699cfe5254e0dc98194ea49e95279bb3a18 100644 (file)
@@ -5,11 +5,13 @@ import hu.user.lis.db.Associate;
 import hu.user.lis.db.Project;
 import hu.user.lis.db.ServiceRecord;
 import hu.user.lis.ui.Constants;
+import hu.user.lis.ui.data.EntityDocumentDataModel;
 import hu.user.lis.ui.data.ServiceRecordsDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.EntityViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
@@ -98,20 +100,24 @@ public class ServiceRecordsViewModel extends EntityViewModel<ServiceRecord> impl
     @Command
     public void onAdd() {
         ServiceRecord entity = serviceRecordsDataModel.createNew();
-        Editors.doEdit(Editors.SERVICE_RECORD, entity, modifiedEntity -> {
-            serviceRecordsDataModel.save(modifiedEntity);
-            refresh();
-            serviceRecordsDataModel.addToSelection(modifiedEntity);
-        });
+        Editors.doEdit(Editors.SERVICE_RECORD, entity, this::saveServiceRecord);
     }
 
     @Command
     public void onEdit() {
         ServiceRecord entity = serviceRecordsDataModel.clone(getSelectedEntity());
-        Editors.doEdit(Editors.SERVICE_RECORD, entity, getSelectedEntity(), modifiedEntity -> {
+        Editors.doEdit(Editors.SERVICE_RECORD, entity, getSelectedEntity(), this::saveServiceRecord);
+    }
+
+    public void saveServiceRecord(SaveEntityEvent<ServiceRecord> event) {
+        if (!event.isCanceled()) {
+            ServiceRecord modifiedEntity = event.getData();
             serviceRecordsDataModel.save(modifiedEntity);
+            EntityDocumentDataModel entityDocumentDataModel = event.withAttachment().getEntityDocumentDataModel();
+            entityDocumentDataModel.save(modifiedEntity.getId());
             refresh();
-        });
+            serviceRecordsDataModel.addToSelection(modifiedEntity);
+        }
     }
 
     @Command
index 775ee4024014061bcdc9f772c7d411e0fb785898..b2c4e9b2a8a7586c6126d580f0a7be955de46095 100644 (file)
                             </vlayout>
                         </tabpanel>
                         <tabpanel>
-                            <borderlayout>
-                                <north flex="true">
-                                    <toolbar>
-                                        <toolbarbutton label="Feltöltés" iconSclass="z-icon-plus" upload="true"
-                                                       onUpload="@command('onUploadFile')"/>
-                                        <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
-                                                       onClick="@command('onRemoveFile')"
-                                                       disabled="@load(empty vm.formDocument.file)"/>
-                                    </toolbar>
-                                </north>
-                                <center border="none" flex="true">
-                                    <iframe hflex="true" vflex="true"
-                                            content="@load(vm.formDocument.file) @converter('hu.user.lis.ui.converter.ByteArrayToAMediaConverter')"/>
-                                </center>
-                            </borderlayout>
+                            <include src="~./form/attachment-form.zul" hflex="true" vflex="true"/>
                         </tabpanel>
                     </tabpanels>
                 </tabbox>
diff --git a/lis-ui/src/main/resources/web/form/attachment-form.zul b/lis-ui/src/main/resources/web/form/attachment-form.zul
new file mode 100644 (file)
index 0000000..e99d831
--- /dev/null
@@ -0,0 +1,33 @@
+<zk>
+    <borderlayout>
+        <north flex="true">
+            <toolbar>
+                <toolbarbutton label="Feltöltés" iconSclass="z-icon-plus" upload="true"
+                               onUpload="@command('onUploadFile')"/>
+                <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
+                               onClick="@command('onRemoveFile')"
+                               disabled="@load(empty vm.selectedDocument)"/>
+            </toolbar>
+        </north>
+        <west title="Fájlok" size="25%" flex="true" border="none" splittable="true" collapsible="true">
+            <listbox vflex="true" hflex="true" model="@load(vm.entityDocumentDataModel)" multiple="false"
+                     sizedByContent="true" selectedItem="@bind(vm.selectedDocument)">
+                <listhead visible="false">
+                    <listheader hflex="true"/>
+                </listhead>
+                <template name="model">
+                    <listitem>
+                        <listcell>
+                            <button iconSclass="z-icon-file-pdf-o"/>
+                            <label value="@load(each.name)"/>
+                        </listcell>
+                    </listitem>
+                </template>
+            </listbox>
+        </west>
+        <center border="none" hflex="true" vflex="true">
+            <iframe hflex="true" vflex="true"
+                    content="@load(vm.selectedDocument.file) @converter('hu.user.lis.ui.converter.ByteArrayToAMediaConverter')"/>
+        </center>
+    </borderlayout>
+</zk>
\ No newline at end of file