Add optional parameter to hide moving buttons
[Sone.git] / src / main / resources / templates / imageBrowser.html
1 <%include include/head.html>
2
3         <div class="page-id hidden">image-browser</div>
4
5         <script language="javascript">
6
7                 /* hide all those forms. */
8                 function hideAndShowBlock(blockElement, clickToShowElement, clickToHideElement) {
9                         $(blockElement).hide();
10                         $(clickToShowElement).removeClass("hidden");
11                         $(clickToShowElement).click(function() {
12                                 $(blockElement).slideDown();
13                                 $(clickToShowElement).addClass("hidden");
14                                 $(clickToHideElement).removeClass("hidden");
15                         });
16                         $(clickToHideElement).click(function() {
17                                 $(blockElement).slideUp();
18                                 $(clickToHideElement).addClass("hidden");
19                                 $(clickToShowElement).removeClass("hidden");
20                         });
21                 }
22
23                 /**
24                  * Returns the image element with the given ID.
25                  *
26                  * @param imageId The ID of the image
27                  * @return The image element
28                  */
29                 function getImage(imageId) {
30                         return $("#sone .image-in-album .image-id:contains('" + imageId + "')").closest(".image-in-album");
31                 }
32
33                 /**
34                  * Swaps two images.
35                  *
36                  * @param sourceId The ID of the source image
37                  * @param destinationId The ID of the destionation image
38                  */
39                 function swapImage(sourceId, destinationId) {
40                         sourceElement = getImage(sourceId);
41                         destinationElement = getImage(destinationId);
42                         sourceParent = sourceElement.closest(".image-row");
43                         sourcePrevSibling = sourceElement.prev();
44                         sourceElement.detach();
45                         destinationElement.before(sourceElement);
46                         if (sourcePrevSibling.get(0) != destinationElement.get(0)) {
47                                 destinationElement.detach();
48                                 (sourcePrevSibling.size() > 0) ? sourcePrevSibling.after(destinationElement) : sourceParent.prepend(destinationElement);
49                         }
50                         if ($("button[name='moveLeft']", sourceElement).hasClass("hidden") != $("button[name='moveLeft']", destinationElement).hasClass("hidden")) {
51                                 $("button[name='moveLeft']", sourceElement).toggleClass("hidden");
52                                 $("button[name='moveLeft']", destinationElement).toggleClass("hidden");
53                         }
54                         if ($("button[name='moveRight']", sourceElement).hasClass("hidden") != $("button[name='moveRight']", destinationElement).hasClass("hidden")) {
55                                 $("button[name='moveRight']", sourceElement).toggleClass("hidden");
56                                 $("button[name='moveRight']", destinationElement).toggleClass("hidden");
57                         }
58                 }
59
60                 /**
61                  * Prepare all images for inline editing.
62                  */
63                 function prepareImages() {
64                         $(".image-in-album").each(function() {
65                                 imageId = $(this).closest(".image-in-album").find(".image-id").text();
66                                 (function(element, imageId) {
67                                         $("button[name='moveLeft'], button[name='moveRight']", element).click(function() {
68                                                 ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "moveLeft": this.name == "moveLeft", "moveRight": this.name == "moveRight" }, function(data) {
69                                                         if (data && data.success) {
70                                                                 swapImage(data.sourceImageId, data.destinationImageId);
71                                                         }
72                                                 });
73                                                 return false;
74                                         });
75                                 })(this, imageId);
76                         });
77                 }
78
79                 /**
80                  * Returns the album element with the given ID.
81                  *
82                  * @param albumId The ID of the album
83                  * @return The album element
84                  */
85                 function getAlbum(albumId) {
86                         return $("#sone .album .album-id:contains('" + albumId + "')").closest(".album");
87                 }
88
89                 /**
90                  * Swaps two albums.
91                  *
92                  * @param sourceId The ID of the source album
93                  * @param destinationId The ID of the destionation album
94                  */
95                 function swapAlbum(sourceId, destinationId) {
96                         sourceElement = getAlbum(sourceId);
97                         destinationElement = getAlbum(destinationId);
98                         sourceParent = sourceElement.closest(".album-row");
99                         sourcePrevSibling = sourceElement.prev();
100                         sourceElement.detach();
101                         destinationElement.before(sourceElement);
102                         if (sourcePrevSibling.get(0) != destinationElement.get(0)) {
103                                 destinationElement.detach();
104                                 (sourcePrevSibling.size() > 0) ? sourcePrevSibling.after(destinationElement) : sourceParent.prepend(destinationElement);
105                         }
106                         if ($("button[name='moveLeft']", sourceElement).hasClass("hidden") != $("button[name='moveLeft']", destinationElement).hasClass("hidden")) {
107                                 $("button[name='moveLeft']", sourceElement).toggleClass("hidden");
108                                 $("button[name='moveLeft']", destinationElement).toggleClass("hidden");
109                         }
110                         if ($("button[name='moveRight']", sourceElement).hasClass("hidden") != $("button[name='moveRight']", destinationElement).hasClass("hidden")) {
111                                 $("button[name='moveRight']", sourceElement).toggleClass("hidden");
112                                 $("button[name='moveRight']", destinationElement).toggleClass("hidden");
113                         }
114                 }
115
116                 /**
117                  * Prepare all albums for inline editing.
118                  */
119                 function prepareAlbums() {
120                         $(".album").each(function() {
121                                 albumId = $(this).closest(".album").find(".album-id").text();
122                                 (function(element, albumId) {
123                                         $("button[name='moveLeft'], button[name='moveRight']", element).click(function() {
124                                                 ajaxGet("editAlbum.ajax", { "formPassword": getFormPassword(), "album": albumId, "moveLeft": this.name == "moveLeft", "moveRight": this.name == "moveRight" }, function(data) {
125                                                         if (data && data.success) {
126                                                                 swapAlbum(data.sourceAlbumId, data.destinationAlbumId);
127                                                         }
128                                                 });
129                                                 return false;
130                                         });
131                                 })(this, albumId);
132                         });
133                 }
134
135         </script>
136
137         <%if albumRequested>
138
139                 <%ifnull album>
140
141                         <p><%= Page.ImageBrowser.Album.Error.NotFound.Text|l10n|html></p>
142
143                 <%elseifnull album.title>
144
145                         <p><%= Page.ImageBrowser.Album.Error.NotFound.Text|l10n|html></p>
146
147                 <%else>
148
149                         <%if album.sone.local>
150                                 <script language="javascript">
151
152                                         $(function() {
153                                                 getTranslation("WebInterface.DefaultText.UploadImage.Title", function(text) {
154                                                         $("#upload-image :input[name='title']").each(function() {
155                                                                 registerInputTextareaSwap(this, text, "title", false, true);
156                                                         });
157                                                 });
158                                                 getTranslation("WebInterface.DefaultText.UploadImage.Description", function(text) {
159                                                         $("#upload-image :input[name='description']").each(function() {
160                                                                 registerInputTextareaSwap(this, text, "description", true, false);
161                                                         });
162                                                 });
163                                                 $("#upload-image label").hide();
164                                                 getTranslation("WebInterface.DefaultText.CreateAlbum.Name", function(text) {
165                                                         $("#create-album input[name='name']").each(function() {
166                                                                 registerInputTextareaSwap(this, text, "name", false, true);
167                                                         });
168                                                 });
169                                                 getTranslation("WebInterface.DefaultText.CreateAlbum.Description", function(text) {
170                                                         $("#create-album input[name='description']").each(function() {
171                                                                 registerInputTextareaSwap(this, text, "description", true, true);
172                                                         });
173                                                 });
174                                                 $("#create-album label").hide();
175                                                 getTranslation("WebInterface.DefaultText.EditAlbum.Title", function(text) {
176                                                         $("#edit-album input[name='title']").each(function() {
177                                                                 registerInputTextareaSwap(this, text, "title", false, true);
178                                                         });
179                                                 });
180                                                 getTranslation("WebInterface.DefaultText.EditAlbum.Description", function(text) {
181                                                         $("#edit-album :input[name='description']").each(function() {
182                                                                 registerInputTextareaSwap(this, text, "description", true, false);
183                                                         });
184                                                 });
185                                                 $("#edit-album label").hide();
186
187                                                 hideAndShowBlock("div.edit-album", ".show-edit-album", ".hide-edit-album");
188                                                 hideAndShowBlock("div.create-album", ".show-create-album", ".hide-create-album");
189                                                 hideAndShowBlock("div.upload-image", ".show-upload-image", ".hide-upload-image");
190                                                 hideAndShowBlock("div.delete-album", ".show-delete-album", ".hide-delete-album");
191
192                                                 prepareAlbums();
193                                                 prepareImages();
194                                         });
195                                 </script>
196                         <%/if>
197
198                         <h1 class="backlink"><%= Page.ImageBrowser.Album.Title|l10n|replace needle=='{album}' replacement=album.title|html></h1>
199
200                         <div class="backlinks">
201                                 <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
202                                 <div class="separator">&gt;</div>
203                                 <%foreach album.backlinks backlink backlinks>
204                                         <div class="backlink">
205                                                 <a href="<% backlink.target|html>"><% backlink.name|html></a>
206                                         </div>
207                                         <%if ! backlinks.last>
208                                                 <div class="separator">&gt;</div>
209                                         <%/if>
210                                 <%/foreach>
211                         </div>
212
213                         <p id="description"><% album.description|parse sone=album.sone|render></p>
214
215                         <%if album.sone.local>
216                                 <div class="show-edit-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
217                                 <div class="hide-edit-album hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
218                                 <div class="edit-album">
219                                         <h2><%= Page.ImageBrowser.Album.Edit.Title|l10n|html></h2>
220
221                                         <form id="edit-album" action="editAlbum.html" method="post">
222                                                 <input type="hidden" name="formPassword" value="<%formPassword|html>" />
223                                                 <input type="hidden" name="album" value="<%album.id|html>" />
224
225                                                 <%if ! album.images.empty>
226                                                         <div>
227                                                                 <label for="album-image"><%= Page.ImageBrowser.Album.Label.AlbumImage|l10n|html></label>
228                                                                 <select name="album-image">
229                                                                         <option disabled="disabled"><%= Page.ImageBrowser.Album.AlbumImage.Choose|l10n|html></option>
230                                                                         <%foreach album.images image>
231                                                                                 <option value="<% image.id|html>"<%if album.albumImage.id|match value=image.id> selected="selected"<%/if>><% image.title|html></option>
232                                                                         <%/foreach>
233                                                                 </select>
234                                                         </div>
235                                                 <%/if>
236                                                 <div>
237                                                         <label for="title"><%= Page.ImageBrowser.Album.Label.Title|l10n|html></label>
238                                                         <input type="text" name="title" value="<%album.title|html>" />
239                                                 </div>
240                                                 <div>
241                                                         <label for="description"><%= Page.ImageBrowser.Album.Label.Description|l10n|html></label>
242                                                         <textarea name="description"><%album.description|html></textarea>
243                                                 </div>
244                                                 <button type="submit"><%= Page.ImageBrowser.Album.Button.Save|l10n|html></button>
245                                         </form>
246                                 </div>
247                         <%/if>
248
249                         <%include include/browseAlbums.html albums=album.albums>
250
251                         <%if album.sone.local>
252                                 <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
253                                 <div class="hide-create-album hidden toggle-link"><a class="small-link">« <%= View.CreateAlbum.Title|l10n|html></a></div>
254                                 <div class="create-album">
255                                         <%include include/createAlbum.html>
256                                 </div>
257                         <%/if>
258
259                         <%foreach album.images image|paginate pageSize=core.preferences.imagesPerPage page=page>
260                                 <%first>
261                                         <h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2>
262                                         <%include include/pagination.html pageParameter=="page">
263                                         <div class="images">
264                                 <%/first>
265                                         <%if loop.even><div class="image-row"><%/if>
266                                                 <div id="image-<% image.id|html>" class="image-in-album">
267                                                         <div class="image-id hidden"><% image.id|html></div>
268                                                         <%include include/viewImage.html>
269                                                 </div>
270                                                 <%= false|store key==endRow>
271                                                 <%if loop.odd><%= true|store key==endRow><%/if>
272                                                 <%last><%= true|store key==endRow><%/last>
273                                                 <%if endRow>
274                                         </div>
275                                 <%/if>
276                 <%last></div><%include include/pagination.html pageParameter=="page"><%/last>
277                         <%/foreach>
278
279                         <%if album.sone.local>
280                                 <div class="clear show-upload-image hidden toggle-link"><a class="small-link">» <%= View.UploadImage.Title|l10n|html></a></div>
281                                 <div class="clear hide-upload-image hidden toggle-link"><a class="small-link">« <%= View.UploadImage.Title|l10n|html></a></div>
282                                 <div class="upload-image">
283                                         <%include include/uploadImage.html>
284                                 </div>
285
286                                 <%if album.empty>
287                                         <div class="show-delete-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Delete.Title|l10n|html></a></div>
288                                         <div class="hide-delete-album hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Album.Delete.Title|l10n|html></a></div>
289                                         <div class="delete-album">
290                                                 <form id="delete-album" action="deleteAlbum.html" method="get">
291                                                         <input type="hidden" name="album" value="<%album.id|html>" />
292                                                         <button type="submit"><%= Page.ImageBrowser.Album.Button.Delete|l10n|html></button>
293                                                 </form>
294                                         </div>
295                                 <%/if>
296
297                         <%/if>
298
299                 <%/if>
300
301         <%elseif imageRequested>
302
303                 <h1 class="backlink"><%image.title|html></h1>
304
305                 <div class="backlinks">
306                         <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
307                         <div class="separator">&gt;</div>
308                         <%foreach image.album.backlinks backlink backlinks>
309                                 <div class="backlink">
310                                         <a href="<% backlink.target|html>"><% backlink.name|html></a>
311                                 </div>
312                                 <%if ! backlinks.last>
313                                         <div class="separator">&gt;</div>
314                                 <%/if>
315                         <%/foreach>
316                         <%ifnull !image.previous><div class="backlink"><a href="imageBrowser.html?image=<%image.previous.id|html>">« <%image.previous.title|html></a></div><%/if>
317                         <%ifnull !image.next><div class="backlink"><a href="imageBrowser.html?image=<%image.next.id|html>">» <%image.next.title|html></a></div><%/if>
318                 </div>
319
320                 <%ifnull image>
321
322                 <%else>
323
324                         <%if image.sone.local>
325                                 <script language="javascript">
326                                         $(function() {
327                                                 getTranslation("WebInterface.DefaultText.EditImage.Title", function(text) {
328                                                         $("#edit-image input[name='title']").each(function() {
329                                                                 registerInputTextareaSwap(this, text, "title", false, true);
330                                                         });
331                                                 });
332                                                 getTranslation("WebInterface.DefaultText.EditImage.Description", function(text) {
333                                                         $("#edit-image :input[name='description']").each(function() {
334                                                                 registerInputTextareaSwap(this, text, "description", true, false);
335                                                         });
336                                                 });
337                                                 $("#edit-image label").hide();
338
339                                                 hideAndShowBlock(".edit-image", ".show-edit-image", ".hide-edit-image");
340                                                 hideAndShowBlock(".delete-image", ".show-delete-image", ".hide-delete-image");
341                                         });
342                                 </script>
343                         <%/if>
344
345                         <div class="single-image">
346                                 <%ifnull !image.key>
347                                         <a href="/<%image.key|html>"><% image|image-link max-width==640 max-height==480></a>
348                                 <%else>
349                                         <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width==640 max-height==480></a>
350                                 <%/if>
351                         </div>
352
353                         <p class="parsed"><%image.description|parse sone=image.sone|render></p>
354
355                         <%if image.sone.local>
356
357                                 <div class="show-edit-image hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Image.Edit.Title|l10n|html></a></div>
358                                 <div class="hide-edit-image hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Image.Edit.Title|l10n|html></a></div>
359                                 <div class="edit-image">
360                                         <h2><%= Page.ImageBrowser.Image.Edit.Title|l10n|html></h2>
361
362                                         <form id="edit-image" action="editImage.html" method="post">
363                                                 <input type="hidden" name="formPassword" value="<%formPassword|html>" />
364                                                 <input type="hidden" name="returnPage" value="<%request.uri|html>" />
365                                                 <input type="hidden" name="image" value="<%image.id|html>" />
366
367                                                 <div>
368                                                         <label for="title"><%= Page.ImageBrowser.Image.Title.Label|l10n|html></label>
369                                                         <input type="text" name="title" value="<%image.title|html>" />
370                                                 </div>
371                                                 <div>
372                                                         <label for="description"><%= Page.ImageBrowser.Image.Description.Label|l10n|html></label>
373                                                         <textarea name="description"><%image.description|html></textarea>
374                                                 </div>
375                                                 <div>
376                                                         <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
377                                                 </div>
378                                         </form>
379                                 </div>
380
381                                 <div class="show-delete-image hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Image.Delete.Title|l10n|html></a></div>
382                                 <div class="hide-delete-image hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Image.Delete.Title|l10n|html></a></div>
383                                 <div class="delete-image">
384                                         <h2><%= Page.ImageBrowser.Image.Delete.Title|l10n|html></h2>
385
386                                         <form id="delete-image" action="deleteImage.html" method="get">
387                                                 <input type="hidden" name="image" value="<%image.id|html>" />
388                                                 <button type="submit"><%= Page.ImageBrowser.Image.Button.Delete|l10n|html></button>
389                                         </form>
390                                 </div>
391
392                         <%/if>
393
394                 <%/if>
395
396         <%elseif soneRequested>
397
398                 <%if sone.local>
399                         <script language="javascript">
400                                 $(function() {
401                                         getTranslation("WebInterface.DefaultText.CreateAlbum.Name", function(text) {
402                                                 $("#create-album input[name='name']").each(function() {
403                                                         registerInputTextareaSwap(this, text, "name", false, true);
404                                                 });
405                                         });
406                                         getTranslation("WebInterface.DefaultText.CreateAlbum.Description", function(text) {
407                                                 $("#create-album input[name='description']").each(function() {
408                                                         registerInputTextareaSwap(this, text, "description", true, true);
409                                                 });
410                                         });
411                                         $("#create-album label").hide();
412
413                                         hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
414
415                                         prepareAlbums();
416                                 });
417                         </script>
418                 <%/if>
419
420                 <%ifnull sone>
421
422                         <p><%= Page.ImageBrowser.Sone.Error.NotFound.Text|l10n|html></p>
423
424                 <%else>
425
426                         <h1><%= Page.ImageBrowser.Sone.Title|l10n|replace needle=='{sone}' replacement=sone.niceName|html></h1>
427
428                         <div class="backlinks">
429                                 <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
430                                 <div class="separator">&gt;</div>
431                                 <div class="backlink"><a href="imageBrowser.html?sone=<%sone.id|html>"><%sone.niceName|html></a></div>
432                         </div>
433
434                         <%include include/browseAlbums.html albums=sone.rootAlbum.albums>
435
436                         <%if sone.local>
437                                 <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
438                                 <div class="hide-create-album hidden toggle-link"><a class="small-link">« <%= View.CreateAlbum.Title|l10n|html></a></div>
439                                 <div class="create-album">
440                                         <%include include/createAlbum.html>
441                                 </div>
442                         <%/if>
443
444                 <%/if>
445
446         <%elseif galleryRequested>
447
448                 <%foreach albums album|paginate pageSize=core.preferences.imagesPerPage pageParameter=request.page pagination=albumPagination>
449                         <%first>
450                                 <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
451                                 <%include include/pagination.html pagination=albumPagination pageParameter=="page">
452                                 <div class="images">
453                         <%/first>
454                         <%if loop.even><div class="album-row"><%/if>
455                         <div id="album-<% album.id|html>" class="album">
456                                 <div class="album-id hidden"><% album.id|html></div>
457                                 <%include include/viewAlbum.html>
458                         </div>
459                         <%= false|store key==endRow>
460                         <%if loop.odd><%= true|store key==endRow><%/if>
461                         <%last><%= true|store key==endRow><%/last>
462                         <%if endRow></div><%/if>
463                         <%last>
464                                 </div>
465                                 <%include include/pagination.html pagination=albumPagination pageParameter=="page">
466                         <%/last>
467                 <%/foreach>
468
469         <%/if>
470
471 <%include include/tail.html>