Remove currently unused javascript
[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").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                                                 /* hide non-js image move buttons. */
188                                                 $(".move-buttons").hide();
189
190                                                 hideAndShowBlock("div.edit-album", ".show-edit-album", ".hide-edit-album");
191                                                 hideAndShowBlock("div.create-album", ".show-create-album", ".hide-create-album");
192                                                 hideAndShowBlock("div.upload-image", ".show-upload-image", ".hide-upload-image");
193                                                 hideAndShowBlock("div.delete-album", ".show-delete-album", ".hide-delete-album");
194
195                                                 prepareAlbums();
196                                                 prepareImages();
197                                         });
198                                 </script>
199                         <%/if>
200
201                         <h1 class="backlink"><%= Page.ImageBrowser.Album.Title|l10n|replace needle=='{album}' replacement=album.title|html></h1>
202
203                         <div class="backlinks">
204                                 <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
205                                 <div class="separator">&gt;</div>
206                                 <%foreach album.backlinks backlink backlinks>
207                                         <div class="backlink">
208                                                 <a href="<% backlink.target|html>"><% backlink.name|html></a>
209                                         </div>
210                                         <%if ! backlinks.last>
211                                                 <div class="separator">&gt;</div>
212                                         <%/if>
213                                 <%/foreach>
214                         </div>
215
216                         <p id="description"><% album.description|parse sone=album.sone|render></p>
217
218                         <%if album.sone.local>
219                                 <div class="show-edit-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
220                                 <div class="hide-edit-album hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Album.Edit.Title|l10n|html></a></div>
221                                 <div class="edit-album">
222                                         <h2><%= Page.ImageBrowser.Album.Edit.Title|l10n|html></h2>
223
224                                         <form id="edit-album" action="editAlbum.html" method="post">
225                                                 <input type="hidden" name="formPassword" value="<%formPassword|html>" />
226                                                 <input type="hidden" name="album" value="<%album.id|html>" />
227
228                                                 <%if ! album.images.empty>
229                                                         <div>
230                                                                 <label for="album-image"><%= Page.ImageBrowser.Album.Label.AlbumImage|l10n|html></label>
231                                                                 <select name="album-image">
232                                                                         <option disabled="disabled"><%= Page.ImageBrowser.Album.AlbumImage.Choose|l10n|html></option>
233                                                                         <%foreach album.images image>
234                                                                                 <option value="<% image.id|html>"<%if album.albumImage.id|match value=image.id> selected="selected"<%/if>><% image.title|html></option>
235                                                                         <%/foreach>
236                                                                 </select>
237                                                         </div>
238                                                 <%/if>
239                                                 <div>
240                                                         <label for="title"><%= Page.ImageBrowser.Album.Label.Title|l10n|html></label>
241                                                         <input type="text" name="title" value="<%album.title|html>" />
242                                                 </div>
243                                                 <div>
244                                                         <label for="description"><%= Page.ImageBrowser.Album.Label.Description|l10n|html></label>
245                                                         <textarea name="description"><%album.description|html></textarea>
246                                                 </div>
247                                                 <button type="submit"><%= Page.ImageBrowser.Album.Button.Save|l10n|html></button>
248                                         </form>
249                                 </div>
250                         <%/if>
251
252                         <%include include/browseAlbums.html albums=album.albums>
253
254                         <%if album.sone.local>
255                                 <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
256                                 <div class="hide-create-album hidden toggle-link"><a class="small-link">« <%= View.CreateAlbum.Title|l10n|html></a></div>
257                                 <div class="create-album">
258                                         <%include include/createAlbum.html>
259                                 </div>
260                         <%/if>
261
262                         <%foreach album.images image|paginate pageSize=core.preferences.imagesPerPage page=page>
263                                 <%first>
264                                         <h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2>
265                                         <%include include/pagination.html pageParameter=="page">
266                                         <div class="images">
267                                 <%/first>
268                                         <%if loop.even><div class="image-row"><%/if>
269                                                 <div id="image-<% image.id|html>" class="image-in-album">
270                                                         <div class="image-id hidden"><% image.id|html></div>
271                                                         <%include include/viewImage.html>
272                                                         <%if album.sone.local>
273                                                         <form class="edit-image" action="editImage.html" method="post">
274                                                                 <input type="hidden" name="formPassword" value="<%formPassword|html>" />
275                                                                 <input type="hidden" name="returnPage" value="<%request.uri|html>" />
276                                                                 <input type="hidden" name="image" value="<%image.id|html>" />
277
278                                                                 <div class="move-buttons">
279                                                                         <button <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
280                                                                         <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
281                                                                 </div>
282
283                                                                 <div class="edit-data hidden">
284                                                                         <div>
285                                                                                 <input type="text" name="title" value="<%image.title|html>" />
286                                                                         </div>
287                                                                         <div>
288                                                                                 <textarea name="description"><%image.description|html></textarea>
289                                                                         </div>
290                                                                         <div>
291                                                                                 <button <%if loop.first>class="hidden" <%/if>type="submit" name="moveLeft" value="true"><%= Page.ImageBrowser.Image.Button.MoveLeft|l10n|html></button>
292                                                                                 <button type="submit" name="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
293                                                                                 <button <%if loop.last>class="hidden" <%/if>type="submit" name="moveRight" value="true"><%= Page.ImageBrowser.Image.Button.MoveRight|l10n|html></button>
294                                                                         </div>
295                                                                 </div>
296                                                         </form>
297                                                         <%/if>
298                                                 </div>
299                                                 <%= false|store key==endRow>
300                                                 <%if loop.odd><%= true|store key==endRow><%/if>
301                                                 <%last><%= true|store key==endRow><%/last>
302                                                 <%if endRow>
303                                         </div>
304                                 <%/if>
305                 <%last></div><%include include/pagination.html pageParameter=="page"><%/last>
306                         <%/foreach>
307
308                         <%if album.sone.local>
309                                 <div class="clear show-upload-image hidden toggle-link"><a class="small-link">» <%= View.UploadImage.Title|l10n|html></a></div>
310                                 <div class="clear hide-upload-image hidden toggle-link"><a class="small-link">« <%= View.UploadImage.Title|l10n|html></a></div>
311                                 <div class="upload-image">
312                                         <%include include/uploadImage.html>
313                                 </div>
314
315                                 <%if album.empty>
316                                         <div class="show-delete-album hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Album.Delete.Title|l10n|html></a></div>
317                                         <div class="hide-delete-album hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Album.Delete.Title|l10n|html></a></div>
318                                         <div class="delete-album">
319                                                 <form id="delete-album" action="deleteAlbum.html" method="get">
320                                                         <input type="hidden" name="album" value="<%album.id|html>" />
321                                                         <button type="submit"><%= Page.ImageBrowser.Album.Button.Delete|l10n|html></button>
322                                                 </form>
323                                         </div>
324                                 <%/if>
325
326                         <%/if>
327
328                 <%/if>
329
330         <%elseif imageRequested>
331
332                 <h1 class="backlink"><%image.title|html></h1>
333
334                 <div class="backlinks">
335                         <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
336                         <div class="separator">&gt;</div>
337                         <%foreach image.album.backlinks backlink backlinks>
338                                 <div class="backlink">
339                                         <a href="<% backlink.target|html>"><% backlink.name|html></a>
340                                 </div>
341                                 <%if ! backlinks.last>
342                                         <div class="separator">&gt;</div>
343                                 <%/if>
344                         <%/foreach>
345                         <%ifnull !image.previous><div class="backlink"><a href="imageBrowser.html?image=<%image.previous.id|html>">« <%image.previous.title|html></a></div><%/if>
346                         <%ifnull !image.next><div class="backlink"><a href="imageBrowser.html?image=<%image.next.id|html>">» <%image.next.title|html></a></div><%/if>
347                 </div>
348
349                 <%ifnull image>
350
351                 <%else>
352
353                         <%if image.sone.local>
354                                 <script language="javascript">
355                                         $(function() {
356                                                 getTranslation("WebInterface.DefaultText.EditImage.Title", function(text) {
357                                                         $("#edit-image input[name='title']").each(function() {
358                                                                 registerInputTextareaSwap(this, text, "title", false, true);
359                                                         });
360                                                 });
361                                                 getTranslation("WebInterface.DefaultText.EditImage.Description", function(text) {
362                                                         $("#edit-image :input[name='description']").each(function() {
363                                                                 registerInputTextareaSwap(this, text, "description", true, false);
364                                                         });
365                                                 });
366                                                 $("#edit-image label").hide();
367
368                                                 hideAndShowBlock(".edit-image", ".show-edit-image", ".hide-edit-image");
369                                                 hideAndShowBlock(".delete-image", ".show-delete-image", ".hide-delete-image");
370                                         });
371                                 </script>
372                         <%/if>
373
374                         <div class="single-image">
375                                 <%ifnull !image.key>
376                                         <a href="/<%image.key|html>"><% image|image-link max-width==640 max-height==480></a>
377                                 <%else>
378                                         <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width==640 max-height==480></a>
379                                 <%/if>
380                         </div>
381
382                         <p class="parsed"><%image.description|parse sone=image.sone|render></p>
383
384                         <%if image.sone.local>
385
386                                 <div class="show-edit-image hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Image.Edit.Title|l10n|html></a></div>
387                                 <div class="hide-edit-image hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Image.Edit.Title|l10n|html></a></div>
388                                 <div class="edit-image">
389                                         <h2><%= Page.ImageBrowser.Image.Edit.Title|l10n|html></h2>
390
391                                         <form id="edit-image" action="editImage.html" method="post">
392                                                 <input type="hidden" name="formPassword" value="<%formPassword|html>" />
393                                                 <input type="hidden" name="returnPage" value="<%request.uri|html>" />
394                                                 <input type="hidden" name="image" value="<%image.id|html>" />
395
396                                                 <div>
397                                                         <label for="title"><%= Page.ImageBrowser.Image.Title.Label|l10n|html></label>
398                                                         <input type="text" name="title" value="<%image.title|html>" />
399                                                 </div>
400                                                 <div>
401                                                         <label for="description"><%= Page.ImageBrowser.Image.Description.Label|l10n|html></label>
402                                                         <textarea name="description"><%image.description|html></textarea>
403                                                 </div>
404                                                 <div>
405                                                         <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
406                                                 </div>
407                                         </form>
408                                 </div>
409
410                                 <div class="show-delete-image hidden toggle-link"><a class="small-link">» <%= Page.ImageBrowser.Image.Delete.Title|l10n|html></a></div>
411                                 <div class="hide-delete-image hidden toggle-link"><a class="small-link">« <%= Page.ImageBrowser.Image.Delete.Title|l10n|html></a></div>
412                                 <div class="delete-image">
413                                         <h2><%= Page.ImageBrowser.Image.Delete.Title|l10n|html></h2>
414
415                                         <form id="delete-image" action="deleteImage.html" method="get">
416                                                 <input type="hidden" name="image" value="<%image.id|html>" />
417                                                 <button type="submit"><%= Page.ImageBrowser.Image.Button.Delete|l10n|html></button>
418                                         </form>
419                                 </div>
420
421                         <%/if>
422
423                 <%/if>
424
425         <%elseif soneRequested>
426
427                 <%if sone.local>
428                         <script language="javascript">
429                                 $(function() {
430                                         getTranslation("WebInterface.DefaultText.CreateAlbum.Name", function(text) {
431                                                 $("#create-album input[name='name']").each(function() {
432                                                         registerInputTextareaSwap(this, text, "name", false, true);
433                                                 });
434                                         });
435                                         getTranslation("WebInterface.DefaultText.CreateAlbum.Description", function(text) {
436                                                 $("#create-album input[name='description']").each(function() {
437                                                         registerInputTextareaSwap(this, text, "description", true, true);
438                                                 });
439                                         });
440                                         $("#create-album label").hide();
441
442                                         hideAndShowBlock(".create-album", ".show-create-album", ".hide-create-album");
443
444                                         prepareAlbums();
445                                 });
446                         </script>
447                 <%/if>
448
449                 <%ifnull sone>
450
451                         <p><%= Page.ImageBrowser.Sone.Error.NotFound.Text|l10n|html></p>
452
453                 <%else>
454
455                         <h1><%= Page.ImageBrowser.Sone.Title|l10n|replace needle=='{sone}' replacement=sone.niceName|html></h1>
456
457                         <div class="backlinks">
458                                 <div class="backlink"><a href="imageBrowser.html?mode=gallery"><%= Page.ImageBrowser.Link.All|l10n|html></a></div>
459                                 <div class="separator">&gt;</div>
460                                 <div class="backlink"><a href="imageBrowser.html?sone=<%sone.id|html>"><%sone.niceName|html></a></div>
461                         </div>
462
463                         <%include include/browseAlbums.html albums=sone.rootAlbum.albums>
464
465                         <%if sone.local>
466                                 <div class="show-create-album hidden toggle-link"><a class="small-link">» <%= View.CreateAlbum.Title|l10n|html></a></div>
467                                 <div class="hide-create-album hidden toggle-link"><a class="small-link">« <%= View.CreateAlbum.Title|l10n|html></a></div>
468                                 <div class="create-album">
469                                         <%include include/createAlbum.html>
470                                 </div>
471                         <%/if>
472
473                 <%/if>
474
475         <%elseif galleryRequested>
476
477                 <%foreach albums album|paginate pageSize=core.preferences.imagesPerPage pageParameter=request.page pagination=albumPagination>
478                         <%first>
479                                 <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
480                                 <%include include/pagination.html pagination=albumPagination pageParameter=="page">
481                                 <div class="images">
482                         <%/first>
483                         <%if loop.even><div class="album-row"><%/if>
484                         <div id="album-<% album.id|html>" class="album">
485                                 <div class="album-id hidden"><% album.id|html></div>
486                                 <%include include/viewAlbum.html>
487                         </div>
488                         <%= false|store key==endRow>
489                         <%if loop.odd><%= true|store key==endRow><%/if>
490                         <%last><%= true|store key==endRow><%/last>
491                         <%if endRow></div><%/if>
492                         <%last>
493                                 </div>
494                                 <%include include/pagination.html pagination=albumPagination pageParameter=="page">
495                         <%/last>
496                 <%/foreach>
497
498         <%/if>
499
500 <%include include/tail.html>