Parse descriptions of albums and images.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Nov 2011 10:54:34 +0000 (11:54 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Nov 2011 10:54:34 +0000 (11:54 +0100)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java
src/main/resources/templates/imageBrowser.html
src/main/resources/templates/include/browseAlbums.html

index 7320ad5..4c41581 100644 (file)
@@ -170,6 +170,9 @@ public class WebInterface implements CoreListener {
        /** The Sone text parser. */
        private final SoneTextParser soneTextParser;
 
+       /** The parser filter. */
+       private final ParserFilter parserFilter;
+
        /** The “new Sone” notification. */
        private final ListNotification<Sone> newSoneNotification;
 
@@ -242,7 +245,7 @@ public class WebInterface implements CoreListener {
                templateContextFactory.addFilter("match", new MatchFilter());
                templateContextFactory.addFilter("css", new CssClassNameFilter());
                templateContextFactory.addFilter("js", new JavascriptFilter());
-               templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory, soneTextParser));
+               templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), templateContextFactory, soneTextParser));
                templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
                templateContextFactory.addFilter("format", new FormatFilter());
                templateContextFactory.addFilter("sort", new CollectionSortFilter());
@@ -668,7 +671,7 @@ public class WebInterface implements CoreListener {
                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 EditImageAjaxPage(this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this, parserFilter)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustAjaxPage(this)));
index 3bef432..3c4de8e 100644 (file)
 package net.pterodactylus.sone.web.ajax;
 
 import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.template.ParserFilter;
 import net.pterodactylus.sone.text.TextFilter;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.MapBuilder;
 import net.pterodactylus.util.json.JsonObject;
+import net.pterodactylus.util.template.TemplateContext;
 
 /**
  * Page that stores a user’s image modifications.
@@ -30,14 +33,20 @@ import net.pterodactylus.util.json.JsonObject;
  */
 public class EditImageAjaxPage extends JsonPage {
 
+       /** Parser for image descriptions. */
+       private final ParserFilter parserFilter;
+
        /**
         * Creates a new edit image AJAX page.
         *
         * @param webInterface
         *            The Sone web interface
+        * @param parserFilter
+        *            The parser filter for image descriptions
         */
-       public EditImageAjaxPage(WebInterface webInterface) {
+       public EditImageAjaxPage(WebInterface webInterface, ParserFilter parserFilter) {
                super("editImage.ajax", webInterface);
+               this.parserFilter = parserFilter;
        }
 
        //
@@ -71,7 +80,7 @@ public class EditImageAjaxPage extends JsonPage {
                String description = request.getHttpRequest().getParam("description").trim();
                image.setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description));
                webInterface.getCore().touchConfiguration();
-               return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription());
+               return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()).put("parsedDescription", (String) parserFilter.format(new TemplateContext(), image.getDescription(), new MapBuilder<String, String>().put("sone", image.getSone().getId()).get()));
        }
 
 }
index d97fc25..1da99ff 100644 (file)
                                                ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "title": title, "description": description }, function(data) {
                                                        if (data && data.success) {
                                                                getImage(data.imageId).find(".image-title").text(data.title);
-                                                               getImage(data.imageId).find(".image-description").text(data.description);
+                                                               getImage(data.imageId).find(".image-description").html(data.parsedDescription);
                                                                getImage(data.imageId).find(":input[name='title']").attr("defaultValue", title);
-                                                               getImage(data.imageId).find(":input[name='description']").attr("defaultValue", description);
+                                                               getImage(data.imageId).find(":input[name='description']").attr("defaultValue", data.description);
                                                                cancelImageEditing();
                                                        }
                                                });
                                <%/foreach>
                        </div>
 
-                       <p id="description"><% album.description|html></p>
+                       <p id="description"><% album.description|parse sone=album.sone></p>
 
                        <%if album.sone.local>
                                <div class="show-edit-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
                                        </div>
                                        <div class="show-data">
                                                <div class="image-title"><% image.title|html></div>
-                                               <div class="image-description"><% image.description|html></div>
+                                               <div class="image-description"><% image.description|parse sone=image.sone></div>
                                        </div>
                                        <%if album.sone.local>
                                                <form class="edit-image" action="editImage.html" method="post">
index d925a3c..1fddebd 100644 (file)
@@ -14,7 +14,7 @@
                </div>
                <div class="show-data">
                        <div class="album-title"><% album.title|html> (<%= View.Sone.Stats.Images|l10n 0=album.images.size>)</div>
-                       <div class="album-description"><% album.description|html></div>
+                       <div class="album-description"><% album.description|parse sone=album.sone></div>
                </div>
                <%if album.sone.local>
                        <form class="edit-album" action="editAlbum.html" method="post">