Add confirmation before deleting album.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 04:16:23 +0000 (06:16 +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/DeleteAlbumPage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/deleteAlbum.html [new file with mode: 0644]
src/main/resources/templates/imageBrowser.html

index b7c7267..6855e38 100644 (file)
@@ -56,6 +56,9 @@ public class DeleteAlbumPage extends SoneTemplatePage {
                        if (!webInterface.getCore().isLocalSone(album.getSone())) {
                                throw new RedirectException("noPermission.html");
                        }
+                       if (request.getHttpRequest().isPartSet("abortDelete")) {
+                               throw new RedirectException("imageBrowser.html?album=" + album.getId());
+                       }
                        Album parentAlbum = album.getParent();
                        webInterface.getCore().deleteAlbum(album);
                        if (parentAlbum == null) {
@@ -63,6 +66,12 @@ public class DeleteAlbumPage extends SoneTemplatePage {
                        }
                        throw new RedirectException("imageBrowser.html?album=" + parentAlbum.getId());
                }
+               String albumId = request.getHttpRequest().getParam("album");
+               Album album = webInterface.getCore().getAlbum(albumId, false);
+               if (album == null) {
+                       throw new RedirectException("invalid.html");
+               }
+               templateContext.set("album", album);
        }
 
 }
index 5fab260..7ad32fd 100644 (file)
@@ -555,6 +555,7 @@ public class WebInterface implements CoreListener {
                Template deleteSoneTemplate = TemplateParser.parse(createReader("/templates/deleteSone.html"));
                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 noPermissionTemplate = TemplateParser.parse(createReader("/templates/noPermission.html"));
                Template optionsTemplate = TemplateParser.parse(createReader("/templates/options.html"));
                Template aboutTemplate = TemplateParser.parse(createReader("/templates/about.html"));
@@ -584,7 +585,7 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new ImageBrowserPage(imageBrowserTemplate, this), "ImageBrowser"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateAlbumPage(createAlbumTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumPage(emptyTemplate, this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteAlbumPage(emptyTemplate, this)));
+               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)));
index da15a37..b112f72 100644 (file)
@@ -184,7 +184,12 @@ Page.UploadImage.Error.InvalidImage=The image you were trying to upload could no
 Page.EditImage.Title=Edit Image
 Page.DeleteImage.Title=Delete Image
 Page.EditAlbum.Title=Edit Album
+
 Page.DeleteAlbum.Title=Delete Album
+Page.DeleteAlbum.Page.Title=Delete Album
+Page.DeleteAlbum.Text.AlbumWillBeGone=This will remove your album “{title}”. Do you really want to do that?
+Page.DeleteAlbum.Button.Yes=Yes, delete album.
+Page.DeleteAlbum.Button.No=No, don’t delete album.
 
 Page.Trust.Title=Trust Sone - Sone
 
diff --git a/src/main/resources/templates/deleteAlbum.html b/src/main/resources/templates/deleteAlbum.html
new file mode 100644 (file)
index 0000000..cb27c19
--- /dev/null
@@ -0,0 +1,14 @@
+<%include include/head.html>
+
+       <h1><%= Page.DeleteAlbum.Page.Title|l10n|html></h1>
+
+       <p><%= Page.DeleteAlbum.Text.AlbumWillBeGone|l10n|replace needle="{title}" replacementKey=album.title|html></p>
+
+       <form method="post">
+               <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+               <input type="hidden" name="album" value="<%album.id|html>" />
+               <button type="submit" name="confirmDelete" value="1"><%= Page.DeleteAlbum.Button.Yes|l10n|html></button>
+               <button type="submit" name="abortDelete" value="1"><%= Page.DeleteAlbum.Button.No|l10n|html></button>
+       </form>
+
+<%include include/tail.html>
index fd4c224..6faea11 100644 (file)
                                </form>
 
                                <%if album.empty>
-                                       <form id="delete-album" action="deleteAlbum.html" method="post">
-                                               <input type="hidden" name="formPassword" value="<%formPassword|html>" />
+                                       <form id="delete-album" action="deleteAlbum.html" method="get">
                                                <input type="hidden" name="album" value="<%album.id|html>" />
                                                <button type="submit"><%= Page.ImageBrowser.Album.Button.Delete|l10n|html></button>
                                        </form>