Parse album descriptions after editing
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 25 Jul 2015 16:09:56 +0000 (18:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 25 Jul 2015 16:09:56 +0000 (18:09 +0200)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java
src/main/resources/templates/imageBrowser.html

index c1fae80..974299d 100644 (file)
@@ -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)));
index 570d027..6fe06bc 100644 (file)
 
 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<Part> parts = (Iterable<Part>) parserFilter.format(new TemplateContext(), album.getDescription(),
+                               ImmutableMap.<String, Object>builder().put("sone", album.getSone()).build());
+               return (String) renderFilter.format(new TemplateContext(), parts, Collections.<String, Object>emptyMap());
+       }
+
 }
index d399862..a237c7f 100644 (file)
                                 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 {