Author: echatellier Date: 2013-02-13 16:03:01 +0100 (Wed, 13 Feb 2013) New Revision: 104 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/104 Log: refs #1653: Add a linked document refs #1654: Consult linked document metadata refs #1656: Manage documents at info level refs #1657: Display documents at info level refs #1658: Display documents at lists level Added: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Document.java trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java trunk/cantharella.data/src/test/resources/log4j.xml trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/DocumentNormalizer.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.html trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.html trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.java trunk/cantharella.web/src/main/webapp/images/attachment.png Removed: trunk/cantharella.data/src/test/resources/log4j.xml Modified: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Molecule.java trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/MoleculeProvenance.java trunk/cantharella.data/src/main/resources/data_en.properties trunk/cantharella.data/src/main/resources/data_fr.properties trunk/cantharella.data/src/main/resources/sql/dev_update.sql trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/MoleculeServiceImpl.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/config/WebApplicationImpl.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/lot/ManageLotPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java trunk/cantharella.web/src/main/resources/web_en.properties trunk/cantharella.web/src/main/resources/web_fr.properties Added: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Document.java =================================================================== --- trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Document.java (rev 0) +++ trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Document.java 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,219 @@ +/* + * #%L + * Cantharella :: Data + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package nc.ird.cantharella.data.model; + +import java.io.InputStream; +import java.util.Date; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.validation.constraints.NotNull; + +import nc.ird.cantharella.data.model.utils.AbstractModel; +import nc.ird.cantharella.data.validation.CountryCode; + +import org.hibernate.annotations.Type; +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.NotEmpty; + +/** + * Document entity. + * + * @author Eric Chatellier + */ +@Entity +public class Document extends AbstractModel { + + /** Id du document. */ + @Id + @GeneratedValue + private Integer idDocument; + + /** Titre. */ + @Length(max = LENGTH_LONG_TEXT) + @NotEmpty + private String titre; + + /** Createur. */ + @NotNull + @ManyToOne(fetch = FetchType.LAZY, optional = false) + private Personne createur; + + /** Date de creation. */ + @NotNull + private Date dateCreation; + + /** Editeur. */ + @Length(max = LENGTH_LONG_TEXT) + @NotEmpty + private String editeur; + + /** Description. */ + @Lob + @Type(type="org.hibernate.type.StringClobType") // see HHH-6105 + private String description; + + /** Langue. */ + @Length(min = 2, max = 2) + @CountryCode + private String langue; + + /** Contrainte légale. */ + @Length(max = LENGTH_LONG_TEXT) + private String contrainteLegale; + + /** Ajouté par. */ + @NotNull + @ManyToOne(fetch = FetchType.LAZY, optional = false) + private Personne ajoutePar; + + /** Type document. */ + @NotNull + @ManyToOne(fetch = FetchType.LAZY, optional = false) + private TypeDocument typeDocument; + + /** File name. */ + @NotEmpty + @Length(max = LENGTH_MEDIUM_TEXT) + private String fileName; + + /* File data. + @Lob + @Basic(fetch=FetchType.LAZY, optional=true) + private byte[] fileContent;*/ + + /** File mime type. */ + @NotEmpty + @Length(max = LENGTH_MEDIUM_TEXT) + private String fileMimetype; + + public Integer getIdDocument() { + return idDocument; + } + + public void setIdDocument(Integer idDocument) { + this.idDocument = idDocument; + } + + public String getTitre() { + return titre; + } + + public void setTitre(String titre) { + this.titre = titre; + } + + public Personne getCreateur() { + return createur; + } + + public void setCreateur(Personne createur) { + this.createur = createur; + } + + public Date getDateCreation() { + return dateCreation; + } + + public void setDateCreation(Date dateCreation) { + this.dateCreation = dateCreation; + } + + public String getEditeur() { + return editeur; + } + + public void setEditeur(String editeur) { + this.editeur = editeur; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getLangue() { + return langue; + } + + public void setLangue(String langue) { + this.langue = langue; + } + + public String getContrainteLegale() { + return contrainteLegale; + } + + public void setContrainteLegale(String contrainteLegale) { + this.contrainteLegale = contrainteLegale; + } + + public Personne getAjoutePar() { + return ajoutePar; + } + + public void setAjoutePar(Personne ajoutePar) { + this.ajoutePar = ajoutePar; + } + + public TypeDocument getTypeDocument() { + return typeDocument; + } + + public void setTypeDocument(TypeDocument typeDocument) { + this.typeDocument = typeDocument; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + /*public byte[] getFileContent() { + return fileContent; + } + + public void setFileContent(byte[] fileContent) { + this.fileContent = fileContent; + }*/ + + public String getFileMimetype() { + return fileMimetype; + } + + public void setFileMimetype(String fileMimetype) { + this.fileMimetype = fileMimetype; + } +} Property changes on: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Document.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Molecule.java =================================================================== --- trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Molecule.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/Molecule.java 2013-02-13 15:03:01 UTC (rev 104) @@ -30,6 +30,7 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.Lob; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -41,6 +42,7 @@ import nc.ird.cantharella.data.config.DataContext; import nc.ird.cantharella.data.model.search.UtilisateurSearchFilter; import nc.ird.cantharella.data.model.utils.AbstractModel; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; @@ -66,7 +68,7 @@ @FullTextFilterDefs( { @FullTextFilterDef(name = "utilisateur-Molecule", impl = UtilisateurSearchFilter.class) }) -public class Molecule extends AbstractModel { +public class Molecule extends AbstractModel implements DocumentAttachable { /** ID */ @Id @@ -134,11 +136,17 @@ @IndexedEmbedded private Personne createur; - /** Produit utilisé obtenir le résultat **/ + /** Produit utilisé obtenir le résultat */ @OneToMany(mappedBy = "molecule", fetch = FetchType.LAZY, orphanRemoval = true) @Cascade({ CascadeType.SAVE_UPDATE }) private List<MoleculeProvenance> provenances; + /** Liste des documents attachés. */ + @OneToMany(fetch = FetchType.LAZY, orphanRemoval = true) + @JoinColumn(name="molecule") + @Cascade({ CascadeType.SAVE_UPDATE }) + private List<Document> documents; + /** * Id molecule getter. * @@ -390,4 +398,30 @@ public void setProvenances(List<MoleculeProvenance> provenances) { this.provenances = provenances; } + + /** {@inheritDoc} */ + public List<Document> getDocuments() { + return documents; + } + + /** + * Documents setter. + * + * @param documents the documents to set + */ + public void setDocuments(List<Document> documents) { + this.documents = documents; + } + + /** {@inheritDoc} */ + @Override + public void addDocument(Document document) { + documents.add(document); + } + + /** {@inheritDoc} */ + @Override + public void removeDocument(Document document) { + documents.remove(document); + } } Modified: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/MoleculeProvenance.java =================================================================== --- trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/MoleculeProvenance.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/MoleculeProvenance.java 2013-02-13 15:03:01 UTC (rev 104) @@ -38,7 +38,7 @@ import nc.ird.cantharella.data.model.utils.AbstractModel; /** - * MoleculeProvenance association entity between {@link Molecule} and {@Produit}. + * MoleculeProvenance association entity between {@link Molecule} and {@link Produit}. * * @author Eric Chatellier */ Added: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java =================================================================== --- trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java (rev 0) +++ trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,53 @@ +/* + * #%L + * Cantharella :: Data + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package nc.ird.cantharella.data.model.utils; + +import java.util.List; + +import nc.ird.cantharella.data.model.Document; + +/** + * Interface to mark entity on which documents can be attached. + * + * @author Eric Chatellier + */ +public interface DocumentAttachable { + + /** + * Get document attached to entity. + * @return document list + */ + List<Document> getDocuments(); + + /** + * Attach new document. + * @param document new document to attach + */ + void addDocument(Document document); + + /** + * Remove an attached document. + * @param document document to remove + */ + void removeDocument(Document document); +} Property changes on: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/cantharella.data/src/main/resources/data_en.properties =================================================================== --- trunk/cantharella.data/src/main/resources/data_en.properties 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.data/src/main/resources/data_en.properties 2013-02-13 15:03:01 UTC (rev 104) @@ -244,6 +244,22 @@ ErreurTestBio.nom=Name ErreurTestBio.description=Description +TypeDocument.nom=Nom +TypeDocument.domaine=Domaine +TypeDocument.description=Description + +Document.titre=Titre +Document.createur=Créateur +Document.dateCreation=Date de création +Document.editeur=Éditeur +Document.description=Description +Document.langue=Langue +Document.contrainteLegale=Contrainte légale +Document.ajoutePar=Ajouté par +Document.typeDocument=Type +Document.fileName=Nom +Document.fileMimetype=Format + #Internationalisation des enums# TypeDroit.ADMINISTRATEUR=Administrator TypeDroit.UTILISATEUR=User Modified: trunk/cantharella.data/src/main/resources/data_fr.properties =================================================================== --- trunk/cantharella.data/src/main/resources/data_fr.properties 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.data/src/main/resources/data_fr.properties 2013-02-13 15:03:01 UTC (rev 104) @@ -243,6 +243,23 @@ ErreurTestBio.nom=Nom ErreurTestBio.description=Description +TypeDocument.nom=Nom +TypeDocument.domaine=Domaine +TypeDocument.description=Description + +Document.titre=Titre +Document.createur=Créateur +Document.dateCreation=Date de création +Document.editeur=Éditeur +Document.description=Description +Document.langue=Langue +Document.contrainteLegale=Contrainte légale +Document.ajoutePar=Ajouté par +Document.typeDocument=Type +Document.fileName=Nom +Document.fileMimetype=Format + + #Internationalisation des enums# TypeDroit.ADMINISTRATEUR=Administrateur TypeDroit.UTILISATEUR=Utilisateur Modified: trunk/cantharella.data/src/main/resources/sql/dev_update.sql =================================================================== --- trunk/cantharella.data/src/main/resources/sql/dev_update.sql 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.data/src/main/resources/sql/dev_update.sql 2013-02-13 15:03:01 UTC (rev 104) @@ -83,5 +83,43 @@ references Produit; create sequence molecule_sequence; - + +-- Document (12/02/2013) + create table Document ( + idDocument int4 not null, + contrainteLegale varchar(100), + dateCreation timestamp not null, + description text, + editeur varchar(100) not null, + fileContent oid, + fileMimetype varchar(60) not null, + fileName varchar(60) not null, + langue varchar(2), + titre varchar(100) not null, + ajoutePar_idPersonne int4 not null, + createur_idPersonne int4 not null, + typeDocument_idTypeDocument int4 not null, + molecule int4, + primary key (idDocument) + ); + + alter table Document + add constraint FK3737353B2F46DB31 + foreign key (ajoutePar_idPersonne) + references Personne; + + alter table Document + add constraint FK3737353B822055B9 + foreign key (createur_idPersonne) + references Personne; + + alter table Document + add constraint FK3737353BBECBA92F + foreign key (typeDocument_idTypeDocument) + references TypeDocument; + + alter table Document + add constraint FK3737353B20FEEDAC + foreign key (molecule) + references Molecule; COMMIT; \ No newline at end of file Deleted: trunk/cantharella.data/src/test/resources/log4j.xml =================================================================== (Binary files differ) Copied: trunk/cantharella.data/src/test/resources/log4j.xml (from rev 58, trunk/cantharella.data/src/test/resources/log4j.xml) =================================================================== (Binary files differ) Modified: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java 2013-02-13 15:03:01 UTC (rev 104) @@ -26,7 +26,10 @@ import nc.ird.cantharella.data.exceptions.DataConstraintException; import nc.ird.cantharella.data.exceptions.DataNotFoundException; +import nc.ird.cantharella.data.model.Document; import nc.ird.cantharella.data.model.TypeDocument; +import nc.ird.cantharella.data.model.Utilisateur; +import nc.ird.cantharella.service.utils.normalizers.DocumentNormalizer; import nc.ird.cantharella.service.utils.normalizers.TypeDocumentNormalizer; import nc.ird.cantharella.service.utils.normalizers.UniqueFieldNormalizer; import nc.ird.cantharella.service.utils.normalizers.utils.Normalize; @@ -85,4 +88,21 @@ */ void deleteTypeDocument(TypeDocument typeDocument) throws DataConstraintException; + /** + * Load a document. + * + * @param idDocument id + * @return the corresponding document + * @throws DataNotFoundException if not found + */ + Document loadDocument(Integer idDocument) throws DataNotFoundException; + + /** + * Check if a user can update or delete a document. + * @param document document + * @param utilisateur Utilisateur + * @return TRUE si il a le droit + */ + boolean updateOrdeleteDocumentEnabled(Document document, Utilisateur utilisateur); + } Modified: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java 2013-02-13 15:03:01 UTC (rev 104) @@ -28,7 +28,9 @@ import nc.ird.cantharella.data.exceptions.DataConstraintException; import nc.ird.cantharella.data.exceptions.DataNotFoundException; import nc.ird.cantharella.data.exceptions.UnexpectedException; +import nc.ird.cantharella.data.model.Document; import nc.ird.cantharella.data.model.TypeDocument; +import nc.ird.cantharella.data.model.Utilisateur; import nc.ird.cantharella.service.services.DocumentService; import nc.ird.module.utils.AssertTools; @@ -100,4 +102,17 @@ throw new UnexpectedException(e); } } + + /** {@inheritDoc} */ + @Override + public Document loadDocument(Integer idDocument) throws DataNotFoundException { + + return null; + } + + /** {@inheritDoc} */ + @Override + public boolean updateOrdeleteDocumentEnabled(Document document, Utilisateur utilisateur) { + return false; + } } Modified: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/MoleculeServiceImpl.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/MoleculeServiceImpl.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/MoleculeServiceImpl.java 2013-02-13 15:03:01 UTC (rev 104) @@ -38,7 +38,6 @@ import nc.ird.cantharella.data.model.Produit; import nc.ird.cantharella.data.model.Utilisateur; import nc.ird.cantharella.data.model.Utilisateur.TypeDroit; -import nc.ird.cantharella.data.model.utils.AbstractModel; import nc.ird.cantharella.service.model.MoleculeProvenanceBean; import nc.ird.cantharella.service.services.LotService; import nc.ird.cantharella.service.services.MoleculeService; Added: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/DocumentNormalizer.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/DocumentNormalizer.java (rev 0) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/DocumentNormalizer.java 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,43 @@ +/* + * #%L + * Cantharella :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package nc.ird.cantharella.service.utils.normalizers; + +import nc.ird.cantharella.data.model.Document; +import nc.ird.cantharella.service.utils.normalizers.utils.Normalizer; +import nc.ird.module.utils.AssertTools; + +/** + * Document normalizer + * @author Eric Chatellier + */ +public final class DocumentNormalizer extends Normalizer<Document> { + + /** {@inheritDoc} */ + @Override + protected Document normalize(Document document) { + AssertTools.assertNotNull(document); + // Unique field + document.setTitre(Normalizer.normalize(ConfigNameNormalizer.class, document.getTitre())); + return document; + } +} Property changes on: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/DocumentNormalizer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/config/WebApplicationImpl.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/config/WebApplicationImpl.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/config/WebApplicationImpl.java 2013-02-13 15:03:01 UTC (rev 104) @@ -22,81 +22,83 @@ */ package nc.ird.cantharella.web.config; -import java.math.BigDecimal; - -import nc.ird.cantharella.data.config.DataContext; -import nc.ird.cantharella.data.exceptions.DataConstraintException; -import nc.ird.cantharella.data.exceptions.UnexpectedException; -import nc.ird.cantharella.service.services.PersonneService; -import nc.ird.cantharella.web.pages.ContactPage; -import nc.ird.cantharella.web.pages.HomePage; -import nc.ird.cantharella.web.pages.domain.campagne.ListCampagnesPage; -import nc.ird.cantharella.web.pages.domain.campagne.ManageCampagnePage; -import nc.ird.cantharella.web.pages.domain.campagne.ReadCampagnePage; -import nc.ird.cantharella.web.pages.domain.config.ListConfigurationPage; -import nc.ird.cantharella.web.pages.domain.extraction.ListExtractionsPage; -import nc.ird.cantharella.web.pages.domain.extraction.ManageExtractionPage; -import nc.ird.cantharella.web.pages.domain.extraction.ReadExtractionPage; -import nc.ird.cantharella.web.pages.domain.lot.ListLotsPage; -import nc.ird.cantharella.web.pages.domain.lot.ManageLotPage; -import nc.ird.cantharella.web.pages.domain.lot.ReadLotPage; +import java.math.BigDecimal; + +import nc.ird.cantharella.data.config.DataContext; +import nc.ird.cantharella.data.exceptions.DataConstraintException; +import nc.ird.cantharella.data.exceptions.UnexpectedException; +import nc.ird.cantharella.service.services.PersonneService; +import nc.ird.cantharella.web.pages.ContactPage; +import nc.ird.cantharella.web.pages.HomePage; +import nc.ird.cantharella.web.pages.domain.campagne.ListCampagnesPage; +import nc.ird.cantharella.web.pages.domain.campagne.ManageCampagnePage; +import nc.ird.cantharella.web.pages.domain.campagne.ReadCampagnePage; +import nc.ird.cantharella.web.pages.domain.config.ListConfigurationPage; +import nc.ird.cantharella.web.pages.domain.document.ManageDocumentPage; +import nc.ird.cantharella.web.pages.domain.document.ReadDocumentPage; +import nc.ird.cantharella.web.pages.domain.extraction.ListExtractionsPage; +import nc.ird.cantharella.web.pages.domain.extraction.ManageExtractionPage; +import nc.ird.cantharella.web.pages.domain.extraction.ReadExtractionPage; +import nc.ird.cantharella.web.pages.domain.lot.ListLotsPage; +import nc.ird.cantharella.web.pages.domain.lot.ManageLotPage; +import nc.ird.cantharella.web.pages.domain.lot.ReadLotPage; import nc.ird.cantharella.web.pages.domain.molecule.ListMoleculesPage; import nc.ird.cantharella.web.pages.domain.molecule.ManageMoleculePage; import nc.ird.cantharella.web.pages.domain.molecule.ReadMoleculePage; -import nc.ird.cantharella.web.pages.domain.personne.ListPersonnesPage; -import nc.ird.cantharella.web.pages.domain.personne.ManagePersonnePage; -import nc.ird.cantharella.web.pages.domain.personne.ReadPersonnePage; -import nc.ird.cantharella.web.pages.domain.purification.ListPurificationsPage; -import nc.ird.cantharella.web.pages.domain.purification.ManagePurificationPage; -import nc.ird.cantharella.web.pages.domain.purification.ReadPurificationPage; +import nc.ird.cantharella.web.pages.domain.personne.ListPersonnesPage; +import nc.ird.cantharella.web.pages.domain.personne.ManagePersonnePage; +import nc.ird.cantharella.web.pages.domain.personne.ReadPersonnePage; +import nc.ird.cantharella.web.pages.domain.purification.ListPurificationsPage; +import nc.ird.cantharella.web.pages.domain.purification.ManagePurificationPage; +import nc.ird.cantharella.web.pages.domain.purification.ReadPurificationPage; import nc.ird.cantharella.web.pages.domain.search.SearchPage; -import nc.ird.cantharella.web.pages.domain.specimen.ListSpecimensPage; -import nc.ird.cantharella.web.pages.domain.specimen.ManageSpecimenPage; -import nc.ird.cantharella.web.pages.domain.specimen.ReadSpecimenPage; -import nc.ird.cantharella.web.pages.domain.station.ListStationsPage; -import nc.ird.cantharella.web.pages.domain.station.ManageStationPage; -import nc.ird.cantharella.web.pages.domain.station.ReadStationPage; -import nc.ird.cantharella.web.pages.domain.testBio.ListTestsBioPage; -import nc.ird.cantharella.web.pages.domain.testBio.ManageTestBioPage; -import nc.ird.cantharella.web.pages.domain.testBio.ReadTestBioPage; -import nc.ird.cantharella.web.pages.domain.utilisateur.ManageUtilisateurPage; -import nc.ird.cantharella.web.pages.domain.utilisateur.RegisterPage; -import nc.ird.cantharella.web.pages.domain.utilisateur.ResetPasswordPage; -import nc.ird.cantharella.web.pages.domain.utilisateur.UpdateUtilisateurPage; -import nc.ird.cantharella.web.pages.errors.AccessDeniedPage; -import nc.ird.cantharella.web.pages.errors.InternalErrorPage; -import nc.ird.cantharella.web.pages.errors.PageExpiredErrorPage; -import nc.ird.cantharella.web.utils.converters.BigDecimalConverterImpl; -import nc.ird.cantharella.web.utils.converters.DoubleConverterImpl; -import nc.ird.cantharella.web.utils.security.AuthSession; -import nc.ird.cantharella.web.utils.security.AuthStrategy; -import nc.ird.module.utils.AssertTools; - +import nc.ird.cantharella.web.pages.domain.specimen.ListSpecimensPage; +import nc.ird.cantharella.web.pages.domain.specimen.ManageSpecimenPage; +import nc.ird.cantharella.web.pages.domain.specimen.ReadSpecimenPage; +import nc.ird.cantharella.web.pages.domain.station.ListStationsPage; +import nc.ird.cantharella.web.pages.domain.station.ManageStationPage; +import nc.ird.cantharella.web.pages.domain.station.ReadStationPage; +import nc.ird.cantharella.web.pages.domain.testBio.ListTestsBioPage; +import nc.ird.cantharella.web.pages.domain.testBio.ManageTestBioPage; +import nc.ird.cantharella.web.pages.domain.testBio.ReadTestBioPage; +import nc.ird.cantharella.web.pages.domain.utilisateur.ManageUtilisateurPage; +import nc.ird.cantharella.web.pages.domain.utilisateur.RegisterPage; +import nc.ird.cantharella.web.pages.domain.utilisateur.ResetPasswordPage; +import nc.ird.cantharella.web.pages.domain.utilisateur.UpdateUtilisateurPage; +import nc.ird.cantharella.web.pages.errors.AccessDeniedPage; +import nc.ird.cantharella.web.pages.errors.InternalErrorPage; +import nc.ird.cantharella.web.pages.errors.PageExpiredErrorPage; +import nc.ird.cantharella.web.utils.converters.BigDecimalConverterImpl; +import nc.ird.cantharella.web.utils.converters.DoubleConverterImpl; +import nc.ird.cantharella.web.utils.security.AuthSession; +import nc.ird.cantharella.web.utils.security.AuthStrategy; +import nc.ird.module.utils.AssertTools; + +import org.apache.wicket.ConverterLocator; +import org.apache.wicket.IConverterLocator; +import org.apache.wicket.RuntimeConfigurationType; +import org.apache.wicket.Session; +import org.apache.wicket.authentication.IAuthenticationStrategy; +import org.apache.wicket.authentication.strategy.DefaultAuthenticationStrategy; +import org.apache.wicket.injection.Injector; +import org.apache.wicket.javascript.DefaultJavaScriptCompressor; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.request.Request; +import org.apache.wicket.request.Response; +import org.apache.wicket.request.mapper.MountedMapper; +import org.apache.wicket.request.mapper.PackageMapper; +import org.apache.wicket.request.mapper.mount.MountMapper; +import org.apache.wicket.resource.NoOpTextCompressor; +import org.apache.wicket.resource.loader.IStringResourceLoader; +import org.apache.wicket.settings.IExceptionSettings; +import org.apache.wicket.settings.IRequestCycleSettings.RenderStrategy; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.spring.injection.annot.SpringComponentInjector; +import org.apache.wicket.util.cookies.CookieUtils; +import org.apache.wicket.util.lang.PackageName; +import org.apache.wicket.util.time.Duration; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.wicket.ConverterLocator; -import org.apache.wicket.IConverterLocator; -import org.apache.wicket.RuntimeConfigurationType; -import org.apache.wicket.Session; -import org.apache.wicket.authentication.IAuthenticationStrategy; -import org.apache.wicket.authentication.strategy.DefaultAuthenticationStrategy; -import org.apache.wicket.injection.Injector; -import org.apache.wicket.javascript.DefaultJavaScriptCompressor; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.request.Request; -import org.apache.wicket.request.Response; -import org.apache.wicket.request.mapper.MountedMapper; -import org.apache.wicket.request.mapper.PackageMapper; -import org.apache.wicket.request.mapper.mount.MountMapper; -import org.apache.wicket.resource.NoOpTextCompressor; -import org.apache.wicket.resource.loader.IStringResourceLoader; -import org.apache.wicket.settings.IExceptionSettings; -import org.apache.wicket.settings.IRequestCycleSettings.RenderStrategy; -import org.apache.wicket.spring.injection.annot.SpringBean; -import org.apache.wicket.spring.injection.annot.SpringComponentInjector; -import org.apache.wicket.util.cookies.CookieUtils; -import org.apache.wicket.util.lang.PackageName; -import org.apache.wicket.util.time.Duration; +import org.slf4j.LoggerFactory; /** * Web application @@ -385,7 +387,7 @@ mountPage("/station/edit", ManageStationPage.class); getRootRequestMapperAsCompound().add(new MountedMapper("/station/view", ReadStationPage.class)); mountPage("/station/view", ReadStationPage.class); - + getRootRequestMapperAsCompound().add(new MountedMapper("/molecule/list", ListMoleculesPage.class)); mountPage("/molecule/list", ListMoleculesPage.class); getRootRequestMapperAsCompound().add(new MountedMapper("/molecule/edit", ManageMoleculePage.class)); @@ -398,7 +400,12 @@ getRootRequestMapperAsCompound().add(new MountedMapper("/testBio/edit", ManageTestBioPage.class)); mountPage("/testBio/edit", ManageTestBioPage.class); getRootRequestMapperAsCompound().add(new MountedMapper("/testBio/view", ReadTestBioPage.class)); - mountPage("/testBio/view", ReadTestBioPage.class); + mountPage("/testBio/view", ReadTestBioPage.class); + + getRootRequestMapperAsCompound().add(new MountedMapper("/document/edit", ManageDocumentPage.class)); + mountPage("/document/edit", ManageDocumentPage.class); + getRootRequestMapperAsCompound().add(new MountedMapper("/document/view", ReadDocumentPage.class)); + mountPage("/document/view", ReadDocumentPage.class); getRootRequestMapperAsCompound().add(new MountedMapper("/utilisateur/edit", ManageUtilisateurPage.class)); mountPage("/utilisateur/edit", ManageUtilisateurPage.class); Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.html (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.html 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,102 @@ +<!-- + #%L + Cantharella :: Web + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"> +<body> +<wicket:extend> + + <form wicket:id="ManageDocumentPage.Form"> + + <div class="property required"> + <label for="Document.titre"><wicket:message key="Document.titre" /></label> + <input type="text" id="Document.titre" wicket:id="Document.titre" /> + </div> + + <div class="property required"> + <label for="Document.createur"><wicket:message key="Document.createur" /></label> + <select id="Document.createur" wicket:id="Document.createur" /> + <a wicket:id="NewPersonne" class="add"><wicket:message key="ListPersonnesPage.NewPersonne" /></a> + </div> + + <div class="property required"> + <label for="Document.dateCreation"><wicket:message key="Document.dateCreation" /></label> + <input type="text" id="Document.dateCreation" wicket:id="Document.dateCreation" /> + </div> + + <div class="property required"> + <label for="Document.editeur"><wicket:message key="Document.editeur" /></label> + <input type="text" id="Document.editeur" wicket:id="Document.editeur" /> + </div> + + <div class="property"> + <label for="Document.description"><wicket:message key="Document.description" /></label> + <textarea id="Document.description" wicket:id="Document.description"></textarea> + </div> + + <div class="property"> + <label for="Document.langue"><wicket:message key="Document.langue" /></label> + <select id="Document.langue" wicket:id="Document.langue" /> + </div> + + <div class="property"> + <label for="Document.contrainteLegale"><wicket:message key="Document.contrainteLegale" /></label> + <input type="text" id="Document.contrainteLegale" wicket:id="Document.contrainteLegale" /> + </div> + + <div class="property required"> + <label for="Document.ajoutePar"><wicket:message key="Document.ajoutePar" /></label> + <input type="text" id="Document.ajoutePar" wicket:id="Document.ajoutePar" /> + </div> + + <div class="property required"> + <label for="TypeDocument.nom"><wicket:message key="TypeDocument.nom" /></label> + <select id="TypeDocument.nom" wicket:id="TypeDocument.nom" /> + </div> + + <div class="property"> + <label for="TypeDocument.domaine"><wicket:message key="TypeDocument.domaine" /></label> + <span id="TypeDocument.domain" wicket:id="TypeDocument.domaine" /> + </div> + + <div class="property"> + <label for="TypeDocument.description"><wicket:message key="TypeDocument.description" /></label> + <span id="TypeDocument.description" wicket:id="TypeDocument.description" /> + </div> + + <div class="property required"> + <label for="Document.fileName"><wicket:message key="Document.fileName" /></label> + <input type="file" id="Document.fileName" wicket:id="Document.fileName" /> + </div> + + <div class="actions"> + <input type="submit" wicket:message="value:Submit" wicket:id="Create" /> + <input type="submit" wicket:message="value:Submit" wicket:id="Update" /> + <input type="submit" wicket:message="value:Delete" wicket:id="Delete" class="warning" /> + <a wicket:id="Cancel"><wicket:message key="Cancel" /></a> + </div> + </form> + +</wicket:extend> +</body> +</html> \ No newline at end of file Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,361 @@ +/* + * #%L + * Cantharella :: Web + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package nc.ird.cantharella.web.pages.domain.document; + +import java.io.IOException; +import java.sql.Blob; +import java.util.Date; +import java.util.List; + +import nc.ird.cantharella.data.exceptions.DataConstraintException; +import nc.ird.cantharella.data.exceptions.DataNotFoundException; +import nc.ird.cantharella.data.exceptions.UnexpectedException; +import nc.ird.cantharella.data.model.Document; +import nc.ird.cantharella.data.model.Personne; +import nc.ird.cantharella.data.model.TypeDocument; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; +import nc.ird.cantharella.data.validation.utils.ModelValidator; +import nc.ird.cantharella.service.services.DocumentService; +import nc.ird.cantharella.service.services.PersonneService; +import nc.ird.cantharella.web.config.WebContext; +import nc.ird.cantharella.web.pages.TemplatePage; +import nc.ird.cantharella.web.pages.domain.personne.ManagePersonnePage; +import nc.ird.cantharella.web.utils.CallerPage; +import nc.ird.cantharella.web.utils.behaviors.JSConfirmationBehavior; +import nc.ird.cantharella.web.utils.forms.SubmittableButton; +import nc.ird.cantharella.web.utils.forms.SubmittableButtonEvents; +import nc.ird.cantharella.web.utils.renderers.MapChoiceRenderer; +import net.sf.ehcache.hibernate.HibernateUtil; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; +import org.apache.wicket.extensions.markup.html.form.DateTextField; +import org.apache.wicket.extensions.yui.calendar.DatePicker; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Button; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.form.upload.FileUpload; +import org.apache.wicket.markup.html.form.upload.FileUploadField; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.lang.Bytes; +import org.hibernate.engine.jdbc.internal.LobCreatorBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.support.lob.LobCreator; + +/** + * Document management page (creation/edition). + * + * @author Eric Chatellier + */ +public class ManageDocumentPage extends TemplatePage { + + /** Action : create */ + private static final String ACTION_CREATE = "Create"; + + /** Action : delete */ + public static final String ACTION_DELETE = "Delete"; + + /** Action : update */ + private static final String ACTION_UPDATE = "Update"; + + /** Logger */ + private static final Logger LOG = LoggerFactory.getLogger(ManageDocumentPage.class); + + /** Model : document. */ + private final IModel<Document> documentModel; + + /** Service : document */ + @SpringBean + private DocumentService documentService; + + /** Service : personnes */ + @SpringBean + private PersonneService personneService; + + /** Model validateur */ + @SpringBean(name = "webModelValidator") + private ModelValidator validator; + + /** Entity where document is attached. */ + private DocumentAttachable documentAttachable; + + /** Caller page. */ + private final CallerPage callerPage; + + /** Multiple entry. */ + private boolean multipleEntry; + + /** + * Constructeur (mode création) + * @param callerPage Page appelante + * @param documentAttachable entity where document is attached to + * @param multipleEntry Saisie multiple + */ + public ManageDocumentPage(CallerPage callerPage, DocumentAttachable documentAttachable, boolean multipleEntry) { + this(null, null, documentAttachable, callerPage, multipleEntry); + } + + /** + * Constructeur (mode édition) + * @param idDocument ID document + * @param callerPage Page appelante + */ + public ManageDocumentPage(Integer idDocument, CallerPage callerPage) { + this(idDocument, null, null, callerPage, false); + } + + /** + * Constructeur (mode saisie du lot suivante) + * @param document document + * @param callerPage Page appelante + */ + public ManageDocumentPage(Document document, CallerPage callerPage) { + this(null, document, null, callerPage, true); + } + + /** + * Constructeur. Si idDocument et document sont null, on créée un nouveau Document. + * Si idDocument est renseigné, on édite le document + * correspondant. Si document est renseigné, on créée un nouveau document à + * partir des informations qu'il contient. + * @param idDocument ID document + * @param document document + * @param documentAttachable entity where document is attached to + * @param callerPage Page appelante + * @param multipleEntry Saisie multiple + */ + private ManageDocumentPage(Integer idDocument, Document document, final DocumentAttachable documentAttachable, + final CallerPage callerPage, boolean multipleEntry) { + super(ManageDocumentPage.class); + assert idDocument == null || document == null; + this.callerPage = callerPage; + this.multipleEntry = multipleEntry; + this.documentAttachable = documentAttachable; + + final CallerPage currentPage = new CallerPage(this); + + // Initialisation du modèle + try { + documentModel = new Model<Document>(idDocument == null && document == null ? new Document() : document != null ? document + : documentService.loadDocument(idDocument)); + } catch (DataNotFoundException e) { + LOG.error(e.getMessage(), e); + throw new UnexpectedException(e); + } + + boolean createMode = idDocument == null; + if (createMode) { + documentModel.getObject().setCreateur(getSession().getUtilisateur()); + documentModel.getObject().setAjoutePar(getSession().getUtilisateur()); + } + + // Initialisation des listes (pour le dropDownChoice) + List<Personne> personnes = personneService.listPersonnes(); + List<TypeDocument> typeDocuments = documentService.listTypeDocuments(); + + // champ fichier + final FileUploadField fileUploadField = new FileUploadField("Document.fileName"); + + // initialisation du formulaire wicket + final Form<Void> formView = new Form<Void>("ManageDocumentPage.Form") { + @Override + protected void onSubmit() { + super.onSubmit(); + + + } + }; + formView.setMultiPart(true); + formView.setMaxSize(Bytes.megabytes(1)); + + formView.add(new TextField<String>("Document.titre", new PropertyModel<String>(documentModel, "titre"))); + + final DropDownChoice<Personne> createurInput = new DropDownChoice<Personne>("Document.createur", + new PropertyModel<Personne>(documentModel, "createur"), personnes); + createurInput.setOutputMarkupId(true); + createurInput.setNullValid(false); + formView.add(createurInput); + + // Action : création d'une nouvelle personne + // ajaxSubmitLink permet de sauvegarder l'état du formulaire + formView.add(new AjaxSubmitLink("NewPersonne") { + @Override + protected void onSubmit(AjaxRequestTarget target, Form<?> form) { + setResponsePage(new ManagePersonnePage(currentPage, false)); + } + + // si erreur, le formulaire est également enregistré puis la redirection effectuée + @Override + protected void onError(AjaxRequestTarget target, Form<?> form) { + setResponsePage(new ManagePersonnePage(currentPage, false)); + } + }); + + formView.add(new DateTextField("Document.dateCreation", new PropertyModel<Date>(documentModel, "dateCreation")) + .add(new DatePicker())); + formView.add(new TextField<String>("Document.editeur", new PropertyModel<String>(documentModel, "editeur"))); + + formView.add(new TextArea<String>("Document.description", new PropertyModel<String>(documentModel, "description"))); + + formView.add(new DropDownChoice<String>("Document.langue", + new PropertyModel<String>(documentModel, "langue"), WebContext.COUNTRY_CODES.get(getSession() + .getLocale()), new MapChoiceRenderer<String, String>(WebContext.COUNTRIES.get(getSession() + .getLocale())))); + formView.add(new TextField<String>("Document.contrainteLegale", new PropertyModel<String>(documentModel, "contrainteLegale"))); + + // AjoutePar en lecture seule + formView.add(new TextField<String>("Document.ajoutePar", new PropertyModel<String>(documentModel, "ajoutePar")) + .setEnabled(false)); + + // Type de document + final DropDownChoice<TypeDocument> typeDocumentInput = new DropDownChoice<TypeDocument>("TypeDocument.nom", + new PropertyModel<TypeDocument>(documentModel, "typeDocument"), typeDocuments); + typeDocumentInput.setOutputMarkupId(true); + typeDocumentInput.setNullValid(false); + formView.add(typeDocumentInput); + + final Label typeDocumentDomainLabel = new Label("TypeDocument.domaine", new PropertyModel<String>(documentModel, "typeDocument.domaine")); + typeDocumentDomainLabel.setOutputMarkupId(true); + formView.add(typeDocumentDomainLabel); + + final Label typeDocumentDescriptionLabel = new Label("TypeDocument.description", new PropertyModel<String>(documentModel, "typeDocument.description")); + typeDocumentDescriptionLabel.setOutputMarkupId(true); + formView.add(typeDocumentDescriptionLabel); + + // Fichier + formView.add(fileUploadField); + + // Action : création du document + Button createButton = new SubmittableButton(ACTION_CREATE, new SubmittableButtonEvents() { + @Override + public void onProcess() throws DataConstraintException { + documentAttachable.addDocument(documentModel.getObject()); + } + + @Override + public void onSuccess() { + successNextPage(ACTION_CREATE); + redirect(); + } + + @Override + public void onValidate() { + final FileUpload uploadedFile = fileUploadField.getFileUpload(); + if (uploadedFile != null) { + //documentModel.getObject().setFileContent(uploadedFile.getBytes()); + documentModel.getObject().setFileName(uploadedFile.getClientFileName()); + documentModel.getObject().setFileMimetype(uploadedFile.getContentType()); + + } + validateModel(); + } + }); + createButton.setVisibilityAllowed(createMode); + formView.add(createButton); + + // Action : mise à jour du document + Button updateButton = new SubmittableButton(ACTION_UPDATE, new SubmittableButtonEvents() { + @Override + public void onProcess() throws DataConstraintException { + // nothing, will be updated by cascade + } + + @Override + public void onSuccess() { + successNextPage(ACTION_UPDATE); + callerPage.responsePage((TemplatePage) getPage()); + } + + @Override + public void onValidate() { + validateModel(); + } + }); + updateButton.setVisibilityAllowed(!createMode + && documentService.updateOrdeleteDocumentEnabled(documentModel.getObject(), getSession().getUtilisateur())); + formView.add(updateButton); + + // Action : suppression du document + Button deleteButton = new SubmittableButton(ACTION_DELETE, new SubmittableButtonEvents() { + @Override + public void onProcess() throws DataConstraintException { + documentAttachable.removeDocument(documentModel.getObject()); + } + + @Override + public void onSuccess() { + successNextPage(ACTION_DELETE); + callerPage.responsePage((TemplatePage) getPage()); + } + }); + deleteButton.setVisibilityAllowed(!createMode + && documentService.updateOrdeleteDocumentEnabled(documentModel.getObject(), getSession().getUtilisateur())); + deleteButton.add(new JSConfirmationBehavior(getString("Confirm"))); + deleteButton.setDefaultFormProcessing(false); + formView.add(deleteButton); + + formView.add(new Link<Void>("Cancel") { + // Cas où le formulaire est annulé + @Override + public void onClick() { + callerPage.responsePage((TemplatePage) this.getPage()); + } + }); + + add(formView); + } + + /** + * Redirection vers une autre page. Cas où le formulaire est validé + */ + private void redirect() { + if (multipleEntry) { + // Redirection vers l'écran de saisie d'un nouveau document, en fournissant déjà quelques données + Document nextDocument = new Document(); + setResponsePage(new ManageDocumentPage(nextDocument, callerPage)); + } else if (callerPage != null) { + // On passe l'id du document associé à cette page, en paramètre de la prochaine page, pour lui permettre de + // l'exploiter si besoin + //callerPage.addPageParameter(Document.class.getSimpleName(), documentModel.getObject().getIdDocument()); + callerPage.responsePage(this); + } + } + + /** + * Validate model + */ + private void validateModel() { + if (documentModel.getObject().getCreateur() == null) { + documentModel.getObject().setCreateur(getSession().getUtilisateur()); + } + addValidationErrors(validator.validate(documentModel.getObject(), getSession().getLocale())); + } +} Property changes on: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.html (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.html 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,110 @@ +<!-- + #%L + Cantharella :: Web + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"> +<body> +<wicket:extend> + <div id="sheet"> + <div class="property"> + <span class="label"><wicket:message key="Document.titre" /></span> + <span class="value" wicket:id="Document.titre"></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.createur" /></span> + <span class="value" wicket:id="Document.createur"></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.editeur" /></span> + <span class="value" wicket:id="Document.editeur"></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.dateCreation" /></span> + <span class="value" wicket:id="Document.dateCreation"></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.description" /></span> + <span class="value" wicket:id="Document.description"></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.langue" /></span> + <span class="value" wicket:id="Document.langue" ></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.contrainteLegale" /></span> + <span class="value" wicket:id="Document.contrainteLegale" ></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.ajoutePar" /></span> + <span class="value" wicket:id="Document.ajoutePar" ></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="TypeDocument.nom" /></span> + <span class="value" wicket:id="TypeDocument.nom" ></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="TypeDocument.domaine" /></span> + <span class="value" wicket:id="TypeDocument.domaine" ></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="TypeDocument.description" /></span> + <span class="value" wicket:id="TypeDocument.description" ></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.fileName" /></span> + <span class="value" wicket:id="Document.fileName"></span> + </div> + + <div class="property"> + <span class="label"><wicket:message key="Document.fileMimetype" /></span> + <span class="value" wicket:id="Document.fileMimetype"></span> + </div> + + <form wicket:id="Form"> + <div class="actions"> + <a class="edit" wicket:id="ReadDocumentPage.Document.Update" wicket:message="title:Update"> + <wicket:message key="Update" /> + </a> + + <input type="submit" wicket:message="value:Delete" wicket:id="Delete" class="warning" /> + + <a wicket:id="ReadDocumentPage.Document.Back" wicket:message="title:Back"> + <wicket:message key="Back" /> + </a> + </div> + </form> + </div> +</wicket:extend> +</body> +</html> \ No newline at end of file Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.java (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.java 2013-02-13 15:03:01 UTC (rev 104) @@ -0,0 +1,149 @@ +/* + * #%L + * Cantharella :: Web + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package nc.ird.cantharella.web.pages.domain.document; + +import nc.ird.cantharella.data.exceptions.DataConstraintException; +import nc.ird.cantharella.data.model.Document; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; +import nc.ird.cantharella.web.pages.TemplatePage; +import nc.ird.cantharella.web.pages.domain.lot.ManageLotPage; +import nc.ird.cantharella.web.utils.CallerPage; +import nc.ird.cantharella.web.utils.behaviors.JSConfirmationBehavior; +import nc.ird.cantharella.web.utils.behaviors.ReplaceEmptyLabelBehavior; +import nc.ird.cantharella.web.utils.forms.SubmittableButton; +import nc.ird.cantharella.web.utils.forms.SubmittableButtonEvents; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Button; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; + +/** + * Document read page. + * + * @author Eric Chatellier + */ +public class ReadDocumentPage extends TemplatePage { + + /** Action : delete */ + public static final String ACTION_DELETE = "Delete"; + + /** Model : document */ + private final IModel<Document> documentModel; + + /** Caller page. */ + private final CallerPage callerPage; + + /** + * Constructeur + * @param idDocument ID document + * @param callerPage Page appelante + */ + public ReadDocumentPage(final Document document, final DocumentAttachable documentAttachable, final CallerPage callerPage) { + super(ReadDocumentPage.class); + this.callerPage = callerPage; + final CallerPage currentPage = new CallerPage(this); + + // Initialisation du modèle + documentModel = new Model<Document>(document); + + add(new Label("Document.titre", new PropertyModel<String>(documentModel, "titre")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.createur", new PropertyModel<String>(documentModel, "createur")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.dateCreation", new PropertyModel<String>(documentModel, "dateCreation")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.editeur", new PropertyModel<String>(documentModel, "editeur")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.description", new PropertyModel<String>(documentModel, "description")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.langue", new PropertyModel<String>(documentModel, "langue")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.contrainteLegale", new PropertyModel<String>(documentModel, "contrainteLegale")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.ajoutePar", new PropertyModel<String>(documentModel, "ajoutePar")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("TypeDocument.nom", new PropertyModel<String>(documentModel, "typeDocument.nom")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("TypeDocument.domaine", new PropertyModel<String>(documentModel, "typeDocument.domaine")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("TypeDocument.description", new PropertyModel<String>(documentModel, "typeDocument.description")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.fileName", new PropertyModel<String>(documentModel, "fileName")) + .add(new ReplaceEmptyLabelBehavior())); + add(new Label("Document.fileMimetype", new PropertyModel<String>(documentModel, "fileMimetype")) + .add(new ReplaceEmptyLabelBehavior())); + + // Formulaire des actions + final Form<Void> formView = new Form<Void>("Form"); + + // Action : mise à jour (redirection vers le formulaire) + Link<Document> updateLink = new Link<Document>(getResource() + ".Document.Update", new Model<Document>(documentModel.getObject())) { + @Override + public void onClick() { + setResponsePage(new ManageDocumentPage(getModelObject().getIdDocument(), currentPage)); + } + }; + //FIXME updateLink.setVisibilityAllowed(documentService.updateOrdeleteDocumentEnabled(documentModel.getObject(), getSession() + // .getUtilisateur())); + formView.add(updateLink); + + // Action : suppression + Button deleteButton = new SubmittableButton(ACTION_DELETE, ManageLotPage.class, new SubmittableButtonEvents() { + @Override + public void onProcess() throws DataConstraintException { + documentAttachable.removeDocument(documentModel.getObject()); + } + + @Override + public void onSuccess() { + successNextPage(ManageLotPage.class, ACTION_DELETE); + redirect(); + } + }); + // FIXME deleteButton.setVisibilityAllowed(documentService.updateOrdeleteDocumentEnabled(documentModel.getObject(), getSession() + // .getUtilisateur())); + deleteButton.add(new JSConfirmationBehavior(getString("Confirm"))); + deleteButton.setDefaultFormProcessing(false); + formView.add(deleteButton); + + // Action : retour + formView.add(new Link<Void>(getResource() + ".Document.Back") { + @Override + public void onClick() { + callerPage.responsePage((TemplatePage) getPage()); + } + }); + add(formView); + } + + /** + * Redirection vers une autre page + */ + private void redirect() { + callerPage.responsePage(this); + } +} Property changes on: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ReadDocumentPage.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/lot/ManageLotPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/lot/ManageLotPage.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/lot/ManageLotPage.java 2013-02-13 15:03:01 UTC (rev 104) @@ -220,7 +220,7 @@ // ajaxSubmitLink permet de sauvegarder l'état du formulaire formView.add(new AjaxSubmitLink("NewCampagne") { @Override - protected void onSubmit(AjaxRequestTarget arg0, Form<?> arg1) { + protected void onSubmit(AjaxRequestTarget target, Form<?> form) { setResponsePage(new ManageCampagnePage(currentPage, false)); } Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java 2013-02-13 15:03:01 UTC (rev 104) @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; + import nc.ird.cantharella.data.model.Lot; import nc.ird.cantharella.data.model.Utilisateur; import nc.ird.cantharella.service.model.MoleculeProvenanceBean; @@ -41,6 +42,8 @@ import nc.ird.cantharella.web.utils.models.SimpleSortableListDataProvider; import nc.ird.cantharella.web.utils.security.AuthRole; import nc.ird.cantharella.web.utils.security.AuthRoles; + +import org.apache.commons.collections.CollectionUtils; import org.apache.wicket.MarkupContainer; import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; @@ -141,6 +144,19 @@ new Model<String>(getString("Molecule.masseMolaire")), "molecule.masseMolaire", "molecule.masseMolaire", DecimalDisplFormat.SMALL, getLocale())); + columns.add(new LinkableImagePropertyColumn<MoleculeProvenanceBean>( + "images/attachment.png", getString("Read"), getString("Read")) { + @Override + public void onClick(Item<ICellPopulator<MoleculeProvenanceBean>> item, String componentId, IModel<MoleculeProvenanceBean> model) { + setResponsePage(new ReadMoleculePage(model.getObject().getIdMolecule(), currentPage)); + } + + @Override + protected boolean isVisibleAllowed(IModel<MoleculeProvenanceBean> model) { + return CollectionUtils.isNotEmpty(model.getObject().getMolecule().getDocuments()); + } + }); + columns.add(new BooleanPropertyColumn<MoleculeProvenanceBean>( new Model<String>(getString("Molecule.nouvMolecul")), "molecule.nouvMolecul", "molecule.nouvMolecul", this)); Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html 2013-02-13 15:03:01 UTC (rev 104) @@ -178,6 +178,14 @@ </table> </fieldset> + <fieldset> + <legend><wicket:message key="ListDocumentsPage.AttachedDocuments" /></legend> + <div wicket:id="ListDocumentsPage.AttachedDocuments.Refresh"> + <table cellspacing="0" wicket:id="ListDocumentsPage.AttachedDocuments"/> + </div> + <a wicket:id="NewDocument" class="add"><wicket:message key="ListDocumentsPage.NewDocument" /></a> + </fieldset> + <div class="actions"> <input type="submit" wicket:message="value:Submit" wicket:id="Create" /> <input type="submit" wicket:message="value:Submit" wicket:id="Update" /> Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java 2013-02-13 15:03:01 UTC (rev 104) @@ -30,19 +30,23 @@ import nc.ird.cantharella.data.exceptions.DataNotFoundException; import nc.ird.cantharella.data.exceptions.UnexpectedException; import nc.ird.cantharella.data.model.Campagne; +import nc.ird.cantharella.data.model.Document; import nc.ird.cantharella.data.model.Extrait; import nc.ird.cantharella.data.model.Fraction; import nc.ird.cantharella.data.model.Molecule; import nc.ird.cantharella.data.model.MoleculeProvenance; import nc.ird.cantharella.data.model.Produit; import nc.ird.cantharella.data.model.Utilisateur; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; import nc.ird.cantharella.data.validation.utils.ModelValidator; import nc.ird.cantharella.service.services.CampagneService; import nc.ird.cantharella.service.services.MoleculeService; import nc.ird.cantharella.service.services.PersonneService; import nc.ird.cantharella.service.services.ProduitService; +import nc.ird.cantharella.web.config.WebContext; import nc.ird.cantharella.web.pages.TemplatePage; import nc.ird.cantharella.web.pages.domain.campagne.ManageCampagnePage; +import nc.ird.cantharella.web.pages.domain.document.ManageDocumentPage; import nc.ird.cantharella.web.pages.domain.extraction.ReadExtractionPage; import nc.ird.cantharella.web.pages.domain.purification.ReadPurificationPage; import nc.ird.cantharella.web.pages.renderers.ProduitRenderer; @@ -56,6 +60,7 @@ import nc.ird.cantharella.web.utils.forms.SubmittableButtonEvents; import nc.ird.cantharella.web.utils.models.DisplayDecimalPropertyModel; import nc.ird.cantharella.web.utils.models.DisplayDecimalPropertyModel.DecimalDisplFormat; +import nc.ird.cantharella.web.utils.models.SimpleSortableListDataProvider; import nc.ird.cantharella.web.utils.panels.PropertyLabelLinkProduitPanel; import nc.ird.cantharella.web.utils.security.AuthRole; import nc.ird.cantharella.web.utils.security.AuthRoles; @@ -67,6 +72,12 @@ import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton; import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; +import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Button; @@ -79,6 +90,7 @@ import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.AbstractPropertyModel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.LoadableDetachableModel; @@ -146,7 +158,6 @@ /** * Constructeur (mode création). * @param callerPage Page appelante - * @param multipleEntry Saisie multiple */ public ManageMoleculePage(CallerPage callerPage) { this(null, callerPage); @@ -156,9 +167,7 @@ * Constructeur. Si idMolecule est null, on créée une nouvelle Molecule. Si idMolecule est renseigné, on édite la molecule * correspondante. * @param idMolecule ID molecule - * @param lot Lot * @param callerPage Page appelante - * @param multipleEntry Saisie multiple */ public ManageMoleculePage(Integer idMolecule, final CallerPage callerPage) { super(ManageMoleculePage.class); @@ -187,6 +196,7 @@ final Form<Void> formView = new Form<Void>("Form"); initProvenanceFields(formView, currentPage); + initAttachedDocumentsTable(formView, moleculeModel.getObject(), currentPage); // page can be accessed by anyone for editing provenance // but molecule fields can be edited only by administrators or @@ -268,6 +278,21 @@ formView.add(new TextField<String>("Molecule.createur", new PropertyModel<String>(moleculeModel, "createur")) .setEnabled(false)); + // Action : création d'un nouveau document + // ajaxSubmitLink permet de sauvegarder l'état du formulaire + formView.add(new AjaxSubmitLink("NewDocument") { + @Override + protected void onSubmit(AjaxRequestTarget request, Form<?> form) { + setResponsePage(new ManageDocumentPage(currentPage, moleculeModel.getObject(), false)); + } + + // si erreur, le formulaire est également enregistré puis la redirection effectuée + @Override + protected void onError(AjaxRequestTarget target, Form<?> form) { + setResponsePage(new ManageDocumentPage(currentPage, moleculeModel.getObject(), false)); + } + }.setVisibilityAllowed(editEnabled)); + // Action : création du lot Button createButton = new SubmittableButton(ACTION_CREATE, new SubmittableButtonEvents() { @Override @@ -575,6 +600,68 @@ } /** + * Init attached document table for current entity. + * + * @param formView form to add table to + * @param documentAttachable entity to get documents + * @param currentPage current page + */ + private void initAttachedDocumentsTable(final Form<Void> formView, final DocumentAttachable documentAttachable, CallerPage currentPage) { + + List<Document> documents = documentAttachable.getDocuments(); + + // On englobe le "DataView" dans un composant neutre que l'on pourra + // rafraichir quand la liste évoluera + final MarkupContainer attachedDocumentRefresh = new WebMarkupContainer("ListDocumentsPage.AttachedDocuments.Refresh"); + attachedDocumentRefresh.setOutputMarkupId(true); + formView.add(attachedDocumentRefresh); + + SimpleSortableListDataProvider<Document> attachedDocumentsDataProvider = + new SimpleSortableListDataProvider<Document>( + documents, getSession().getLocale()); + + List<IColumn<Document>> columns = new ArrayList<IColumn<Document>>(); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.titre")), "titre", "titre")); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.typeDocument")), "typeDocument.nom", "typeDocument.nom")); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.createur")), "createur", "createur")); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.fileName")), "fileName", "fileName")); + + columns.add(new AbstractColumn<Document>(new Model<String>(), "idMolecule") { + @Override + public void populateItem(Item<ICellPopulator<Document>> cellItem, String componentId, final IModel<Document> rowModel) { + cellItem.add(new AjaxFallbackButton(componentId, new Model<String>(getString("Delete")), formView) { + @Override + protected void onSubmit(AjaxRequestTarget target, Form<?> form) { + documentAttachable.removeDocument(rowModel.getObject()); + + if (target != null) { + target.add(attachedDocumentRefresh); + refreshFeedbackPage(target); + } + } + + @Override + protected void onError(AjaxRequestTarget target, Form<?> form) { + // never called + } + }); + } + }); + + final DataTable<Document> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document>("ListDocumentsPage.AttachedDocuments", columns, + attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); + attachedDocumentRefresh.add(attachedDocumentTable); + } + + /** * Redirection vers une autre page. Cas où le formulaire est validé */ private void redirect() { Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.html 2013-02-13 15:03:01 UTC (rev 104) @@ -152,6 +152,11 @@ </div> </fieldset> + <fieldset> + <legend><wicket:message key="ListDocumentsPage.AttachedDocuments" /></legend> + <table cellspacing="0" wicket:id="ListDocumentsPage.AttachedDocuments"/> + </fieldset> + <form wicket:id="Form"> <div class="actions"> <a class="edit" wicket:id="ReadMoleculePage.Molecule.Update" wicket:message="title:Update"> Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-13 15:03:01 UTC (rev 104) @@ -27,14 +27,18 @@ import nc.ird.cantharella.data.exceptions.DataConstraintException; import nc.ird.cantharella.data.model.Campagne; +import nc.ird.cantharella.data.model.Document; import nc.ird.cantharella.data.model.Extrait; import nc.ird.cantharella.data.model.Fraction; import nc.ird.cantharella.data.model.Molecule; import nc.ird.cantharella.data.model.MoleculeProvenance; import nc.ird.cantharella.data.model.Personne; import nc.ird.cantharella.data.model.Produit; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; import nc.ird.cantharella.service.services.MoleculeService; +import nc.ird.cantharella.web.config.WebContext; import nc.ird.cantharella.web.pages.TemplatePage; +import nc.ird.cantharella.web.pages.domain.document.ReadDocumentPage; import nc.ird.cantharella.web.pages.domain.extraction.ReadExtractionPage; import nc.ird.cantharella.web.pages.domain.lot.ManageLotPage; import nc.ird.cantharella.web.pages.domain.personne.ReadPersonnePage; @@ -43,12 +47,14 @@ import nc.ird.cantharella.web.utils.behaviors.JSConfirmationBehavior; import nc.ird.cantharella.web.utils.behaviors.MoleculeViewBehavior; import nc.ird.cantharella.web.utils.behaviors.ReplaceEmptyLabelBehavior; +import nc.ird.cantharella.web.utils.columns.LinkPropertyColumn; import nc.ird.cantharella.web.utils.forms.SubmittableButton; import nc.ird.cantharella.web.utils.forms.SubmittableButtonEvents; import nc.ird.cantharella.web.utils.models.DisplayBooleanPropertyModel; import nc.ird.cantharella.web.utils.models.DisplayDecimalPropertyModel; import nc.ird.cantharella.web.utils.models.DisplayDecimalPropertyModel.DecimalDisplFormat; import nc.ird.cantharella.web.utils.models.GenericLoadableDetachableModel; +import nc.ird.cantharella.web.utils.models.SimpleSortableListDataProvider; import nc.ird.cantharella.web.utils.panels.PropertyLabelLinkPanel; import nc.ird.cantharella.web.utils.panels.PropertyLabelLinkProduitPanel; import nc.ird.cantharella.web.utils.security.AuthRole; @@ -57,6 +63,11 @@ import org.apache.wicket.AttributeModifier; import org.apache.wicket.MarkupContainer; +import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Button; @@ -64,6 +75,7 @@ import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.IModel; import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.model.Model; @@ -106,6 +118,7 @@ moleculeModel = new GenericLoadableDetachableModel<Molecule>(Molecule.class, idMolecule); initProvenanceFields(currentPage); + initAttachedDocumentsTable(moleculeModel.getObject(), currentPage); add(new Label("Molecule.idMolecule", new PropertyModel<String>(moleculeModel, "idMolecule"))); add(new Label("Molecule.nomCommun", new PropertyModel<String>(moleculeModel, "nomCommun")).add(new ReplaceEmptyLabelBehavior())); @@ -271,4 +284,43 @@ }; add(noTableProvenances); } + + /** + * Init attached document table for current entity. + * + * @param formView form to add table to + * @param documentAttachable entity to get documents + * @param currentPage current page + */ + private void initAttachedDocumentsTable(final DocumentAttachable documentAttachable, final CallerPage currentPage) { + + List<Document> documents = documentAttachable.getDocuments(); + + SimpleSortableListDataProvider<Document> attachedDocumentsDataProvider = + new SimpleSortableListDataProvider<Document>( + documents, getSession().getLocale()); + + List<IColumn<Document>> columns = new ArrayList<IColumn<Document>>(); + + columns.add(new LinkPropertyColumn<Document>( + new Model<String>(getString("Document.titre")), "titre", "titre") { + @Override + public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { + setResponsePage(new ReadDocumentPage(model.getObject(), documentAttachable, currentPage)); + } + }); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.typeDocument")), "typeDocument.nom", "typeDocument.nom")); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.createur")), "createur", "createur")); + + columns.add(new PropertyColumn<Document>( + new Model<String>(getString("Document.fileName")), "fileName", "fileName")); + + final DataTable<Document> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document>("ListDocumentsPage.AttachedDocuments", columns, + attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); + add(attachedDocumentTable); + } } Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java 2013-02-13 15:03:01 UTC (rev 104) @@ -64,10 +64,21 @@ /** {@inheritDoc} */ @Override public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> model) { - item.add(new LinkableImagePanel(item, componentId, model)); + LinkableImagePanel panel = new LinkableImagePanel(item, componentId, model); + panel.setVisibilityAllowed(isVisibleAllowed(model)); + item.add(panel); } /** + * Overridable method to mask panel. + * @param model model + * @return true if panel is visible + */ + protected boolean isVisibleAllowed(IModel<T> model) { + return true; + } + + /** * Override this method to react to link clicks. Your own/internal row id will most likely be inside the model. * @param item Item * @param componentId Component id Modified: trunk/cantharella.web/src/main/resources/web_en.properties =================================================================== --- trunk/cantharella.web/src/main/resources/web_en.properties 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/resources/web_en.properties 2013-02-13 15:03:01 UTC (rev 104) @@ -131,6 +131,9 @@ ListTestsBioPage2=Bioassays ListTestsBioPage.NewTestBio=New bioassay +ListDocumentsPage.NewDocument=New document +ListDocumentsPage.AttachedDocuments=Attached documents + ManageCampagnePage=Campaign management ManageCampagnePage.Create.OK=Campaign added ManageCampagnePage.Create.DataConstraintException=The name already exists @@ -207,6 +210,12 @@ ManageTestBioPage.Delete.OK=Bioassay deleted ManageTestBioPage.Delete.DataConstraintException=There are data linked to this biassay +ManageDocumentPage=Document management +ManageDocumentPage.Create.OK=Document added +ManageDocumentPage.Update.OK=Document updated +ManageDocumentPage.Delete.OK=Document deleted +ManageDocumentPage.Form.uploadTooLarge=La taille du document ne peut pas dépasser ${maxSize} + UpdateUtilisateurPage=Account management UpdateUtilisateurPage.Password=Password UpdateUtilisateurPage.Profile=Profile @@ -280,6 +289,7 @@ ReadPurificationPage=Viewing a purification ReadMoleculePage=Viewing a molecule ReadTestBioPage=Viewing a bioassay +ReadDocumentPage=Viewing a document SearchPage=Search SearchPage.Search=Search Modified: trunk/cantharella.web/src/main/resources/web_fr.properties =================================================================== --- trunk/cantharella.web/src/main/resources/web_fr.properties 2013-02-13 11:57:28 UTC (rev 103) +++ trunk/cantharella.web/src/main/resources/web_fr.properties 2013-02-13 15:03:01 UTC (rev 104) @@ -130,6 +130,9 @@ ListTestsBioPage2=Tests biologiques ListTestsBioPage.NewTestBio=Nouveau test biologique +ListDocumentsPage.NewDocument=Nouveau document +ListDocumentsPage.AttachedDocuments=Document(s) attaché(s) + ManageCampagnePage=Gestion d'une campagne ManageCampagnePage.Create.OK=Campagne ajoutée ManageCampagnePage.Create.DataConstraintException=Le nom existe déjà @@ -206,6 +209,12 @@ ManageTestBioPage.Delete.OK=Test biologique supprimé ManageTestBioPage.Delete.DataConstraintException=Il existe des données liées à ce test biologique +ManageDocumentPage=Gestion d'un document +ManageDocumentPage.Create.OK=Document ajouté +ManageDocumentPage.Update.OK=Document mis à jour +ManageDocumentPage.Delete.OK=Document supprimé +ManageDocumentPage.Form.uploadTooLarge=La taille du document ne peut pas dépasser ${maxSize} + UpdateUtilisateurPage=Gestion du compte UpdateUtilisateurPage.Password=Mot de passe UpdateUtilisateurPage.Profile=Profil @@ -279,6 +288,7 @@ ReadPurificationPage=Consultation d'une purification ReadMoleculePage=Consultation d'une molécule ReadTestBioPage=Consultation d'un test biologique +ReadDocumentPage=Consultation d'un document SearchPage=Recherche SearchPage.Search=Rechercher Added: trunk/cantharella.web/src/main/webapp/images/attachment.png =================================================================== (Binary files differ) Property changes on: trunk/cantharella.web/src/main/webapp/images/attachment.png ___________________________________________________________________ Added: svn:mime-type + image/png