Add confirmation for image deletion.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 04:36:01 +0000 (06:36 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 04:41:30 +0000 (06:41 +0200)
src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/deleteImage.html [new file with mode: 0644]
src/main/resources/templates/imageBrowser.html

index 84222ee..999a38a 100644 (file)
@@ -51,18 +51,22 @@ public class DeleteImagePage extends SoneTemplatePage {
        @Override
        protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
+               String imageId = (request.getMethod() == Method.POST) ? request.getHttpRequest().getPartAsStringFailsafe("image", 36) : request.getHttpRequest().getParam("image");
+               Image image = webInterface.getCore().getImage(imageId, false);
+               if (image == null) {
+                       throw new RedirectException("invalid.html");
+               }
+               if (!webInterface.getCore().isLocalSone(image.getSone())) {
+                       throw new RedirectException("noPermission.html");
+               }
                if (request.getMethod() == Method.POST) {
-                       String imageId = request.getHttpRequest().getPartAsStringFailsafe("image", 36);
-                       Image image = webInterface.getCore().getImage(imageId, false);
-                       if (image == null) {
-                               throw new RedirectException("invalid.html");
-                       }
-                       if (!webInterface.getCore().isLocalSone(image.getSone())) {
-                               throw new RedirectException("noPermission.html");
+                       if (request.getHttpRequest().isPartSet("abortDelete")) {
+                               throw new RedirectException("imageBrowser.html?image=" + image.getId());
                        }
                        webInterface.getCore().deleteImage(image);
                        throw new RedirectException("imageBrowser.html?album=" + image.getAlbum().getId());
                }
+               templateContext.set("image", image);
        }
 
 }
index 7ad32fd..376ff09 100644 (file)
@@ -556,6 +556,7 @@ public class WebInterface implements CoreListener {
                Template imageBrowserTemplate = TemplateParser.parse(createReader("/templates/imageBrowser.html"));
                Template createAlbumTemplate = TemplateParser.parse(createReader("/templates/createAlbum.html"));
                Template deleteAlbumTemplate = TemplateParser.parse(createReader("/templates/deleteAlbum.html"));
+               Template deleteImageTemplate = TemplateParser.parse(createReader("/templates/deleteImage.html"));
                Template noPermissionTemplate = TemplateParser.parse(createReader("/templates/noPermission.html"));
                Template optionsTemplate = TemplateParser.parse(createReader("/templates/options.html"));
                Template aboutTemplate = TemplateParser.parse(createReader("/templates/about.html"));
@@ -588,7 +589,7 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteAlbumPage(deleteAlbumTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UploadImagePage(invalidTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImagePage(emptyTemplate, this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteImagePage(emptyTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteImagePage(deleteImageTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustPage(emptyTemplate, this)));
index b112f72..a5ab0c1 100644 (file)
@@ -182,7 +182,13 @@ Page.UploadImage.Title=Upload Image - Sone
 Page.UploadImage.Error.InvalidImage=The image you were trying to upload could not be recognized. Please upload only JPEG (*.jpg or *.jpeg), or PNG (*.png) images.
 
 Page.EditImage.Title=Edit Image
+
 Page.DeleteImage.Title=Delete Image
+Page.DeleteImage.Page.Title=Delete Image
+Page.DeleteImage.Text.ImageWillBeGone=This will remove the image “{image}” from your album “{album}”. If it has already been inserted into Freenet it can not be removed from there forcefully. Do you want to do delete the image?
+Page.DeleteImage.Button.Yes=Yes, delete image.
+Page.DeleteImage.Button.No=No, don’t delete image.
+
 Page.EditAlbum.Title=Edit Album
 
 Page.DeleteAlbum.Title=Delete Album
diff --git a/src/main/resources/templates/deleteImage.html b/src/main/resources/templates/deleteImage.html
new file mode 100644 (file)
index 0000000..68b403e
--- /dev/null
@@ -0,0 +1,14 @@
+<%include include/head.html>
+
+       <h1><%= Page.DeleteImage.Page.Title|l10n|html></h1>
+
+       <p><%= Page.DeleteImage.Text.ImageWillBeGone|l10n|replace needle="{image}" replacementKey=image.title|replace needle="{album}" replacementKey=image.album.title|html></p>
+
+       <form method="post">
+               <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+               <input type="hidden" name="image" value="<%image.id|html>" />
+               <button type="submit" name="confirmDelete" value="1"><%= Page.DeleteImage.Button.Yes|l10n|html></button>
+               <button type="submit" name="abortDelete" value="1"><%= Page.DeleteImage.Button.No|l10n|html></button>
+       </form>
+
+<%include include/tail.html>
index 6faea11..9bcaa9d 100644 (file)
 
                                <h2><%= Page.ImageBrowser.Image.Delete.Title|l10n|html></h2>
 
-                               <form id="delete-image" action="deleteImage.html" method="post">
-                                       <input type="hidden" name="formPassword" value="<%formPassword|html>" />
+                               <form id="delete-image" action="deleteImage.html" method="get">
                                        <input type="hidden" name="image" value="<%image.id|html>" />
                                        <button type="submit"><%= Page.ImageBrowser.Image.Button.Delete|l10n|html></button>
                                </form>