Show moving buttons for images, too
[Sone.git] / src / main / resources / templates / imageBrowser.html
index a88c48f..c705a2c 100644 (file)
                        });
                }
 
-               /* 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) {
-                               cancelImageEditing();
-                       } else {
-                               return;
-                       }
-                       editingImageId = imageId;
-                       $(".show-data", getImage(imageId)).hide();
-                       $(".edit-data", getImage(imageId)).show();
-                       $(document).bind("click.sone", function(event) {
-                               if ($(event.target).closest("#image-" + imageId).size() == 0) {
-                                       cancelImageEditing();
-                               }
-                       });
-               }
-
-               /**
-                * Cancels all image editing.
-                */
-               function cancelImageEditing() {
-                       $(".image .show-data").show();
-                       $(".image .edit-data").hide();
-                       $("form.edit-image").each(function() {
-                               this.reset();
-                       });
-                       $(document).unbind("click.sone");
-                       editingImageId = null;
-               }
-
                /**
                 * Returns the image element with the given ID.
                 *
@@ -64,7 +27,7 @@
                 * @return The image element
                 */
                function getImage(imageId) {
-                       return $("#sone .image .image-id:contains('" + imageId + "')").closest(".image");
+                       return $("#sone .image-in-album .image-id:contains('" + imageId + "')").closest(".image-in-album");
                }
 
                /**
                 * Prepare all images for inline editing.
                 */
                function prepareImages() {
-                       $(".image").each(function() {
-                               imageId = $(this).closest(".image").find(".image-id").text();
+                       $(".image-in-album").each(function() {
+                               imageId = $(this).closest(".image-in-album").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) {
                                                });
                                                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").html(data.parsedDescription);
-                                                               getImage(data.imageId).find(":input[name='title']").attr("defaultValue", title);
-                                                               getImage(data.imageId).find(":input[name='description']").attr("defaultValue", data.description);
-                                                               cancelImageEditing();
-                                                       }
-                                               });
-                                               return false;
-                                       });
                                })(this, imageId);
                        });
                }
 
-               /* ID of the album currently being edited. */
-               var editingAlbumId = null;
-
-               /**
-                * Shows the form for editing an album.
-                *
-                * @param albumId The ID of the album to edit.
-                */
-               function editAlbum(albumId) {
-                       if (editingAlbumId != albumId) {
-                               if (editingAlbumId != null) {
-                                       cancelAlbumEditing();
-                               }
-                       } else {
-                               console.log("already editing " + albumId);
-                               return;
-                       }
-                       editingAlbumId = albumId;
-                       $(".show-data", getAlbum(albumId)).hide();
-                       $(".edit-data", getAlbum(albumId)).show();
-                       console.log(getAlbum(albumId));
-                       $(document).bind("click.sone", function(event) {
-                               if ($(event.target).closest("#album-" + albumId).size() == 0) {
-                                       cancelAlbumEditing();
-                               }
-                       });
-               }
-
-               /**
-                * Cancels all album editing.
-                */
-               function cancelAlbumEditing() {
-                       console.log("cancel-album-edit");
-                       $(".album .show-data").show();
-                       $(".album .edit-data").hide();
-                       $("form.edit-album").each(function() {
-                               this.reset();
-                       });
-                       $(document).unbind("click.sone");
-                       editingAlbumId = null;
-               }
-
                /**
                 * Returns the album element with the given ID.
                 *
                        $(".album").each(function() {
                                albumId = $(this).closest(".album").find(".album-id").text();
                                (function(element, albumId) {
-                                       $(".show-data", element).click(function() {
-                                               console.log("show-data");
-                                               editAlbum(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) {
                                                });
                                                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("editAlbum.ajax", { "formPassword": getFormPassword(), "album": albumId, "title": title, "description": description }, function(data) {
-                                                       if (data && data.success) {
-                                                               getAlbum(data.albumId).find(".album-title").text(data.title);
-                                                               getAlbum(data.albumId).find(".album-description").text(data.description);
-                                                               getAlbum(data.albumId).find(":input[name='title']").attr("defaultValue", title);
-                                                               getAlbum(data.albumId).find(":input[name='description']").attr("defaultValue", description);
-                                                               cancelAlbumEditing();
-                                                       }
-                                               });
-                                               return false;
-                                       });
                                })(this, albumId);
                        });
                }
                                                });
                                                $("#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");
                                <%/foreach>
                        </div>
 
-                       <p id="description"><% album.description|parse sone=album.sone></p>
+                       <p id="description"><% album.description|parse sone=album.sone|render></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>
                        <%/if>
 
-                       <%foreach album.images image|paginate pageSize=core.preferences.imagesPerPage page=request.page>
+                       <%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.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|parse sone=image.sone></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="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>" />
-                                                               </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>
+                                       <%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>
-                                       <%include include/pagination.html pageParameter=="page">
                                <%/if>
+                <%last></div><%include include/pagination.html pageParameter=="page"><%/last>
                        <%/foreach>
 
                        <%if album.sone.local>
                                <%/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>
 
                                        });
                                        $("#create-album label").hide();
 
-                                       /* hide non-js move buttons. */
-                                       $(".move-buttons").hide();
-
                                        hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
 
                                        prepareAlbums();
                                <div class="backlink"><a href="imageBrowser.html?sone=<%sone.id|html>"><%sone.niceName|html></a></div>
                        </div>
 
-                       <%include include/browseAlbums.html albums=sone.albums>
+                       <%include include/browseAlbums.html albums=sone.rootAlbum.albums>
 
                        <%if sone.local>
                                <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
                        <%first>
                                <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
                                <%include include/pagination.html pagination=albumPagination pageParameter=="page">
+                               <div class="images">
                        <%/first>
-                       <%if loop.count|mod divisor==3><div class="album-row"><%/if>
+                       <%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>
-                               <div class="album-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> (<%album.sone.niceName|html>)" title="<% album.title|html> (<%album.sone.niceName|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-sone"><a href="imageBrowser.html?sone=<%album.sone.id|html>"><%album.sone.niceName|html></a></div>
-                                       <div class="album-title"><% album.title|html> (<%= View.Sone.Stats.Images|l10n 0=album.images.size>)</div>
-                                       <div class="album-description"><% album.description|parse sone=album.sone></div>
-                               </div>
+                               <%include include/viewAlbum.html>
                        </div>
                        <%= false|store key==endRow>
-                       <%if loop.count|mod divisor==3 offset==1><%= true|store key==endRow><%/if>
+                       <%if loop.odd><%= true|store key==endRow><%/if>
                        <%last><%= true|store key==endRow><%/last>
-                       <%if endRow>
-                               </div>
-                       <%/if>
+                       <%if endRow></div><%/if>
                        <%last>
+                               </div>
                                <%include include/pagination.html pagination=albumPagination pageParameter=="page">
                        <%/last>
                <%/foreach>