r146 - in trunk/cantharella.web/src/main: java/nc/ird/cantharella/web/config java/nc/ird/cantharella/web/pages java/nc/ird/cantharella/web/pages/domain/document java/nc/ird/cantharella/web/pages/domain/molecule resources
Author: echatellier Date: 2013-02-21 13:33:49 +0100 (Thu, 21 Feb 2013) New Revision: 146 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/146 Log: Move document table init in helper class to be used in multiple class. Fix configuration (in wicket application class) Fix display messages. Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/config/WebApplicationImpl.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/TemplatePage.java 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/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.java trunk/cantharella.web/src/main/resources/cantharella.conf trunk/cantharella.web/src/main/resources/web_en.properties trunk/cantharella.web/src/main/resources/web_fr.properties 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-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/config/WebApplicationImpl.java 2013-02-21 12:33:49 UTC (rev 146) @@ -28,6 +28,7 @@ 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.utils.AssertTools; import nc.ird.cantharella.web.pages.ContactPage; import nc.ird.cantharella.web.pages.HomePage; import nc.ird.cantharella.web.pages.domain.campagne.ListCampagnesPage; @@ -72,7 +73,6 @@ 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.cantharella.utils.AssertTools; import org.apache.wicket.ConverterLocator; import org.apache.wicket.IConverterLocator; @@ -99,6 +99,7 @@ import org.apache.wicket.util.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; /** * Web application @@ -134,6 +135,10 @@ /** Wicket configuration (Application.DEVELOPMENT or Application.DEPLOYMENT) */ private final RuntimeConfigurationType wicketConfiguration; + /** Configuration document max upload size. */ + @Value("${document.maxUploadSize}") + protected long documentMaxUploadSize; + /** * Constructor * @param debug Debug mode @@ -423,4 +428,12 @@ mountPage("/search", SearchPage.class); } + /** + * Get document max upload size. + * + * @return document max upload size + */ + public long getDocumentMaxUploadSize() { + return documentMaxUploadSize; + } } \ No newline at end of file Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/TemplatePage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/TemplatePage.java 2013-02-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/TemplatePage.java 2013-02-21 12:33:49 UTC (rev 146) @@ -378,7 +378,7 @@ * Refresh feedback page and scroll up to the anchor if any feedback message * @param target Ajax target */ - protected final void refreshFeedbackPage(AjaxRequestTarget target) { + public final void refreshFeedbackPage(AjaxRequestTarget target) { if (target != null) { target.add(feedbackPanelContainer); // scroll up to the anchor if any feedback message Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java 2013-02-21 12:33:49 UTC (rev 146) @@ -0,0 +1,208 @@ +/* + * #%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.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import nc.ird.cantharella.data.model.Document; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; +import nc.ird.cantharella.web.config.WebContext; +import nc.ird.cantharella.web.pages.TemplatePage; +import nc.ird.cantharella.web.utils.CallerPage; +import nc.ird.cantharella.web.utils.columns.AjaxButtonPropertyColumn; +import nc.ird.cantharella.web.utils.columns.LinkPropertyColumn; +import nc.ird.cantharella.web.utils.columns.LinkableImagePropertyColumn; +import nc.ird.cantharella.web.utils.models.SimpleSortableListDataProvider; + +import org.apache.commons.io.IOUtils; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.ajax.AjaxRequestTarget; +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.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.form.Form; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.http.WebResponse; + +/** + * Helper providing static method to init document list into entity Read or + * Manager page. + * + * @author Eric Chatellier + */ +public abstract class DocumentPageHelper { + + /** + * Init attached document table for current entity. + * + * @param templatePage parent page + * @param formView form to add table to + * @param documentAttachable entity to get documents + * @param currentPage current page + */ + public static void initAttachedDocumentsManageTable(final TemplatePage templatePage, + final Form<Void> formView, final DocumentAttachable documentAttachable, final 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, templatePage.getSession().getLocale()); + + List<IColumn<Document, String>> columns = new ArrayList<IColumn<Document, String>>(); + + columns.add(new LinkPropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.titre")), "titre", + "titre") { + @Override + public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { + templatePage.setResponsePage(new ReadDocumentPage(model.getObject(), documentAttachable, currentPage)); + } + }); + + columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.typeDocument")), + "typeDocument.nom", "typeDocument.nom")); + + columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.createur")), "createur", + "createur")); + + columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.link")), + "images/download.png", templatePage.getString("Document.link"), templatePage.getString("Document.link")) { + @Override + public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { + Document document = model.getObject(); + WebResponse response = (WebResponse) templatePage.getResponse(); + response.setContentType(document.getFileMimetype()); + response.setAttachmentHeader(document.getFileName()); + response.write(document.getFileContent()); + } + }); + + final DataTable<Document, String> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document, String>( + "ListDocumentsPage.AttachedDocuments", columns, attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); + + columns.add(new AjaxButtonPropertyColumn<Document, String>(new Model<String>(templatePage.getString("Actions")), + new Model<String>(templatePage.getString("Delete")), formView) { + @Override + public void onSubmit(AjaxRequestTarget target, Form<?> form, IModel<Document> model) { + Document document = model.getObject(); + documentAttachable.removeDocument(document); + + if (target != null) { + target.add(attachedDocumentTable); + templatePage.refreshFeedbackPage(target); + } + } + }); + + attachedDocumentRefresh.add(attachedDocumentTable); + + // 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, documentAttachable, 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, documentAttachable, false)); + } + }.setVisibilityAllowed(true)); + } + + /** + * Init attached document table for current entity. + * + * @param templatePage parent page + * @param formView form to add table to + * @param documentAttachable entity to get documents + * @param currentPage current page + */ + public static void initAttachedDocumentsReadTable(final TemplatePage templatePage, final DocumentAttachable documentAttachable, + final CallerPage currentPage) { + + List<Document> documents = documentAttachable.getDocuments(); + + SimpleSortableListDataProvider<Document> attachedDocumentsDataProvider = new SimpleSortableListDataProvider<Document>( + documents, templatePage.getSession().getLocale()); + + List<IColumn<Document, String>> columns = new ArrayList<IColumn<Document, String>>(); + + columns.add(new LinkPropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.titre")), "titre", + "titre") { + @Override + public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { + templatePage.setResponsePage(new ReadDocumentPage(model.getObject(), documentAttachable, currentPage)); + } + }); + + columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.typeDocument")), + "typeDocument.nom", "typeDocument.nom")); + + columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.createur")), "createur", + "createur")); + + columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.link")), + "images/download.png", templatePage.getString("Document.link"), templatePage.getString("Document.link")) { + @Override + public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { + + Document document = model.getObject(); + WebResponse response = (WebResponse) templatePage.getResponse(); + response.setContentType(document.getFileMimetype()); + response.setAttachmentHeader(document.getFileName()); + + OutputStream out = templatePage.getResponse().getOutputStream(); + InputStream in = new ByteArrayInputStream(document.getFileContent()); + try { + IOUtils.copy(in, out); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + + final DataTable<Document, String> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document, String>( + "ListDocumentsPage.AttachedDocuments", columns, attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); + templatePage.add(attachedDocumentTable); + } +} Property changes on: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: 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 2013-02-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java 2013-02-21 12:33:49 UTC (rev 146) @@ -35,6 +35,7 @@ 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.WebApplicationImpl; import nc.ird.cantharella.web.config.WebContext; import nc.ird.cantharella.web.pages.TemplatePage; import nc.ird.cantharella.web.pages.domain.personne.ManagePersonnePage; @@ -68,7 +69,6 @@ import org.apache.wicket.util.lang.Bytes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; /** * Document management page (creation/edition). @@ -110,10 +110,6 @@ /** Multiple entry. */ private boolean multipleEntry; - /** Configuration document max upload size. */ - @Value("${document.maxUploadSize}") - protected long documentMaxUploadSize; - /** * Constructeur (mode création) * @param callerPage Page appelante @@ -162,6 +158,9 @@ final CallerPage currentPage = new CallerPage(this); + // get configuration + long documentMaxUploadSize = ((WebApplicationImpl)getApplication()).getDocumentMaxUploadSize(); + // Initialisation du modèle try { documentModel = new Model<Document>(idDocument == null && document == null ? new Document() @@ -267,7 +266,8 @@ }); // Fichier - formView.add(new SimpleTooltipPanel("Document.file.info", new Model<String>(getString("Document.file.info")))); + formView.add(new SimpleTooltipPanel("Document.file.info", new Model<String>(getString("Document.file.info", + Model.of(new Object[]{documentMaxUploadSize}))))); formView.add(fileUploadField); // Action : création du document @@ -290,7 +290,6 @@ documentModel.getObject().setFileContent(uploadedFile.getBytes()); documentModel.getObject().setFileName(uploadedFile.getClientFileName()); documentModel.getObject().setFileMimetype(uploadedFile.getContentType()); - } validateModel(); } 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-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.html 2013-02-21 12:33:49 UTC (rev 146) @@ -99,7 +99,7 @@ <fieldset> <legend><wicket:message key="Molecule.provenance" /></legend> - <table class="large" cellspacing="0" wicket:id="Molecule.provenance.Table"> + <table cellspacing="0" wicket:id="Molecule.provenance.Table"> <thead> <tr> <th class="required"> @@ -182,7 +182,7 @@ <fieldset> <legend><wicket:message key="ListDocumentsPage.AttachedDocuments" /></legend> <div wicket:id="ListDocumentsPage.AttachedDocuments.Refresh"> - <table class="large" cellspacing="0" wicket:id="ListDocumentsPage.AttachedDocuments"/> + <table cellspacing="0" wicket:id="ListDocumentsPage.AttachedDocuments"/> </div> <a wicket:id="NewDocument" class="add"><wicket:message key="ListDocumentsPage.NewDocument" /></a> </fieldset> 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-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ManageMoleculePage.java 2013-02-21 12:33:49 UTC (rev 146) @@ -22,10 +22,6 @@ */ package nc.ird.cantharella.web.pages.domain.molecule; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -34,23 +30,19 @@ 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.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.document.ReadDocumentPage; +import nc.ird.cantharella.web.pages.domain.document.DocumentPageHelper; 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; @@ -58,34 +50,24 @@ import nc.ird.cantharella.web.utils.behaviors.JSConfirmationBehavior; import nc.ird.cantharella.web.utils.behaviors.MoleculeEditorBehavior; import nc.ird.cantharella.web.utils.behaviors.MoleculeViewBehavior; -import nc.ird.cantharella.web.utils.columns.AjaxButtonPropertyColumn; -import nc.ird.cantharella.web.utils.columns.LinkPropertyColumn; -import nc.ird.cantharella.web.utils.columns.LinkableImagePropertyColumn; import nc.ird.cantharella.web.utils.forms.AutoCompleteTextFieldString; import nc.ird.cantharella.web.utils.forms.AutoCompleteTextFieldString.ComparisonMode; import nc.ird.cantharella.web.utils.forms.SubmittableButton; 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.panels.SimpleTooltipPanel; import nc.ird.cantharella.web.utils.security.AuthRole; import nc.ird.cantharella.web.utils.security.AuthRoles; import nc.ird.cantharella.web.utils.security.AuthSession; -import org.apache.commons.io.IOUtils; import org.apache.wicket.AttributeModifier; import org.apache.wicket.MarkupContainer; import org.apache.wicket.ajax.AjaxRequestTarget; 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.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; @@ -98,13 +80,11 @@ 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; import org.apache.wicket.model.Model; import org.apache.wicket.model.PropertyModel; -import org.apache.wicket.request.http.WebResponse; import org.apache.wicket.spring.injection.annot.SpringBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -202,7 +182,7 @@ final Form<Void> formView = new Form<Void>("Form"); initProvenanceFields(formView, currentPage); - initAttachedDocumentsTable(formView, moleculeModel.getObject(), currentPage); + DocumentPageHelper.initAttachedDocumentsManageTable(this, formView, moleculeModel.getObject(), currentPage); // page can be accessed by anyone for editing provenance // but molecule fields can be edited only by administrators or @@ -606,99 +586,6 @@ } /** - * 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, - final 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, String>> columns = new ArrayList<IColumn<Document, String>>(); - - columns.add(new LinkPropertyColumn<Document, String>(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, String>(new Model<String>(getString("Document.typeDocument")), - "typeDocument.nom", "typeDocument.nom")); - - columns.add(new PropertyColumn<Document, String>(new Model<String>(getString("Document.createur")), "createur", - "createur")); - - columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(getString("Document.link")), - "images/download.png", getString("Document.link"), getString("Document.link")) { - @Override - public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { - - Document document = model.getObject(); - WebResponse response = (WebResponse) getResponse(); - response.setContentType(document.getFileMimetype()); - response.setAttachmentHeader(document.getFileName()); - - OutputStream out = getResponse().getOutputStream(); - InputStream in = new ByteArrayInputStream(document.getFileContent()); - try { - IOUtils.copy(in, out); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - final DataTable<Document, String> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document, String>( - "ListDocumentsPage.AttachedDocuments", columns, attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); - - columns.add(new AjaxButtonPropertyColumn<Document, String>(new Model<String>(getString("Actions")), - new Model<String>(getString("Delete")), formView) { - @Override - public void onSubmit(AjaxRequestTarget target, Form<?> form, IModel<Document> model) { - Document document = model.getObject(); - documentAttachable.removeDocument(document); - - if (target != null) { - target.add(attachedDocumentTable); - refreshFeedbackPage(target); - } - } - }); - - attachedDocumentRefresh.add(attachedDocumentTable); - - // 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(true)); - } - - /** * 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.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ReadMoleculePage.java 2013-02-21 12:33:49 UTC (rev 146) @@ -22,27 +22,20 @@ */ package nc.ird.cantharella.web.pages.domain.molecule; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; 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.document.DocumentPageHelper; 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; @@ -51,29 +44,20 @@ 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.columns.LinkableImagePropertyColumn; 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; import nc.ird.cantharella.web.utils.security.AuthRoles; import nc.ird.cantharella.web.utils.security.AuthSession; -import org.apache.commons.io.IOUtils; 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; @@ -82,12 +66,9 @@ import org.apache.wicket.markup.html.link.ResourceLink; 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; import org.apache.wicket.model.PropertyModel; -import org.apache.wicket.request.http.WebResponse; import org.apache.wicket.request.resource.ByteArrayResource; import org.apache.wicket.spring.injection.annot.SpringBean; @@ -103,14 +84,14 @@ public static final String ACTION_DELETE = "Delete"; /** Modèle : molecule */ - private final IModel<Molecule> moleculeModel; + private IModel<Molecule> moleculeModel; /** Service : molecule */ @SpringBean private MoleculeService moleculeService; /** Page appelante */ - private final CallerPage callerPage; + private CallerPage callerPage; /** * Constructor with molecule id to render. @@ -127,7 +108,7 @@ moleculeModel = new GenericLoadableDetachableModel<Molecule>(Molecule.class, idMolecule); initProvenanceFields(currentPage); - initAttachedDocumentsTable(moleculeModel.getObject(), currentPage); + DocumentPageHelper.initAttachedDocumentsReadTable(this, moleculeModel.getObject(), currentPage); add(new Label("Molecule.idMolecule", new PropertyModel<String>(moleculeModel, "idMolecule"))); add(new Label("Molecule.nomCommun", new PropertyModel<String>(moleculeModel, "nomCommun")) @@ -318,59 +299,4 @@ }; 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, String>> columns = new ArrayList<IColumn<Document, String>>(); - - columns.add(new LinkPropertyColumn<Document, String>(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, String>(new Model<String>(getString("Document.typeDocument")), - "typeDocument.nom", "typeDocument.nom")); - - columns.add(new PropertyColumn<Document, String>(new Model<String>(getString("Document.createur")), "createur", - "createur")); - - columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(getString("Document.link")), - "images/download.png", getString("Document.link"), getString("Document.link")) { - @Override - public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { - - Document document = model.getObject(); - WebResponse response = (WebResponse) getResponse(); - response.setContentType(document.getFileMimetype()); - response.setAttachmentHeader(document.getFileName()); - - OutputStream out = getResponse().getOutputStream(); - InputStream in = new ByteArrayInputStream(document.getFileContent()); - try { - IOUtils.copy(in, out); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - final DataTable<Document, String> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document, String>( - "ListDocumentsPage.AttachedDocuments", columns, attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); - add(attachedDocumentTable); - } } Modified: trunk/cantharella.web/src/main/resources/cantharella.conf =================================================================== --- trunk/cantharella.web/src/main/resources/cantharella.conf 2013-02-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/resources/cantharella.conf 2013-02-21 12:33:49 UTC (rev 146) @@ -36,4 +36,4 @@ # value for production #log4j.config=/home/tomcat/.config/log4j_prod.xml #document file max upload size (Mb) -document.maxUploadSize=1 \ No newline at end of file +document.maxUploadSize=1 Modified: trunk/cantharella.web/src/main/resources/web_en.properties =================================================================== --- trunk/cantharella.web/src/main/resources/web_en.properties 2013-02-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/resources/web_en.properties 2013-02-21 12:33:49 UTC (rev 146) @@ -131,7 +131,7 @@ ListTestsBioPage2=Bioassays ListTestsBioPage.NewTestBio=New bioassay -ListDocumentsPage.NewDocument=New document +ListDocumentsPage.NewDocument=Attach new document ListDocumentsPage.AttachedDocuments=Attached documents ManageCampagnePage=Campaign management @@ -414,7 +414,7 @@ Document.link=Link Document.type=Type Document.file=File -Document.file.info=File size must be less than 1Mb +Document.file.info=File size must be less than ${0}Mb #BASIC# Actions=Actions Modified: trunk/cantharella.web/src/main/resources/web_fr.properties =================================================================== --- trunk/cantharella.web/src/main/resources/web_fr.properties 2013-02-21 12:30:01 UTC (rev 145) +++ trunk/cantharella.web/src/main/resources/web_fr.properties 2013-02-21 12:33:49 UTC (rev 146) @@ -130,7 +130,7 @@ ListTestsBioPage2=Tests biologiques ListTestsBioPage.NewTestBio=Nouveau test biologique -ListDocumentsPage.NewDocument=Nouveau document +ListDocumentsPage.NewDocument=Joindre un nouveau document ListDocumentsPage.AttachedDocuments=Document(s) attaché(s) ManageCampagnePage=Gestion d'une campagne @@ -412,7 +412,7 @@ Document.link=Lien Document.type=Type Document.file=Fichier -Document.file.info=La taille du fichier doit faire moins de 1Mo +Document.file.info=La taille du fichier doit faire moins de ${0}Mo #BASIC# Actions=Actions
participants (1)
-
echatellier@users.forge.codelutin.com