Author: ymartel Date: 2012-06-05 17:25:22 +0200 (Tue, 05 Jun 2012) New Revision: 177 Url: http://chorem.org/repositories/revision/chorem/177 Log: be abel to add an attachment for a wikitty Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java trunk/chorem-webmotion/src/main/resources/mapping trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.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-06-05 13:54:15 UTC (rev 176) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java 2012-06-05 15:25:22 UTC (rev 177) @@ -1,15 +1,6 @@ package org.chorem.webmotion.actions; import com.google.common.collect.LinkedHashMultimap; -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; @@ -17,6 +8,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.ChoremClient; import org.chorem.ChoremConfigOption; +import org.chorem.entities.Attachment; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.UploadFile; @@ -32,6 +24,16 @@ import org.nuiton.wikitty.query.WikittyQueryParser; import org.nuiton.wikitty.query.WikittyQueryResult; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; + /** * * @author poussin @@ -389,6 +391,30 @@ return renderView("edit.jsp", "wikitty", w, "extensions", exts); } + public Render addAttachment(ChoremClient client, String wikittyId) { + log.debug("add attachment for : " + wikittyId); + Wikitty w = client.restore(wikittyId, ".*"); + + Wikitty attachment = new WikittyImpl(); + + LinkedHashSet<WikittyExtension> exts = new LinkedHashSet<WikittyExtension>(); + + // Load Attachment extension, and potential dependencies + List<String> extensionNames = Arrays.asList(Attachment.EXT_ATTACHMENT); + List<WikittyExtension> newExts = + client.restoreExtensionAndDependenciesLastVesion(extensionNames); + attachment.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); + // Show all wikitty if no extension were mentioned + exts.addAll(attachment.getExtensions()); + + attachment.setField(Attachment.EXT_ATTACHMENT, Attachment.FIELD_ATTACHMENT_TARGET, w); + return renderView("edit.jsp", "wikitty", attachment, "extensions", exts); + } + public Render save(ChoremClient client, String id, String[] extension, Call call) { log.debug("save: " + id); Wikitty w = client.restore(id); Modified: trunk/chorem-webmotion/src/main/resources/mapping =================================================================== --- trunk/chorem-webmotion/src/main/resources/mapping 2012-06-05 13:54:15 UTC (rev 176) +++ trunk/chorem-webmotion/src/main/resources/mapping 2012-06-05 15:25:22 UTC (rev 177) @@ -16,6 +16,7 @@ * /wikitty/{extension}/search action:GenericAction.search * /wikitty/{extension}/view/{id} action:GenericAction.view * /wikitty/{extension}/edit/{id} action:GenericAction.edit +* /wikitty/{wikittyId}/Attachment/edit/new action:GenericAction.addAttachment * /wikitty/{extension}/delete/{id} action:GenericAction.delete * /wikitty/search action:GenericAction.search * /wikitty/searchRelated?id={query} action:GenericAction.search Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp 2012-06-05 13:54:15 UTC (rev 176) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp 2012-06-05 15:25:22 UTC (rev 177) @@ -20,6 +20,14 @@ </dl> </c:forEach> +<p> + <c:if test="${not empty wikitty}"> + <p> + <a class="btn btn-success" href="<c:url value="/wikitty/${wikitty.id}/Attachment/edit/new"/>"><i class="icon-plus icon-white"></i> Add Attachment</a> + </p> + </c:if> +</p> + <div class="container"> <jsp:include page="/wikitty/searchRelated?id=${wikitty.id}"/> <%--