@Override
public Album update() throws IllegalStateException {
+ if (title.isPresent() && title.get().trim().isEmpty()) {
+ throw new AlbumTitleMustNotBeEmpty();
+ }
if (title.isPresent()) {
AlbumImpl.this.title = title.get();
}
};
}
+ public static class AlbumTitleMustNotBeEmpty extends IllegalStateException { }
+
//
// FINGERPRINTABLE METHODS
//
package net.pterodactylus.sone.web;
import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.AlbumImpl.AlbumTitleMustNotBeEmpty;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.text.TextFilter;
import net.pterodactylus.sone.web.page.FreenetRequest;
parent = currentSone.getRootAlbum();
}
Album album = webInterface.getCore().createAlbum(currentSone, parent);
- album.modify().setTitle(name).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
+ try {
+ album.modify().setTitle(name).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
+ } catch (AlbumTitleMustNotBeEmpty atmnbe) {
+ throw new RedirectException("emptyAlbumTitle.html");
+ }
webInterface.getCore().touchConfiguration();
throw new RedirectException("imageBrowser.html?album=" + album.getId());
}
package net.pterodactylus.sone.web;
import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.AlbumImpl.AlbumTitleMustNotBeEmpty;
import net.pterodactylus.sone.text.TextFilter;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Template;
}
album.modify().setAlbumImage(albumImageId).update();
String title = request.getHttpRequest().getPartAsStringFailsafe("title", 100).trim();
- if (title.length() == 0) {
- templateContext.set("titleMissing", true);
- return;
- }
String description = request.getHttpRequest().getPartAsStringFailsafe("description", 1000).trim();
- album.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
+ try {
+ album.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
+ } catch (AlbumTitleMustNotBeEmpty atmnbe) {
+ throw new RedirectException("emptyAlbumTitle.html");
+ }
webInterface.getCore().touchConfiguration();
throw new RedirectException("imageBrowser.html?album=" + album.getId());
}
Template deleteImageTemplate = parseTemplate("/templates/deleteImage.html");
Template noPermissionTemplate = parseTemplate("/templates/noPermission.html");
Template emptyImageTitleTemplate = parseTemplate("/templates/emptyImageTitle.html");
+ Template emptyAlbumTitleTemplate = parseTemplate("/templates/emptyAlbumTitle.html");
Template optionsTemplate = parseTemplate("/templates/options.html");
Template rescueTemplate = parseTemplate("/templates/rescue.html");
Template aboutTemplate = parseTemplate("/templates/about.html");
pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", emptyImageTitleTemplate, "Page.EmptyImageTitle.Title", this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("css/", "/static/css/", "text/css")));
}
String title = request.getHttpRequest().getParam("title").trim();
String description = request.getHttpRequest().getParam("description").trim();
- album.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
- webInterface.getCore().touchConfiguration();
- return createSuccessJsonObject().put("albumId", album.getId()).put("title", album.getTitle()).put("description", album.getDescription());
+ try {
+ album.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
+ webInterface.getCore().touchConfiguration();
+ return createSuccessJsonObject().put("albumId", album.getId()).put("title", album.getTitle()).put("description", album.getDescription());
+ } catch (IllegalStateException e) {
+ return createErrorJsonObject("invalid-album-title");
+ }
}
}
Page.EmptyImageTitle.Page.Title=Title Must Not Be Empty
Page.EmptyImageTitle.Text.EmptyImageTitle=You have to give your image a title. Please go back to the previous page and enter a title.
+Page.EmptyAlbumTitle.Title=Title Must Not Be Empty - Sone
+Page.EmptyAlbumTitle.Page.Title=Title Must Not Be Empty
+Page.EmptyAlbumTitle.Text.EmptyAlbumTitle=You have to give your album a title. Please go back to the previous page and enter a title.
+
Page.DismissNotification.Title=Dismiss Notification - Sone
Page.WotPluginMissing.Text.WotRequired=Because the Web of Trust is an integral part of Sone, the Web of Trust plugin has to be loaded in order to run Sone.
--- /dev/null
+<%include include/head.html>
+
+ <h1><%= Page.EmptyAlbumTitle.Page.Title|l10n|html></h1>
+
+ <p><%= Page.EmptyAlbumTitle.Text.EmptyAlbumTitle|l10n|html></p>
+
+<%include include/tail.html>
title = $(":input[name='title']:enabled", this.form).val();
description = $(":input[name='description']:enabled", this.form).val();
ajaxGet("editAlbum.ajax", { "formPassword": getFormPassword(), "album": albumId, "title": title, "description": description }, function(data) {
- if (data && data.success) {
- getAlbum(data.albumId).find(".album-title").text(data.title);
- getAlbum(data.albumId).find(".album-description").text(data.description);
- getAlbum(data.albumId).find(":input[name='title']").attr("defaultValue", title);
- getAlbum(data.albumId).find(":input[name='description']").attr("defaultValue", description);
- cancelAlbumEditing();
- }
+ if (data) {
+ var albumTitleField = getAlbum(data.albumId).find(".album-title");
+ var albumDescriptionField = getAlbum(data.albumId).find(".album-description");
+ if (data.success) {
+ albumTitleField.text(data.title);
+ albumDescriptionField.text(data.description);
+ getAlbum(data.albumId).find(":input[name='title']").attr("defaultValue", title);
+ getAlbum(data.albumId).find(":input[name='description']").attr("defaultValue", description);
+ } else {
+ albumTitleField.attr("value", albumTitleField.attr("defaultValue"));
+ albumDescriptionField.attr("value", albumDescriptionField.attr("defaultValue"));
+ }
+ cancelAlbumEditing();
+ }
});
return false;
});