From: David ‘Bombe’ Roden Date: Sat, 25 Jul 2015 16:09:56 +0000 (+0200) Subject: Parse album descriptions after editing X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a073898124dfcd550299c1f6ef707ee399bce270;p=Sone.git Parse album descriptions after editing --- diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index c1fae80..974299d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -726,7 +726,7 @@ public class WebInterface { pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumAjaxPage(this, parserFilter, renderFilter))); pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this, parserFilter, renderFilter))); pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustAjaxPage(this))); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java index 570d027..6fe06bc 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java @@ -17,12 +17,20 @@ package net.pterodactylus.sone.web.ajax; +import java.util.Collections; + import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.template.ParserFilter; +import net.pterodactylus.sone.template.RenderFilter; +import net.pterodactylus.sone.text.Part; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; +import net.pterodactylus.util.template.TemplateContext; import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; /** * Page that stores a user’s album modifications. @@ -31,14 +39,13 @@ import com.google.common.base.Optional; */ public class EditAlbumAjaxPage extends JsonPage { - /** - * Creates a new edit album AJAX page. - * - * @param webInterface - * The Sone web interface - */ - public EditAlbumAjaxPage(WebInterface webInterface) { + private final ParserFilter parserFilter; + private final RenderFilter renderFilter; + + public EditAlbumAjaxPage(WebInterface webInterface, ParserFilter parserFilter, RenderFilter renderFilter) { super("editAlbum.ajax", webInterface); + this.parserFilter = parserFilter; + this.renderFilter = renderFilter; } // @@ -73,10 +80,16 @@ public class EditAlbumAjaxPage extends JsonPage { try { album.get().modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update(); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("albumId", album.get().getId()).put("title", album.get().getTitle()).put("description", album.get().getDescription()); + return createSuccessJsonObject().put("albumId", album.get().getId()).put("title", album.get().getTitle()).put("description", parseDescription(album.get())); } catch (IllegalStateException e) { return createErrorJsonObject("invalid-album-title"); } } + private String parseDescription(Album album) { + Iterable parts = (Iterable) parserFilter.format(new TemplateContext(), album.getDescription(), + ImmutableMap.builder().put("sone", album.getSone()).build()); + return (String) renderFilter.format(new TemplateContext(), parts, Collections.emptyMap()); + } + } diff --git a/src/main/resources/templates/imageBrowser.html b/src/main/resources/templates/imageBrowser.html index d399862..a237c7f 100644 --- a/src/main/resources/templates/imageBrowser.html +++ b/src/main/resources/templates/imageBrowser.html @@ -244,7 +244,7 @@ var albumDescriptionField = getAlbum(data.albumId).find(".album-description"); if (data.success) { albumTitleField.text(data.title); - albumDescriptionField.text(data.description); + albumDescriptionField.html(data.description); getAlbum(data.albumId).find(":input[name='title']").attr("defaultValue", title); getAlbum(data.albumId).find(":input[name='description']").attr("defaultValue", description); } else {