Author: bpoussin Date: 2012-08-03 18:31:36 +0200 (Fri, 03 Aug 2012) New Revision: 227 Url: http://chorem.org/repositories/revision/chorem/227 Log: les attachments sont telechargement directement dans les tableaux Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java 2012-08-03 15:36:56 UTC (rev 226) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java 2012-08-03 16:31:36 UTC (rev 227) @@ -62,6 +62,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.servlet.ServletContext; +import org.apache.commons.lang3.StringUtils; /** * @@ -217,8 +219,29 @@ // } // }; + public final class AttachmentLink { + protected String contextPath; + protected Attachment attachment; - protected <E> Map<String, List<Attachment>> prepareAttachment(ChoremClient client, Collection<E> ids) { + public AttachmentLink(String contextPath, Attachment attachment) { + this.contextPath = contextPath; + this.attachment = attachment; + } + + @Override + public String toString() { + String id = attachment.getWikittyId(); + String name = attachment.getName(); + String url = attachment.getContentUrl(); + if (StringUtils.isBlank(url)) { + url = contextPath + "/wikitty/view/" + id + "/Attachment/content"; + } + return String.format("<a href='%s'>%s</a>", url, name); + } + + } + + protected <E> Map<String, List<AttachmentLink>> prepareAttachment(ChoremClient client, Collection<E> ids) { // recherche des attachments de chaque quotation trouvee WikittyQuery attachmentQuery = new WikittyQueryMaker().and() .exteq(Attachment.EXT_ATTACHMENT) @@ -229,15 +252,17 @@ client.findAllByQuery(Attachment.class, attachmentQuery); // preparation des attachements pour chaque quotation - Map<String, List<Attachment>> attachments = new HashMap<String, List<Attachment>>(); + ServletContext servletContext = getContext().getServletContext(); + String contextPath = servletContext.getContextPath(); + Map<String, List<AttachmentLink>> attachments = new HashMap<String, List<AttachmentLink>>(); for (Attachment a : attachmentResult) { String id = a.getTarget(); - List<Attachment> l = attachments.get(id); + List<AttachmentLink> l = attachments.get(id); if (l == null) { - l = new LinkedList<Attachment>(); + l = new LinkedList<AttachmentLink>(); attachments.put(id, l); } - l.add(a); + l.add(new AttachmentLink(contextPath, a)); } return attachments; @@ -311,7 +336,7 @@ client.findAllByQuery(Quotation.class, quotationQuery); // recherche des attachments de chaque quotation trouvee - Map<String, List<Attachment>> attachments = + Map<String, List<AttachmentLink>> attachments = prepareAttachment(client, result.getAll()); // TODO poussin 20120523 ajouer la recherche des note sur la quotation @@ -535,7 +560,7 @@ } // recherche des attachments de chaque quotation trouvee - Map<String, List<Attachment>> attachments = + Map<String, List<AttachmentLink>> attachments = prepareAttachment(client, invoices.getAll()); return renderView("dashboardInvoice.jsp", Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java 2012-08-03 15:36:56 UTC (rev 226) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java 2012-08-03 16:31:36 UTC (rev 227) @@ -380,8 +380,10 @@ return map; } - public Render view(ChoremClient client, String id, String[] extension, - Config config, ServletContext servletContext) { + public Render view(ChoremClient client, String id, String[] extension) { + Config config = getContext().getServerContext().getMapping().getConfig(); + ServletContext servletContext = getContext().getServletContext(); + log.debug("view: " + id); Wikitty w = client.restore(id, ".*"); @@ -422,21 +424,6 @@ return renderView("view.jsp", "wikitty", w, "extensions", exts, "viewActions", viewActions); } - public Render extensionView(ChoremClient client, String id, String extension) { - log.debug("view: " + id); - Wikitty w = client.restore(id, ".*"); - - LinkedHashSet<WikittyExtension> exts = new LinkedHashSet<WikittyExtension>(); - if (w != null) { - // Display the extensions and required ones for them - List<String> extensionNames = Arrays.asList(extension); - List<WikittyExtension> wikittyExtensions = client.restoreExtensionAndDependenciesLastVesion(extensionNames); - exts.addAll(wikittyExtensions); - } - - return renderView(StringUtils.lowerCase(extension) +"/view.jsp", "wikitty", w, "extensions", exts); - } - public Render edit(ChoremClient client, String id, String[] extension, Call call) { log.debug("edit: " + id); // on preload rien, le preload sera fait a la fin @@ -476,47 +463,6 @@ return renderView("edit.jsp", "wikitty", w, "extensions", exts); } - - // A SUPPRIMER, ne sert a rien, pas la bonne methode (pour reordonner les champs) -// /** -// * Edit une extension et les extensions requisent de l'objet -// * -// * @param client -// * @param id -// * @param extension -// * @param call -// * @return -// */ -// public Render extensionEdit(ChoremClient client, String id, String extension, Call call) { -// log.debug("edit: " + id); -// Wikitty w = client.restore(id, ".*"); -// -// if (w == null) { -// w = new WikittyImpl(); -// } -// -// LinkedHashSet<WikittyExtension> exts = new LinkedHashSet<WikittyExtension>(); -// -// // If extension is not null, load all required extensions too -// List<String> extensionNames = Arrays.asList(extension); -// List<WikittyExtension> newExts = -// client.restoreExtensionAndDependenciesLastVesion(extensionNames); -// w.addExtension(newExts); -// -// // As we want to edit a wikitty by its extensions, we should edit the required extensions too -// // Add the extension and required ones in the list of extensions to display -// exts.addAll(newExts); -// -// // si des nouvelles valeurs sont en parametre, on change les valeurs -// // actuel du wikitty -// Map<String, Object> params = call.getExtractParameters(); -// String error = setWikittyField(w, params); -// -// getContext().addInfoMessage("message", "Warning: Can't put some value in object" + error); -// -// return renderView(StringUtils.lowerCase(extension) + "/edit.jsp", "wikitty", w); -// } - public Render save(ChoremClient client, String id, String[] extension, Call call) { log.debug("save: " + id); Wikitty w = client.restore(id);
participants (1)
-
bpoussin@users.chorem.org