Add buttons to re-order images and albums without javascript.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Nov 2011 12:16:54 +0000 (13:16 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Nov 2011 12:16:54 +0000 (13:16 +0100)
This resolves #243.

src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java
src/main/resources/templates/imageBrowser.html
src/main/resources/templates/include/browseAlbums.html

index 8f595a7..dc5c8fa 100644 (file)
@@ -18,6 +18,7 @@
 package net.pterodactylus.sone.web;
 
 import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.text.TextFilter;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
@@ -50,6 +51,7 @@ public class EditAlbumPage extends SoneTemplatePage {
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
                if (request.getMethod() == Method.POST) {
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
                        String albumId = request.getHttpRequest().getPartAsStringFailsafe("album", 36);
                        Album album = webInterface.getCore().getAlbum(albumId, false);
                        if (album == null) {
@@ -58,6 +60,25 @@ public class EditAlbumPage extends SoneTemplatePage {
                        if (!webInterface.getCore().isLocalSone(album.getSone())) {
                                throw new RedirectException("noPermission.html");
                        }
+                       if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) {
+                               if (album.getParent() == null) {
+                                       currentSone.moveAlbumUp(album);
+                                       webInterface.getCore().touchConfiguration();
+                                       throw new RedirectException("imageBrowser.html?sone=" + currentSone.getId());
+                               }
+                               album.getParent().moveAlbumUp(album);
+                               webInterface.getCore().touchConfiguration();
+                               throw new RedirectException("imageBrowser.html?album=" + album.getParent().getId());
+                       } else if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveRight", 4))) {
+                               if (album.getParent() == null) {
+                                       currentSone.moveAlbumDown(album);
+                                       webInterface.getCore().touchConfiguration();
+                                       throw new RedirectException("imageBrowser.html?sone=" + currentSone.getId());
+                               }
+                               album.getParent().moveAlbumDown(album);
+                               webInterface.getCore().touchConfiguration();
+                               throw new RedirectException("imageBrowser.html?album=" + album.getParent().getId());
+                       }
                        String albumImageId = request.getHttpRequest().getPartAsStringFailsafe("album-image", 36);
                        if (webInterface.getCore().getImage(albumImageId, false) == null) {
                                albumImageId = null;
index 1da99ff..755c431 100644 (file)
                                                });
                                                $("#edit-album label").hide();
 
+                                               /* hide non-js image move buttons. */
+                                               $(".move-buttons").hide();
+
                                                hideAndShowBlock("div.edit-album", ".show-edit-album", ".hide-edit-album");
                                                hideAndShowBlock("div.create-album", ".show-create-album", ".hide-create-album");
                                                hideAndShowBlock("div.upload-image", ".show-upload-image", ".hide-upload-image");
                                                        <input type="hidden" name="returnPage" value="<%request.uri|html>" />
                                                        <input type="hidden" name="image" value="<%image.id|html>" />
 
+                                                       <div class="move-buttons">
+                                                                       <button <%first>class="hidden" <%/first>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
+                                                                       <button <%last>class="hidden" <%/last>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
+                                                       </div>
+
                                                        <div class="edit-data hidden">
                                                                <div>
                                                                        <input type="text" name="title" value="<%image.title|html>" />
                                        });
                                        $("#create-album label").hide();
 
+                                       /* hide non-js move buttons. */
+                                       $(".move-buttons").hide();
+
                                        hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
 
                                        prepareAlbums();
index 1fddebd..cb9abba 100644 (file)
                                <input type="hidden" name="returnPage" value="<%request.uri|html>" />
                                <input type="hidden" name="album" value="<%album.id|html>" />
 
+                               <div class="move-buttons">
+                                               <button <%first>class="hidden" <%/first>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
+                                               <button <%last>class="hidden" <%/last>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
+                               </div>
+
                                <div class="edit-data hidden">
                                        <div>
                                                <input type="text" name="title" value="<%album.title|html>" />