From: <udi...@us...> - 2021-09-16 09:11:48
|
Revision: 1391 http://sourceforge.net/p/j-trac/code/1391 Author: udittmer Date: 2021-09-16 09:11:45 +0000 (Thu, 16 Sep 2021) Log Message: ----------- make new attachment behavior configurable Modified Paths: -------------- trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.html trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.java trunk/jtrac/src/main/resources/messages.properties trunk/jtrac/src/main/resources/messages_de.properties Modified: trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.html =================================================================== --- trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.html 2021-09-16 07:18:08 UTC (rev 1390) +++ trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.html 2021-09-16 09:11:45 UTC (rev 1391) @@ -1,6 +1,4 @@ <wicket:panel> - <!-- - <span wicket:id="attachment"><a href="#" target="_blank"><img src="resources/attachment.gif" class="nav-link"/><span wicket:id="fileName"></span></a></span> - --> - <a wicket:id="attachment" href="#" target="_blank"><img src="resources/attachment.gif" class="nav-link"/><span wicket:id="fileName"></span></a> + <span id="oldStyle"><span wicket:id="attachment"><a href="#" target="_blank"><img src="resources/attachment.gif" class="nav-link"/><span wicket:id="fileName"></span></a></span></span> + <span id="newStyle"><a wicket:id="attachment" href="#" target="_blank"><img src="resources/attachment.gif" class="nav-link"/><span wicket:id="fileName"></span></a></span> </wicket:panel> Modified: trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.java =================================================================== --- trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.java 2021-09-16 07:18:08 UTC (rev 1390) +++ trunk/jtrac/src/main/java/info/jtrac/wicket/AttachmentLinkPanel.java 2021-09-16 09:11:45 UTC (rev 1391) @@ -25,9 +25,12 @@ import java.io.IOException; import java.io.InputStream; +import org.springframework.util.StringUtils; + import org.apache.wicket.IRequestTarget; import org.apache.wicket.RequestCycle; import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.internal.HtmlHeaderContainer; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.protocol.http.WebResponse; import org.apache.wicket.util.io.Streams; @@ -51,6 +54,7 @@ Link link = new Link("attachment") { // adapted from wicket.markup.html.link.DownloadLink // with the difference that the File is instantiated only after onClick + @Override public void onClick() { getRequestCycle().setRequestTarget(new IRequestTarget() { @@ -61,14 +65,17 @@ public void respond (RequestCycle requestCycle) { WebResponse r = (WebResponse) requestCycle.getResponse(); String fileType = AttachmentUtils.guessFileType(attachment, getJtrac().getJtracHome()); - System.out.println(fileType); - if (fileType != null && (fileType.startsWith("image") || fileType.startsWith("text"))) { - r.setHeader("Content-Disposition", "inline; filename="+fileName); + if (openNewWindow()) { + if (fileType != null && (fileType.startsWith("image") || fileType.startsWith("text"))) { + r.setHeader("Content-Disposition", "inline; filename="+fileName); + //r.setInlineHeader(fileName); + // not available in Wicket 1.3.7 + } else { + r.setAttachmentHeader(fileName); + } } else { r.setAttachmentHeader(fileName); } - //r.setInlineHeader(fileName); - // not available in Wicket 1.3.7 try { File file = AttachmentUtils.getFile(attachment, getJtrac().getJtracHome()); InputStream is = new FileInputStream(file); @@ -89,10 +96,27 @@ } }); } + + @Override + public void renderHead (HtmlHeaderContainer container) { + if (openNewWindow()) { + container.getHeaderResponse().renderString("<style>#oldStyle { display: none; } #newStyle { display: inline}</style>"); + } else { + container.getHeaderResponse().renderString("<style>#oldStyle { display: inline; } #newStyle { display: none}</style>"); + } + } }; link.add(new Label("fileName", fileName)); add(link); } - + + protected boolean openNewWindow() { + String openNewWindow = getJtrac().loadConfig("attachments.openNewWindow"); + if (StringUtils.hasText(openNewWindow)) { + return openNewWindow.trim().equalsIgnoreCase("true"); + } else { + return false; + } + } } Modified: trunk/jtrac/src/main/resources/messages.properties =================================================================== --- trunk/jtrac/src/main/resources/messages.properties 2021-09-16 07:18:08 UTC (rev 1390) +++ trunk/jtrac/src/main/resources/messages.properties 2021-09-16 09:11:45 UTC (rev 1391) @@ -205,6 +205,7 @@ config.pwd.minLength = Minimal length of passwords (default is 8) config.time.pretty = Show relative timestamps as on Github, Twitter and Facebook (set to true, default is false) config.urls.autolink = Auto-link URLs in tickets and comments (set to true, default is false) +config.attachments.openNewWindow = Open text and image attachments in a new tab/window, rather than downloading them # config_list (config_form does not have any extra messages) config_list.configurationSettings = Configuration Settings Modified: trunk/jtrac/src/main/resources/messages_de.properties =================================================================== --- trunk/jtrac/src/main/resources/messages_de.properties 2021-09-16 07:18:08 UTC (rev 1390) +++ trunk/jtrac/src/main/resources/messages_de.properties 2021-09-16 09:11:45 UTC (rev 1391) @@ -205,6 +205,7 @@ config.pwd.minLength = Minimale L\u00e4nge von Passw\u00f6rtern (Default 8) config.time.pretty = Relative Zeiten anzeigen wie auf Github, Twitter und Facebook (auf true setzen, Default ist false) config.urls.autolink = URLs in Tickets und Kommentaren automatisch verlinken (auf true setzen, Default ist false) +config.attachments.openNewWindow = Text- und Bild-Anh\u00e4nge in neuem Fenster \u00f6ffnen statt sie herunterzuladen # config_list (config_form does not have any extra messages) config_list.configurationSettings = Einstellungen This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |