From 1443715f27869721c8ff82b8c3d0f959b5c4aaae Mon Sep 17 00:00:00 2001
From: gnaegi <none@none>
Date: Fri, 18 Sep 2015 15:22:36 +0200
Subject: [PATCH] OO-1693 beautify lti talk back message at end of module

---
 .../nodes/basiclti/LTIRunController.java      |  2 +-
 .../course/nodes/basiclti/_content/run.html   |  2 +-
 .../org/olat/ims/lti/ui/TalkBackMapper.java   | 55 ++++++++++++++++---
 .../lti/ui/_i18n/LocalStrings_de.properties   |  6 ++
 .../lti/ui/_i18n/LocalStrings_en.properties   |  9 ++-
 5 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/olat/course/nodes/basiclti/LTIRunController.java b/src/main/java/org/olat/course/nodes/basiclti/LTIRunController.java
index 4bd592521e7..4e090648eaf 100644
--- a/src/main/java/org/olat/course/nodes/basiclti/LTIRunController.java
+++ b/src/main/java/org/olat/course/nodes/basiclti/LTIRunController.java
@@ -403,7 +403,7 @@ public class LTIRunController extends BasicController {
 		container.contextPut("sourcedId", sourcedId);
 		OLATResource courseResource = courseEnv.getCourseGroupManager().getCourseResource();
 		
-		Mapper talkbackMapper = new TalkBackMapper();
+		Mapper talkbackMapper = new TalkBackMapper(getLocale(), getWindowControl().getWindowBackOffice().getWindow().getGuiTheme().getBaseURI());
 		String backMapperUrl = registerCacheableMapper(ureq, sourcedId + "_talkback", talkbackMapper);
 		String backMapperUri = serverUri + backMapperUrl + "/";
 
diff --git a/src/main/java/org/olat/course/nodes/basiclti/_content/run.html b/src/main/java/org/olat/course/nodes/basiclti/_content/run.html
index fbfdb13620d..399ce10b2b0 100644
--- a/src/main/java/org/olat/course/nodes/basiclti/_content/run.html
+++ b/src/main/java/org/olat/course/nodes/basiclti/_content/run.html
@@ -8,7 +8,7 @@
 	</div>
 #end
 <div class="o_iframedisplay">
-	<iframe id="IMSBasicLTIFrame" src="${mapperUri}?$r.uuid"  marginwidth="0" marginheight="0" #if($width!='auto') width="${width}px" #end height="#if($height!='auto')${height}#else 400#{end}px" style="#if($width!='auto') width:${width}px;#end #if($height!='auto')height:${height}px;#{end}"></iframe>
+	<iframe id="IMSBasicLTIFrame" src="${mapperUri}?$r.uuid"  marginwidth="0" marginheight="0" #if($width!='auto') width="${width}px" #end height="#if($height!='auto')${height}#else 400#{end}px" frameborder="0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" style="#if($width!='auto') width:${width}px;#end #if($height!='auto')height:${height}px;#{end}"></iframe>
 </div>
 #if(!$height || 'auto' == $height)
 	<script type="text/javascript">
diff --git a/src/main/java/org/olat/ims/lti/ui/TalkBackMapper.java b/src/main/java/org/olat/ims/lti/ui/TalkBackMapper.java
index 693bd934659..55fcdb0f7b0 100644
--- a/src/main/java/org/olat/ims/lti/ui/TalkBackMapper.java
+++ b/src/main/java/org/olat/ims/lti/ui/TalkBackMapper.java
@@ -20,12 +20,19 @@
 package org.olat.ims.lti.ui;
 
 import java.io.Serializable;
+import java.util.Locale;
 
 import javax.servlet.http.HttpServletRequest;
 
 import org.olat.core.dispatcher.mapper.Mapper;
 import org.olat.core.gui.media.MediaResource;
+import org.olat.core.gui.media.ServletUtil;
 import org.olat.core.gui.media.StringMediaResource;
+import org.olat.core.gui.translator.Translator;
+import org.olat.core.logging.OLog;
+import org.olat.core.logging.Tracing;
+import org.olat.core.util.StringHelper;
+import org.olat.core.util.Util;
 
 /**
  * 
@@ -36,18 +43,52 @@ import org.olat.core.gui.media.StringMediaResource;
 public class TalkBackMapper implements Mapper, Serializable {
 
 	private static final long serialVersionUID = -8319259842325597955L;
+	private static final OLog log = Tracing.createLoggerFor(TalkBackMapper.class);
+	
+	private Translator trans;
+	private String themeBaseUri;
 
+	public TalkBackMapper(Locale loc, String themeBaseUri) {
+		this.trans = Util.createPackageTranslator(this.getClass(), loc);		
+		this.themeBaseUri = themeBaseUri;
+	}
+	
 	@Override
 	public MediaResource handle(String relPath, HttpServletRequest request) {	
 		StringMediaResource mediares = new StringMediaResource();
 		StringBuilder sb = new StringBuilder();
-		sb.append("<html><head><title>").append("LTI talk back").append("</title></head><body>")
-		  .append("lti_msg: ").append(request.getParameter("lti_msg")).append("<br/>")
-		  .append("lti_errormsg: ").append(request.getParameter("lti_errormsg")).append("<br/>")
-		  .append("lti_log: ").append(request.getParameter("lti_log")).append("<br/>")
-		  .append("lti_errorlog: ").append(request.getParameter("lti_errorlog")).append("<br/>")
-		  .append("</body></html>");
-		//ServletUtil.printOutRequestParameter(request);
+		sb.append("<html><head>")
+			.append("\n<link rel=\"stylesheet\" type=\"text/css\" id=\"ocontentcss\" href=\"").append(themeBaseUri).append("content.css\" />\n")
+			.append("<title>").append(trans.translate("talkback.title")).append("</title></head><body>")
+			.append("<div class='o_lti_talkback'>")
+			.append("<h1>").append(trans.translate("talkback.title")).append("</h1>")
+			.append("<p class='o_info'>").append(trans.translate("talkback.info")).append("</p>");
+		String lti_msg = request.getParameter("lti_msg");
+		if (StringHelper.containsNonWhitespace(lti_msg)) {
+			sb.append("<div class='o_note'><h3>").append(trans.translate("talkback.msg")).append("</h3><p>")
+				.append(request.getParameter("lti_msg")).append("</p></div>");			
+		}
+		String lti_errormsg = request.getParameter("lti_errormsg");
+		if (StringHelper.containsNonWhitespace(lti_errormsg)) {
+			sb.append("<div class='o_error'><h3>").append(trans.translate("talkback.errormsg")).append("</h3><p>")
+				.append(lti_errormsg).append("</p></div>");			
+		}
+		String lti_log = request.getParameter("lti_log");
+		if (StringHelper.containsNonWhitespace(lti_log)) {
+			sb.append("<h3>").append(trans.translate("talkback.log")).append("</h3><pre>\n")
+				.append(lti_log).append("\n</pre>");			
+		}
+		String lti_errorlog = request.getParameter("lti_errorlog");
+		if (StringHelper.containsNonWhitespace(lti_errorlog)) {
+			sb.append("<h3>").append(trans.translate("talkback.errorlog")).append("</h3><pre>\n")
+				.append(lti_errorlog).append("\n</pre>");			
+		}
+		sb.append("</div></body></html>");
+		
+		if (log.isDebug()) {
+			ServletUtil.printOutRequestParameters(request);
+			
+		}
 		mediares.setData(sb.toString());
 		mediares.setContentType("text/html");
 		mediares.setEncoding("UTF-8");
diff --git a/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_de.properties
index eb2d274839a..036060e290c 100644
--- a/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_de.properties
@@ -3,3 +3,9 @@ table.header.action=Aktion
 table.header.key=Key
 table.header.value=Wert
 
+talkback.title=Abschluss Lernmodul
+talkback.info=Sie sind zurück vom Lernmodul. Das Lernmodul hat die folgenden Informationen bereitgestellt:
+talkback.msg=Mitteilung
+talkback.errormsg=Fehlermeldung
+talkback.log=Protokoll
+talkback.errorlog=Fehlerprotokoll
diff --git a/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_en.properties
index f1663d4735d..4394702a8e8 100644
--- a/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_en.properties
+++ b/src/main/java/org/olat/ims/lti/ui/_i18n/LocalStrings_en.properties
@@ -1,4 +1,11 @@
 table.header.date=Date
 table.header.action=Action
 table.header.key=Key
-table.header.value=Value
\ No newline at end of file
+table.header.value=Value
+
+talkback.title=Learning module finished
+talkback.info=You are back from the learning module. The learning module delivered the following information:
+talkback.msg=Message
+talkback.errormsg=Error message
+talkback.log=Log
+talkback.errorlog=Error log
-- 
GitLab