Use larger preview images.
[Sone.git] / src / main / resources / templates / imageBrowser.html
index bb21d46..a4fef79 100644 (file)
 
                        <%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() {
                                                hideAndShowBlock(".upload-image", ".show-upload-image", ".hide-upload-image");
                                                hideAndShowBlock(".delete-album", ".show-delete-album", ".hide-delete-album");
 
-                                               hideAndShowData = function(activationElements, activeElements, hideElement, showElement) {
-                                                       $(activationElements).click(function() {
-                                                               imageId = $(this).closest(".image").find(".image-id").text();
-                                                               $(hideElement, $("#image-" + imageId)).hide();
-                                                               $(showElement, $("#image-" + imageId)).show();
-                                                               $(document).click(function(event) {
-                                                                       if ($(event.target).closest("#image-" + imageId).size() == 0) {
-                                                                               $(showElement).hide();
-                                                                               $(hideElement).show();
-                                                                       }
-                                                                       return $(event.target).is("button");
+                                               $(".image").each(function() {
+                                                       imageId = $(this).closest(".image").find(".image-id").text();
+                                                       (function(element, imageId) {
+                                                               $(".show-data", element).click(function() {
+                                                                       editImage(imageId);
                                                                });
-                                                       });
-                                               };
-
-                                               hideAndShowData(".image-title, .image-description", ".image", ".show-data", ".edit-data");
+                                                               $("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>
                                        <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="266" height="200" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -33px;" />
+                                                               <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=200 max-height=200 mode=enlarge title==album.title>
+                                                               <% album.albumImage|image-link max-width=250 max-height=250 mode=enlarge title==album.title>
                                                        <%/if>
                                                </a>
                                        </div>
                                <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=200 max-height=200 mode=enlarge title==image.title></a>
+                                               <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>
                                                                        <textarea name="description"><%image.description|html></textarea>
                                                                </div>
                                                                <div>
-                                                                       <%notfirst><button type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button><%/notfirst>
-                                                                       <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
-                                                                       <%notlast><button type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button><%/notlast>
+                                                                       <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>
                                        <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="266" height="200" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -33px;"/>
+                                                               <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=200 max-height=200 mode=enlarge title==album.title>
+                                                               <% album.albumImage|image-link max-width=250 max-height=250 mode=enlarge title==album.title>
                                                        <%/if>
                                                </a>
                                        </div>