Use larger preview images.
[Sone.git] / src / main / resources / templates / imageBrowser.html
index 9d89055..a4fef79 100644 (file)
@@ -2,7 +2,27 @@
 
        <div class="page-id hidden">image-browser</div>
 
-       <h1><%= Page.ImageBrowser.Page.Title|l10n|html></h1>
+       <script language="javascript">
+               $(function() {
+
+                       /* hide all those forms. */
+                       hideAndShowBlock = function(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");
+                               });
+                       };
+
+               });
+       </script>
 
        <%if albumRequested>
 
 
                        <p><%= Page.ImageBrowser.Album.Error.NotFound.Text|l10n|html></p>
 
-               <%elseifnull album.name>
+               <%elseifnull album.title>
 
                        <p><%= Page.ImageBrowser.Album.Error.NotFound.Text|l10n|html></p>
 
                <%else>
 
-                       <h2><% album.name|html></h2>
+                       <%if album.sone.local>
+                               <script language="javascript">
+
+                                       /* ID of the image currently being edited. */
+                                       var editingImageId = null;
+
+                                       /**
+                                        * Shows the form for editing an image.
+                                        *
+                                        * @param imageId The ID of the image to edit.
+                                        */
+                                       function editImage(imageId) {
+                                               if (editingImageId != imageId) {
+                                                       cancelEditing();
+                                               } else {
+                                                       return;
+                                               }
+                                               $(".show-data", "#image-" + imageId).hide();
+                                               $(".edit-data", "#image-" + imageId).show();
+                                               $(document).bind("click.sone", function(event) {
+                                                       if ($(event.target).closest("#image-" + imageId).size() == 0) {
+                                                               cancelEditing();
+                                                       }
+                                               });
+                                       }
+
+                                       /**
+                                        * Cancels all image editing.
+                                        */
+                                       function cancelEditing() {
+                                               $(".show-data").show();
+                                               $(".edit-data").hide();
+                                               $("form.edit-image").each(function() {
+                                                       this.reset();
+                                               });
+                                               $(document).unbind("click.sone");
+                                               editingImageId = null;
+                                       }
+
+                                       /**
+                                        * 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 .image-id:contains('" + imageId + "')").closest(".image");
+                                       }
+
+                                       /**
+                                        * 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");
+                                               }
+                                       }
+
+                                       $(function() {
+                                               getTranslation("WebInterface.DefaultText.UploadImage.Title", function(text) {
+                                                       $("#upload-image :input[name='title']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "title", false, true);
+                                                       });
+                                               });
+                                               getTranslation("WebInterface.DefaultText.UploadImage.Description", function(text) {
+                                                       $("#upload-image :input[name='description']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "description", true, false);
+                                                       });
+                                               });
+                                               $("#upload-image label").hide();
+                                               getTranslation("WebInterface.DefaultText.CreateAlbum.Name", function(text) {
+                                                       $("#create-album input[name='name']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "name", false, true);
+                                                       });
+                                               });
+                                               getTranslation("WebInterface.DefaultText.CreateAlbum.Description", function(text) {
+                                                       $("#create-album input[name='description']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "description", true, true);
+                                                       });
+                                               });
+                                               $("#create-album label").hide();
+                                               getTranslation("WebInterface.DefaultText.EditAlbum.Title", function(text) {
+                                                       $("#edit-album input[name='title']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "title", false, true);
+                                                       });
+                                               });
+                                               getTranslation("WebInterface.DefaultText.EditAlbum.Description", function(text) {
+                                                       $("#edit-album :input[name='description']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "description", true, false);
+                                                       });
+                                               });
+                                               $("#edit-album label").hide();
+
+                                               hideAndShowBlock(".edit-album", ".show-edit-album", ".hide-edit-album");
+                                               hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
+                                               hideAndShowBlock(".upload-image", ".show-upload-image", ".hide-upload-image");
+                                               hideAndShowBlock(".delete-album", ".show-delete-album", ".hide-delete-album");
+
+                                               $(".image").each(function() {
+                                                       imageId = $(this).closest(".image").find(".image-id").text();
+                                                       (function(element, imageId) {
+                                                               $(".show-data", element).click(function() {
+                                                                       editImage(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;
+                                                               });
+                                                               $("button[name='submit']", element).click(function() {
+                                                                       title = $(":input[name='title']:enabled", this.form).val();
+                                                                       description = $(":input[name='description']:enabled", this.form).val();
+                                                                       ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "title": title, "description": description }, function(data) {
+                                                                               if (data && data.success) {
+                                                                                       getImage(data.imageId).find(".image-title").text(data.title);
+                                                                                       getImage(data.imageId).find(".image-description").text(data.description);
+                                                                                       getImage(data.imageId).find(":input[name='title']").attr("defaultValue", title);
+                                                                                       getImage(data.imageId).find(":input[name='description']").attr("defaultValue", description);
+                                                                                       cancelEditing();
+                                                                               }
+                                                                       });
+                                                                       return false;
+                                                               });
+                                                       })(this, imageId);
+                                               });
+                                       });
+                               </script>
+                       <%/if>
+
+                       <h1 class="backlink"><%= Page.ImageBrowser.Album.Title|l10n|replace needle='{album}' replacementKey=album.title|html></h1>
 
                        <div class="backlinks">
                                <%foreach album.backlinks backlink backlinks>
                                <%/foreach>
                        </div>
 
+                       <p id="description"><% album.description|html></p>
+
+                       <%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>
+
+                                       <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 key=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>
+                       <%/if>
+
                        <%foreach album.albums album>
-                               <div class="album">
-                                       <div class="name"><% album.name|html></div>
+                               <%first><h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2><%/first>
+                               <%if loop.count|mod divisor=3><div class="image-row"><%/if>
+                               <div class="album image">
+                                       <div class="image-container">
+                                               <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
+                                                       <%ifnull album.albumImage>
+                                                               <img src="images/unknown-image-0.png" width="333" height="250" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -41px;" />
+                                                       <%else><!-- TODO -->
+                                                               <% album.albumImage|image-link max-width=250 max-height=250 mode=enlarge title==album.title>
+                                                       <%/if>
+                                               </a>
+                                       </div>
+                                       <div class="show-data">
+                                               <div class="album-title"><% album.title|html></div>
+                                               <div class="album-description"><% album.description|html></div>
+                                       </div>
                                </div>
+                               <%= false|store key=endRow>
+                               <%if loop.count|mod divisor=3 offset=1><%= true|store key=endRow><%/if>
+                               <%last><%= true|store key=endRow><%/last>
+                               <%if endRow></div><%/if>
                        <%/foreach>
 
-                       <%include include/createAlbum.html>
+                       <%if album.sone.local>
+                               <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 id="description">
-                               <% album.description|html>
-                       </div>
+                       <%foreach album.images image>
+                               <%first><h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2><%/first>
+                               <%if loop.count|mod divisor=3><div class="image-row"><%/if>
+                               <div id="image-<% image.id|html>" class="image">
+                                       <div class="image-id hidden"><% image.id|html></div>
+                                       <div class="image-container">
+                                               <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width=250 max-height=250 mode=enlarge title==image.title></a>
+                                       </div>
+                                       <div class="show-data">
+                                               <div class="image-title"><% image.title|html></div>
+                                               <div class="image-description"><% image.description|html></div>
+                                       </div>
+                                       <%if album.sone.local>
+                                               <form class="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 class="edit-data hidden">
+                                                               <div>
+                                                                       <input type="text" name="title" value="<%image.title|html>" />
+                                                               </div>
+                                                               <div>
+                                                                       <textarea name="description"><%image.description|html></textarea>
+                                                               </div>
+                                                               <div>
+                                                                       <button <%first>class="hidden" <%/first>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
+                                                                       <button type="submit" name="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
+                                                                       <button <%last>class="hidden" <%/last>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
+                                                               </div>
+                                                       </div>
+                                               </form>
+                                       <%/if>
+                               </div>
+                               <%= false|store key=endRow>
+                               <%if loop.count|mod divisor=3 offset=1><%= true|store key=endRow><%/if>
+                               <%last><%= true|store key=endRow><%/last>
+                               <%if endRow></div><%/if>
+                       <%/foreach>
+
+                       <%if album.sone.local>
+                               <div class="show-upload-image hidden toggle-link"><a class="small-link">» <%= View.UploadImage.Title|l10n|html></a></div>
+                               <div class="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>
+                                       <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>
 
                <%/if>
 
        <%elseif imageRequested>
 
-       <%else>
+               <h1 class="backlink"><%image.title|html></h1>
+
+               <div class="backlinks">
+                       <%foreach image.album.backlinks backlink backlinks>
+                               <div class="backlink">
+                                       <a href="<% backlink.target|html>"><% backlink.name|html></a>
+                               </div>
+                               <%if ! backlinks.last>
+                                       <div class="separator">&gt;</div>
+                               <%/if>
+                       <%/foreach>
+               </div>
+
+               <%ifnull image>
 
-               <%include include/createAlbum.html>
+               <%else>
+
+                       <%if image.sone.local>
+                               <script language="javascript">
+                                       $(function() {
+                                               getTranslation("WebInterface.DefaultText.EditImage.Title", function(text) {
+                                                       $("#edit-image input[name='title']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "title", false, true);
+                                                       });
+                                               });
+                                               getTranslation("WebInterface.DefaultText.EditImage.Description", function(text) {
+                                                       $("#edit-image :input[name='description']").each(function() {
+                                                               registerInputTextareaSwap(this, text, "description", true, false);
+                                                       });
+                                               });
+                                               $("#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>
+                               <%else>
+                                       <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>
+
+                       <%if image.sone.local>
+
+                               <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>
+
+                               <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>
+                               </div>
+
+                       <%/if>
+
+               <%/if>
+
+       <%elseif soneRequested>
+
+               <%if sone.local>
+                       <script language="javascript">
+                               $(function() {
+                                       getTranslation("WebInterface.DefaultText.CreateAlbum.Name", function(text) {
+                                               $("#create-album input[name='name']").each(function() {
+                                                       registerInputTextareaSwap(this, text, "name", false, true);
+                                               });
+                                       });
+                                       getTranslation("WebInterface.DefaultText.CreateAlbum.Description", function(text) {
+                                               $("#create-album input[name='description']").each(function() {
+                                                       registerInputTextareaSwap(this, text, "description", true, true);
+                                               });
+                                       });
+                                       $("#create-album label").hide();
+
+                                       hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
+                               });
+                       </script>
+               <%/if>
+
+               <%ifnull sone>
+
+                       <p><%= Page.ImageBrowser.Sone.Error.NotFound.Text|l10n|html></p>
+
+               <%else>
+
+                       <h1><%= Page.ImageBrowser.Sone.Title|l10n|replace needle='{sone}' replacementKey=sone.niceName|html></h1>
+
+                       <%foreach sone.albums album>
+                               <%if loop.count|mod divisor=3><div class="image-row"><%/if>
+                               <div class="album image">
+                                       <div class="image-container">
+                                               <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
+                                                       <%ifnull album.albumImage>
+                                                               <img src="images/unknown-image-0.png" width="333" height="250" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -41px;"/>
+                                                       <%else><!-- TODO -->
+                                                               <% album.albumImage|image-link max-width=250 max-height=250 mode=enlarge title==album.title>
+                                                       <%/if>
+                                               </a>
+                                       </div>
+                                       <div class="show-data">
+                                               <div class="album-title"><% album.title|html></div>
+                                               <div class="album-description"><% album.description|html></div>
+                                       </div>
+                               </div>
+                               <%= false|store key=endRow>
+                               <%if loop.count|mod divisor=3 offset=1><%= true|store key=endRow><%/if>
+                               <%last><%= true|store key=endRow><%/last>
+                               <%if endRow></div><%/if>
+                       <%/foreach>
+
+                       <%if sone.local>
+                               <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>
 
        <%/if>