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)));
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.
*/
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;
}
//
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());
+ }
+
}