Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
+ Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetSoneStatusPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
package net.pterodactylus.sone.web.ajax;
+import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.json.JsonObject;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateException;
/**
* This AJAX page returns the details of a reply.
/** Date formatter. */
private static final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy, HH:mm:ss");
+ /** The template to render. */
+ private final Template replyTemplate;
+
/**
* Creates a new “get reply” page.
*
* @param webInterface
+ * The Sone web interface
+ * @param replyTemplate
+ * The template to render
*/
- public GetReplyAjaxPage(WebInterface webInterface) {
+ public GetReplyAjaxPage(WebInterface webInterface, Template replyTemplate) {
super("ajax/getReply.ajax", webInterface);
+ this.replyTemplate = replyTemplate;
}
//
if ((reply == null) || (reply.getSone() == null)) {
return createErrorJsonObject("invalid-reply-id");
}
+ replyTemplate.set("reply", reply);
+ replyTemplate.set("currentSone", getCurrentSone(request.getToadletContext()));
+ StringWriter templateWriter = new StringWriter();
+ try {
+ replyTemplate.render(templateWriter);
+ } catch (TemplateException te1) {
+ /* TODO - shouldn’t happen. */
+ } finally {
+ Closer.close(templateWriter);
+ }
synchronized (dateFormat) {
- return new JsonObject().put("success", true).put("sone-id", reply.getSone().getId()).put("sone-name", SoneAccessor.getNiceName(reply.getSone())).put("time", reply.getTime()).put("display-time", dateFormat.format(new Date(reply.getTime()))).put("text", reply.getText());
+ return new JsonObject().put("success", true).put("soneId", reply.getSone().getId()).put("soneName", SoneAccessor.getNiceName(reply.getSone())).put("time", reply.getTime()).put("displayTime", dateFormat.format(new Date(reply.getTime()))).put("text", reply.getText()).put("html", templateWriter.toString());
}
}