Rework pretty much all image displaying code
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 31 Jul 2015 08:53:34 +0000 (10:53 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 31 Jul 2015 08:53:34 +0000 (10:53 +0200)
src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java
src/main/resources/static/css/sone.css
src/main/resources/static/images/broken-album.png [new file with mode: 0644]
src/main/resources/static/images/broken-image.png [new file with mode: 0644]
src/main/resources/static/javascript/sone.js
src/main/resources/templates/imageBrowser.html
src/main/resources/templates/include/browseAlbums.html
src/main/resources/templates/include/pagination.html
src/main/resources/templates/include/viewAlbum.html
src/main/resources/templates/include/viewImage.html [new file with mode: 0644]
src/main/resources/templates/include/viewPost.html

index 5674ee8..58aee5c 100644 (file)
@@ -72,6 +72,7 @@ public class ImageBrowserPage extends SoneTemplatePage {
                        templateContext.set("albumRequested", true);
                        templateContext.set("album", album.orNull());
                        templateContext.set("page", request.getHttpRequest().getParam("page"));
+                       templateContext.set("albumPage", request.getHttpRequest().getParam("albumPage"));
                        return;
                }
                String imageId = request.getHttpRequest().getParam("image", null);
@@ -86,6 +87,7 @@ public class ImageBrowserPage extends SoneTemplatePage {
                        Optional<Sone> sone = webInterface.getCore().getSone(soneId);
                        templateContext.set("soneRequested", true);
                        templateContext.set("sone", sone.orNull());
+                       templateContext.set("albumPage", request.getHttpRequest().getParam("albumPage"));
                        return;
                }
                String mode = request.getHttpRequest().getParam("mode", null);
index 68c9878..49f2cba 100644 (file)
@@ -734,6 +734,11 @@ textarea {
        width: 95%;
 }
 
+#sone .images {
+       display: table;
+       width: 100%;
+}
+
 #sone .album-row, #sone .image-row {
        display: table-row;
        border-collapse: separate;
@@ -748,7 +753,8 @@ textarea {
        position: relative;
        margin-top: 1ex;
        margin-bottom: 1ex;
-       height: 120px;
+       height: 122px;
+       overflow: hidden;
 }
 
 #sone .image {
diff --git a/src/main/resources/static/images/broken-album.png b/src/main/resources/static/images/broken-album.png
new file mode 100644 (file)
index 0000000..324d9c4
Binary files /dev/null and b/src/main/resources/static/images/broken-album.png differ
diff --git a/src/main/resources/static/images/broken-image.png b/src/main/resources/static/images/broken-image.png
new file mode 100644 (file)
index 0000000..1725c10
Binary files /dev/null and b/src/main/resources/static/images/broken-image.png differ
index 07c5b3d..3235f51 100644 (file)
@@ -1878,6 +1878,22 @@ var currentSoneMenuId;
 /** Timeout handler for the next-to-show Sone context menu. */
 var currentSoneMenuTimeoutHandler;
 
+function replaceImagesWithErrorWithBrokenImages() {
+       var replaceImage = function(imageElement, sourcePath) {
+               $(imageElement).attr("src", sourcePath)
+                       .attr("width", "160")
+                       .attr("height", "120")
+                       .attr("style", "position: absolute; top: 0px; left: 0px; opacity: .25");
+       };
+
+       $(".image-in-album .image img").error(function () {
+               replaceImage(this, "images/broken-image.png");
+       });
+       $(".album .image img").error(function () {
+               replaceImage(this, "images/broken-album.png");
+       });
+}
+
 $(document).ready(function() {
 
        /* rip out the status update textarea. */
@@ -2005,6 +2021,8 @@ $(document).ready(function() {
        /* activate status polling. */
        setTimeout(getStatus, 5000);
 
+       replaceImagesWithErrorWithBrokenImages();
+
        /* reset activity counter when the page has focus. */
        $(window).focus(function() {
                focus = true;
index a237c7f..3a720b6 100644 (file)
                                <%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|render></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>
+                                       <%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>
+                                                       <%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 <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
+                                                                       <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
                                                                </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 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 <%if loop.first>class="hidden" <%/if>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 <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
+                                                                       </div>
                                                                </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>
+                                                       </form>
+                                                       <%/if>
+                                               </div>
+                                               <%= false|store key==endRow>
+                                               <%if loop.odd><%= true|store key==endRow><%/if>
+                                               <%last><%= true|store key==endRow><%/last>
+                                               <%if endRow>
                                        </div>
                                <%/if>
-                <%last><%include include/pagination.html pageParameter=="page"><%/last>
+                <%last></div><%include include/pagination.html pageParameter=="page"><%/last>
                        <%/foreach>
 
                        <%if album.sone.local>
                        <%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|render></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>
index 74bf714..4961e74 100644 (file)
@@ -1,9 +1,47 @@
-<%foreach albums album>
-       <%first><h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2><%/first>
-       <%if loop.count|mod divisor==3><div class="album-row"><%/if>
-       <%include include/viewAlbum.html>
+<%foreach albums album|paginate pageSize=core.preferences.imagesPerPage page=albumPage>
+       <%first>
+               <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
+               <%include include/pagination.html pageParameter=="albumPage">
+               <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.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>
+       <%last>
+               </div>
+               <%include include/pagination.html pageParameter=="albumPage">
+       <%/last>
+
+       <%if album.sone.local>
+               <form class="edit-album" action="editAlbum.html" method="post">
+                       <input type="hidden" name="formPassword" value="<%formPassword|html>" />
+                       <input type="hidden" name="returnPage" value="<%request.uri|html>" />
+                       <input type="hidden" name="album" value="<%album.id|html>" />
+
+                       <div class="move-buttons">
+                               <button <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
+                               <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
+                       </div>
+
+                       <div class="edit-data hidden">
+                               <div>
+                                       <input type="text" name="title" value="<%album.title|html>" />
+                               </div>
+                               <div>
+                                       <textarea name="description"><%album.description|html></textarea>
+                               </div>
+                               <div>
+                                       <button <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
+                                       <button type="submit" name="submit"><%= Page.ImageBrowser.Album.Button.Save|l10n|html></button>
+                                       <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
+                               </div>
+                       </div>
+               </form>
+       <%/if>
 <%/foreach>
index 80248d4..b2bafcd 100644 (file)
@@ -7,4 +7,5 @@
                <div class="last"><%if ! pagination.last><a href="<% request|change name=pageParameter value=pagination.lastPage>">»</a><%else><span>»</span><%/if></div>
                <div class="next"><%if ! pagination.last><a href="<% request|change name=pageParameter value=pagination.nextPage>">›</a><%else><span>›</span><%/if></div>
        </div>
+       <div class="clear"/>
 <%/if>
index 0821909..8a3d6de 100644 (file)
@@ -1,45 +1,17 @@
-<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>" title="<% album.title|html>" style="position: relative; top: 0px; left: -41px;" />
-                       <%else><!-- TODO -->
-                       <div class="image-container">
-                               <% album.albumImage|image-link class==album-image max-width==250 max-height==250 mode==enlarge title=album.title>
-                       </div>
-                       <div class="link-to-album"><a href="album://<% album.id|html>">[link album]</a></div>
+<div class="image-with-information">
+       <div class="image">
+               <a href="imageBrowser.html?album=<% album.id|html>">
+                       <%ifnull album.images.random>
+                               <img src="images/broken-album.png" width="160" height="120" title="<% album.title|html>" style="opacity: 0.25;"/>
+                       <%else>
+                               <% album.images.random|image-link max-width==160 max-height==120 mode==enlarge title=album.title>
                        <%/if>
                </a>
        </div>
-       <div class="show-data">
-               <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|render></div>
+       <div class="information">
+               <div class="link"><a href="album://<% album.id|html>">[link album]</a></div>
+               <div class="title"><a href="imageBrowser.html?album=<% album.id|html>"><% album.title|html></a></div>
+               <div class="author"><% =View.Post.LinkedAlbum.SizeAndAuthor|l10n 0=album.sone.niceName 1=album.images.size|html|replace needle=="[link]" replacement=='<a href="viewSone.html?sone=<sone-id>">'|replace needle=='[/link]' replacement=='</a>'|replace needle=='<sone-id>' replacement=album.sone.id></div>
+               <div class="description"><% album.description|parse sone=album.sone|render></div>
        </div>
-       <%if album.sone.local>
-       <form class="edit-album" action="editAlbum.html" method="post">
-               <input type="hidden" name="formPassword" value="<%formPassword|html>" />
-               <input type="hidden" name="returnPage" value="<%request.uri|html>" />
-               <input type="hidden" name="album" value="<%album.id|html>" />
-
-               <div class="move-buttons">
-                       <button <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
-                       <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
-               </div>
-
-               <div class="edit-data hidden">
-                       <div>
-                               <input type="text" name="title" value="<%album.title|html>" />
-                       </div>
-                       <div>
-                               <textarea name="description"><%album.description|html></textarea>
-                       </div>
-                       <div>
-                               <button <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
-                               <button type="submit" name="submit"><%= Page.ImageBrowser.Album.Button.Save|l10n|html></button>
-                               <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
-                       </div>
-               </div>
-       </form>
-       <%/if>
 </div>
diff --git a/src/main/resources/templates/include/viewImage.html b/src/main/resources/templates/include/viewImage.html
new file mode 100644 (file)
index 0000000..4e9087b
--- /dev/null
@@ -0,0 +1,12 @@
+<div class="image-with-information">
+       <div class="image">
+               <a href="imageBrowser.html?image=<% image.id|html>">
+                       <% image|image-link max-width==160 max-height==120 mode==enlarge title=image.title>
+               </a>
+       </div>
+       <div class="information">
+               <div class="link"><a href="image://<% image.id|html>">[link image]</a></div>
+               <div class="title"><a href="imageBrowser.html?image=<% image.id|html>"><% image.title|html></a></div>
+               <div class="description"><% image.description|parse sone=image.sone|render></div>
+       </div>
+</div>
index d150d4f..5ce2d28 100644 (file)
                </div>
                <%foreach parts part>
                        <%if part.class.simpleName|match value==AlbumPart><!-- ← this is so ugly. -->
-                               <div class="linked-album">
-                                       <div class="linked-image">
-                                               <div class="image-left">
-                                                       <div class="image">
-                                                               <a href="imageBrowser.html?album=<% part.album.id|html>"><% part.album.albumImage|image-link max-width==160 max-height==90 mode==enlarge title=part.album.title></a>
-                                                       </div>
-                                               </div>
-                                               <div class="about-image">
-                                                       <div class="title"><% part.album.title|html></div>
-                                                       <div><% =View.Post.LinkedAlbum.SizeAndAuthor|l10n 0=part.album.sone.niceName 1=part.album.images.size|html|replace needle=="[link]" replacement=='<a href="viewSone.html?sone=<sone-id>">'|replace needle=='[/link]' replacement=='</a>'|replace needle=='<sone-id>' replacement=part.album.sone.id></div>
-                                                       <div class="description"><% part.album.description|parse sone=part.album.sone|render></div>
-                                               </div>
-                                       </div>
+                               <% part.album.images.random|store key==image>
+                               <div class="album images">
+                                       <%include include/viewAlbum.html album=part.album>
                                </div>
                        <%/if>
                <%/foreach>