Show moving buttons for images, too
[Sone.git] / src / main / resources / templates / imageBrowser.html
index 8c7c429..c705a2c 100644 (file)
@@ -2,6 +2,138 @@
 
        <div class="page-id hidden">image-browser</div>
 
+       <script language="javascript">
+
+               /* hide all those forms. */
+               function hideAndShowBlock(blockElement, clickToShowElement, clickToHideElement) {
+                       $(blockElement).hide();
+                       $(clickToShowElement).removeClass("hidden");
+                       $(clickToShowElement).click(function() {
+                               $(blockElement).slideDown();
+                               $(clickToShowElement).addClass("hidden");
+                               $(clickToHideElement).removeClass("hidden");
+                       });
+                       $(clickToHideElement).click(function() {
+                               $(blockElement).slideUp();
+                               $(clickToHideElement).addClass("hidden");
+                               $(clickToShowElement).removeClass("hidden");
+                       });
+               }
+
+               /**
+                * Returns the image element with the given ID.
+                *
+                * @param imageId The ID of the image
+                * @return The image element
+                */
+               function getImage(imageId) {
+                       return $("#sone .image-in-album .image-id:contains('" + imageId + "')").closest(".image-in-album");
+               }
+
+               /**
+                * Swaps two images.
+                *
+                * @param sourceId The ID of the source image
+                * @param destinationId The ID of the destionation image
+                */
+               function swapImage(sourceId, destinationId) {
+                       sourceElement = getImage(sourceId);
+                       destinationElement = getImage(destinationId);
+                       sourceParent = sourceElement.closest(".image-row");
+                       sourcePrevSibling = sourceElement.prev();
+                       sourceElement.detach();
+                       destinationElement.before(sourceElement);
+                       if (sourcePrevSibling.get(0) != destinationElement.get(0)) {
+                               destinationElement.detach();
+                               (sourcePrevSibling.size() > 0) ? sourcePrevSibling.after(destinationElement) : sourceParent.prepend(destinationElement);
+                       }
+                       if ($("button[name='moveLeft']", sourceElement).hasClass("hidden") != $("button[name='moveLeft']", destinationElement).hasClass("hidden")) {
+                               $("button[name='moveLeft']", sourceElement).toggleClass("hidden");
+                               $("button[name='moveLeft']", destinationElement).toggleClass("hidden");
+                       }
+                       if ($("button[name='moveRight']", sourceElement).hasClass("hidden") != $("button[name='moveRight']", destinationElement).hasClass("hidden")) {
+                               $("button[name='moveRight']", sourceElement).toggleClass("hidden");
+                               $("button[name='moveRight']", destinationElement).toggleClass("hidden");
+                       }
+               }
+
+               /**
+                * Prepare all images for inline editing.
+                */
+               function prepareImages() {
+                       $(".image-in-album").each(function() {
+                               imageId = $(this).closest(".image-in-album").find(".image-id").text();
+                               (function(element, imageId) {
+                                       $("button[name='moveLeft'], button[name='moveRight']", element).click(function() {
+                                               ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "moveLeft": this.name == "moveLeft", "moveRight": this.name == "moveRight" }, function(data) {
+                                                       if (data && data.success) {
+                                                               swapImage(data.sourceImageId, data.destinationImageId);
+                                                       }
+                                               });
+                                               return false;
+                                       });
+                               })(this, imageId);
+                       });
+               }
+
+               /**
+                * Returns the album element with the given ID.
+                *
+                * @param albumId The ID of the album
+                * @return The album element
+                */
+               function getAlbum(albumId) {
+                       return $("#sone .album .album-id:contains('" + albumId + "')").closest(".album");
+               }
+
+               /**
+                * Swaps two albums.
+                *
+                * @param sourceId The ID of the source album
+                * @param destinationId The ID of the destionation album
+                */
+               function swapAlbum(sourceId, destinationId) {
+                       sourceElement = getAlbum(sourceId);
+                       destinationElement = getAlbum(destinationId);
+                       sourceParent = sourceElement.closest(".album-row");
+                       sourcePrevSibling = sourceElement.prev();
+                       sourceElement.detach();
+                       destinationElement.before(sourceElement);
+                       if (sourcePrevSibling.get(0) != destinationElement.get(0)) {
+                               destinationElement.detach();
+                               (sourcePrevSibling.size() > 0) ? sourcePrevSibling.after(destinationElement) : sourceParent.prepend(destinationElement);
+                       }
+                       if ($("button[name='moveLeft']", sourceElement).hasClass("hidden") != $("button[name='moveLeft']", destinationElement).hasClass("hidden")) {
+                               $("button[name='moveLeft']", sourceElement).toggleClass("hidden");
+                               $("button[name='moveLeft']", destinationElement).toggleClass("hidden");
+                       }
+                       if ($("button[name='moveRight']", sourceElement).hasClass("hidden") != $("button[name='moveRight']", destinationElement).hasClass("hidden")) {
+                               $("button[name='moveRight']", sourceElement).toggleClass("hidden");
+                               $("button[name='moveRight']", destinationElement).toggleClass("hidden");
+                       }
+               }
+
+               /**
+                * Prepare all albums for inline editing.
+                */
+               function prepareAlbums() {
+                       $(".album").each(function() {
+                               albumId = $(this).closest(".album").find(".album-id").text();
+                               (function(element, albumId) {
+                                       $("button[name='moveLeft'], button[name='moveRight']", element).click(function() {
+                                               ajaxGet("editAlbum.ajax", { "formPassword": getFormPassword(), "album": albumId, "moveLeft": this.name == "moveLeft", "moveRight": this.name == "moveRight" }, function(data) {
+                                                       if (data && data.success) {
+                                                               swapAlbum(data.sourceAlbumId, data.destinationAlbumId);
+                                                       }
+                                               });
+                                               return false;
+                                       });
+                               })(this, albumId);
+                       });
+               }
+
+       </script>
+
        <%if albumRequested>
 
                <%ifnull album>
 
                        <%if album.sone.local>
                                <script language="javascript">
+
                                        $(function() {
                                                getTranslation("WebInterface.DefaultText.UploadImage.Title", function(text) {
                                                        $("#upload-image :input[name='title']").each(function() {
                                                        });
                                                });
                                                $("#edit-album label").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");
+                                               hideAndShowBlock("div.delete-album", ".show-delete-album", ".hide-delete-album");
+
+                                               prepareAlbums();
+                                               prepareImages();
                                        });
                                </script>
                        <%/if>
 
-                       <h1 class="backlink"><%= Page.ImageBrowser.Album.Title|l10n|replace needle='{album}' replacementKey=album.title|html></h1>
+                       <h1 class="backlink"><%= Page.ImageBrowser.Album.Title|l10n|replace needle=='{album}' replacement=album.title|html></h1>
 
                        <div class="backlinks">
+                               <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
+                               <div class="separator">&gt;</div>
                                <%foreach album.backlinks backlink backlinks>
                                        <div class="backlink">
                                                <a href="<% backlink.target|html>"><% backlink.name|html></a>
                                <%/foreach>
                        </div>
 
-                       <p id="description"><% album.description|html></p>
+                       <p id="description"><% album.description|parse sone=album.sone|render></p>
 
-                       <%foreach album.albums album>
-                               <%first><h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2><%/first>
-                               <div class="album image">
-                                       <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
-                                               <%ifnull album.albumImage>
-                                                       <img src="images/unknown-image-0.png" width="200" height="150" alt="<% album.title|html>" title="<% album.title|html>" />
-                                               <%else><!-- TODO -->
-                                                       <% album.albumImage|image-link max-width=200 max-height=150 title==album.title>
-                                               <%/if>
-                                               <br/>
-                                               <% album.title|html>
-                                       </a>
-                               </div>
-                       <%/foreach>
+                       <%if album.sone.local>
+                               <div class="show-edit-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
+                               <div class="hide-edit-album hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
+                               <div class="edit-album">
+                                       <h2><%= Page.ImageBrowser.Album.Edit.Title|l10n|html></h2>
 
-                       <%foreach album.images image>
-                               <%first><h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2><%/first>
-                               <div class="image">
-                                       <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width=200 max-height=150></a>
+                                       <form id="edit-album" action="editAlbum.html" method="post">
+                                               <input type="hidden" name="formPassword" value="<%formPassword|html>" />
+                                               <input type="hidden" name="album" value="<%album.id|html>" />
+
+                                               <%if ! album.images.empty>
+                                                       <div>
+                                                               <label for="album-image"><%= Page.ImageBrowser.Album.Label.AlbumImage|l10n|html></label>
+                                                               <select name="album-image">
+                                                                       <option disabled="disabled"><%= Page.ImageBrowser.Album.AlbumImage.Choose|l10n|html></option>
+                                                                       <%foreach album.images image>
+                                                                               <option value="<% image.id|html>"<%if album.albumImage.id|match value=image.id> selected="selected"<%/if>><% image.title|html></option>
+                                                                       <%/foreach>
+                                                               </select>
+                                                       </div>
+                                               <%/if>
+                                               <div>
+                                                       <label for="title"><%= Page.ImageBrowser.Album.Label.Title|l10n|html></label>
+                                                       <input type="text" name="title" value="<%album.title|html>" />
+                                               </div>
+                                               <div>
+                                                       <label for="description"><%= Page.ImageBrowser.Album.Label.Description|l10n|html></label>
+                                                       <textarea name="description"><%album.description|html></textarea>
+                                               </div>
+                                               <button type="submit"><%= Page.ImageBrowser.Album.Button.Save|l10n|html></button>
+                                       </form>
                                </div>
-                       <%/foreach>
+                       <%/if>
 
+                       <%include include/browseAlbums.html albums=album.albums>
 
                        <%if album.sone.local>
-                               <%include include/uploadImage.html>
-                               <%include include/createAlbum.html>
-
-                               <h2><%= Page.ImageBrowser.Album.Edit.Title|l10n|html></h2>
-
-                               <form id="edit-album" action="editAlbum.html" method="post">
-                                       <input type="hidden" name="formPassword" value="<%formPassword|html>" />
-                                       <input type="hidden" name="album" value="<%album.id|html>" />
+                               <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
+                               <div class="hide-create-album hidden toggle-link"><a class="small-link">« <%= View.CreateAlbum.Title|l10n|html></a></div>
+                               <div class="create-album">
+                                       <%include include/createAlbum.html>
+                               </div>
+                       <%/if>
 
-                                       <div>
-                                               <label for="title"><%= Page.ImageBrowser.Album.Label.Title|l10n|html></label>
-                                               <input type="text" name="title" value="<%album.title|html>" />
-                                       </div>
-                                       <div>
-                                               <label for="description"><%= Page.ImageBrowser.Album.Label.Description|l10n|html></label>
-                                               <textarea name="description"><%album.description|html></textarea>
+                       <%foreach album.images image|paginate pageSize=core.preferences.imagesPerPage page=page>
+                               <%first>
+                                       <h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2>
+                                       <%include include/pagination.html pageParameter=="page">
+                                       <div class="images">
+                               <%/first>
+                                       <%if loop.even><div class="image-row"><%/if>
+                                               <div id="image-<% image.id|html>" class="image-in-album">
+                                                       <div class="image-id hidden"><% image.id|html></div>
+                                                       <%include include/viewImage.html>
+                                               </div>
+                                               <%= false|store key==endRow>
+                                               <%if loop.odd><%= true|store key==endRow><%/if>
+                                               <%last><%= true|store key==endRow><%/last>
+                                               <%if endRow>
                                        </div>
-                                       <button type="submit"><%= Page.ImageBrowser.Album.Button.Save|l10n|html></button>
-                               </form>
+                               <%/if>
+                <%last></div><%include include/pagination.html pageParameter=="page"><%/last>
+                       <%/foreach>
+
+                       <%if album.sone.local>
+                               <div class="clear show-upload-image hidden toggle-link"><a class="small-link">» <%= View.UploadImage.Title|l10n|html></a></div>
+                               <div class="clear hide-upload-image hidden toggle-link"><a class="small-link">« <%= View.UploadImage.Title|l10n|html></a></div>
+                               <div class="upload-image">
+                                       <%include include/uploadImage.html>
+                               </div>
 
                                <%if album.empty>
-                                       <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>
+                                       <div class="show-delete-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Delete.Title|l10n|html></a></div>
+                                       <div class="hide-delete-album hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Album.Delete.Title|l10n|html></a></div>
+                                       <div class="delete-album">
+                                               <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>
+                                       </div>
                                <%/if>
 
                        <%/if>
                <h1 class="backlink"><%image.title|html></h1>
 
                <div class="backlinks">
+                       <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
+                       <div class="separator">&gt;</div>
                        <%foreach image.album.backlinks backlink backlinks>
                                <div class="backlink">
                                        <a href="<% backlink.target|html>"><% backlink.name|html></a>
                                        <div class="separator">&gt;</div>
                                <%/if>
                        <%/foreach>
+                       <%ifnull !image.previous><div class="backlink"><a href="imageBrowser.html?image=<%image.previous.id|html>">« <%image.previous.title|html></a></div><%/if>
+                       <%ifnull !image.next><div class="backlink"><a href="imageBrowser.html?image=<%image.next.id|html>">» <%image.next.title|html></a></div><%/if>
                </div>
 
                <%ifnull image>
                                                        });
                                                });
                                                $("#edit-image label").hide();
+
+                                               hideAndShowBlock(".edit-image", ".show-edit-image", ".hide-edit-image");
+                                               hideAndShowBlock(".delete-image", ".show-delete-image", ".hide-delete-image");
                                        });
                                </script>
                        <%/if>
 
                        <div class="single-image">
                                <%ifnull !image.key>
-                                       <a href="/<%image.key|html>"><% image|image-link max-width=640 max-height=480></a>
+                                       <a href="/<%image.key|html>"><% image|image-link max-width==640 max-height==480></a>
                                <%else>
-                                       <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width=640 max-height=480></a>
+                                       <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width==640 max-height==480></a>
                                <%/if>
                        </div>
 
-                       <p class="parsed"><%image.description|parse sone=image.sone></p>
+                       <p class="parsed"><%image.description|parse sone=image.sone|render></p>
 
                        <%if image.sone.local>
 
-                               <h2><%= Page.ImageBrowser.Image.Edit.Title|l10n|html></h2>
-
-                               <form id="edit-image" action="editImage.html" method="post">
-                                       <input type="hidden" name="formPassword" value="<%formPassword|html>" />
-                                       <input type="hidden" name="image" value="<%image.id|html>" />
-
-                                       <div>
-                                               <label for="title"><%= Page.ImageBrowser.Image.Title.Label|l10n|html></label>
-                                               <input type="text" name="title" value="<%image.title|html>" />
-                                       </div>
-                                       <div>
-                                               <label for="description"><%= Page.ImageBrowser.Image.Description.Label|l10n|html></label>
-                                               <textarea name="description"><%image.description|html></textarea>
-                                       </div>
-                                       <div>
-                                               <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
-                                       </div>
-                               </form>
+                               <div class="show-edit-image hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Image.Edit.Title|l10n|html></a></div>
+                               <div class="hide-edit-image hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Image.Edit.Title|l10n|html></a></div>
+                               <div class="edit-image">
+                                       <h2><%= Page.ImageBrowser.Image.Edit.Title|l10n|html></h2>
+
+                                       <form id="edit-image" action="editImage.html" method="post">
+                                               <input type="hidden" name="formPassword" value="<%formPassword|html>" />
+                                               <input type="hidden" name="returnPage" value="<%request.uri|html>" />
+                                               <input type="hidden" name="image" value="<%image.id|html>" />
+
+                                               <div>
+                                                       <label for="title"><%= Page.ImageBrowser.Image.Title.Label|l10n|html></label>
+                                                       <input type="text" name="title" value="<%image.title|html>" />
+                                               </div>
+                                               <div>
+                                                       <label for="description"><%= Page.ImageBrowser.Image.Description.Label|l10n|html></label>
+                                                       <textarea name="description"><%image.description|html></textarea>
+                                               </div>
+                                               <div>
+                                                       <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
+                                               </div>
+                                       </form>
+                               </div>
 
-                               <h2><%= Page.ImageBrowser.Image.Delete.Title|l10n|html></h2>
+                               <div class="show-delete-image hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Image.Delete.Title|l10n|html></a></div>
+                               <div class="hide-delete-image hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Image.Delete.Title|l10n|html></a></div>
+                               <div class="delete-image">
+                                       <h2><%= Page.ImageBrowser.Image.Delete.Title|l10n|html></h2>
 
-                               <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>
+                                       <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>
+                               </div>
 
                        <%/if>
 
                                                });
                                        });
                                        $("#create-album label").hide();
+
+                                       hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
+
+                                       prepareAlbums();
                                });
                        </script>
                <%/if>
 
                <%else>
 
-                       <h1><%= Page.ImageBrowser.Sone.Title|l10n|replace needle='{sone}' replacementKey=sone.niceName|html></h1>
+                       <h1><%= Page.ImageBrowser.Sone.Title|l10n|replace needle=='{sone}' replacement=sone.niceName|html></h1>
 
-                       <%foreach sone.albums album>
-                               <div class="album image">
-                                       <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
-                                               <%ifnull album.albumImage>
-                                                       <img src="images/unknown-image-0.png" width="200" height="150" alt="<% album.title|html>" title="<% album.title|html>" />
-                                               <%else><!-- TODO -->
-                                                       <% album.albumImage|image-link max-width=200 max-height=150 title==album.title>
-                                               <%/if>
-                                               <br/>
-                                               <% album.title|html>
-                                       </a>
-                               </div>
-                       <%/foreach>
+                       <div class="backlinks">
+                               <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
+                               <div class="separator">&gt;</div>
+                               <div class="backlink"><a href="imageBrowser.html?sone=<%sone.id|html>"><%sone.niceName|html></a></div>
+                       </div>
+
+                       <%include include/browseAlbums.html albums=sone.rootAlbum.albums>
 
                        <%if sone.local>
-                               <%include include/createAlbum.html>
+                               <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
+                               <div class="hide-create-album hidden toggle-link"><a class="small-link">« <%= View.CreateAlbum.Title|l10n|html></a></div>
+                               <div class="create-album">
+                                       <%include include/createAlbum.html>
+                               </div>
                        <%/if>
 
                <%/if>
 
+       <%elseif galleryRequested>
+
+               <%foreach albums album|paginate pageSize=core.preferences.imagesPerPage pageParameter=request.page pagination=albumPagination>
+                       <%first>
+                               <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
+                               <%include include/pagination.html pagination=albumPagination pageParameter=="page">
+                               <div class="images">
+                       <%/first>
+                       <%if loop.even><div class="album-row"><%/if>
+                       <div id="album-<% album.id|html>" class="album">
+                               <div class="album-id hidden"><% album.id|html></div>
+                               <%include include/viewAlbum.html>
+                       </div>
+                       <%= false|store key==endRow>
+                       <%if loop.odd><%= true|store key==endRow><%/if>
+                       <%last><%= true|store key==endRow><%/last>
+                       <%if endRow></div><%/if>
+                       <%last>
+                               </div>
+                               <%include include/pagination.html pagination=albumPagination pageParameter=="page">
+                       <%/last>
+               <%/foreach>
+
        <%/if>
 
 <%include include/tail.html>