albums.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * @name albums.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2013 by Philipp Maurer, Tobias Reich
  6. *
  7. * Albums Module
  8. * Takes care of every action albums can handle and execute.
  9. */
  10. albums = {
  11. load: function() {
  12. loadingBar.show();
  13. lychee.animate(".album, .photo", "contentZoomOut");
  14. /* Search */
  15. lychee.content.attr("data-search", "");
  16. lychee.animate(".divider", "fadeOut");
  17. startTime = new Date().getTime();
  18. lychee.api("getAlbums", "json", function(data) {
  19. durationTime = (new Date().getTime() - startTime);
  20. if (durationTime>300) waitTime = 0; else waitTime = 300 - durationTime;
  21. $.timer(waitTime,function(){
  22. $("#tools_album, #tools_photo").hide();
  23. $("#tools_albums").show();
  24. /* Smart Albums */
  25. unsortedAlbum = new Object();
  26. unsortedAlbum.id = 0;
  27. unsortedAlbum.title = "Unsorted";
  28. unsortedAlbum.sysdate = data.unsortNum + " photos";
  29. unsortedAlbum.unsorted = 1;
  30. if (data.unsortThumb0) unsortedAlbum.thumb0 = lychee.upload_path + data.unsortThumb0; else unsortedAlbum.thumb0 = "";
  31. if (data.unsortThumb1) unsortedAlbum.thumb1 = lychee.upload_path + data.unsortThumb1; else unsortedAlbum.thumb1 = "";
  32. if (data.unsortThumb2) unsortedAlbum.thumb2 = lychee.upload_path + data.unsortThumb2; else unsortedAlbum.thumb2 = "";
  33. starredAlbum = new Object();
  34. starredAlbum.id = "f";
  35. starredAlbum.title = "Starred";
  36. starredAlbum.sysdate = data.starredNum + " photos";
  37. starredAlbum.star = 1;
  38. if (data.starredThumb0) starredAlbum.thumb0 = lychee.upload_path + data.starredThumb0; else starredAlbum.thumb0 = "";
  39. if (data.starredThumb1) starredAlbum.thumb1 = lychee.upload_path + data.starredThumb1; else starredAlbum.thumb1 = "";
  40. if (data.starredThumb2) starredAlbum.thumb2 = lychee.upload_path + data.starredThumb2; else starredAlbum.thumb2 = "";
  41. publicAlbum = new Object();
  42. publicAlbum.id = "s";
  43. publicAlbum.title = "Public";
  44. publicAlbum.sysdate = data.publicNum + " photos";
  45. publicAlbum.public = 1;
  46. if (data.publicThumb0) publicAlbum.thumb0 = lychee.upload_path + data.publicThumb0; else publicAlbum.thumb0 = "";
  47. if (data.publicThumb1) publicAlbum.thumb1 = lychee.upload_path + data.publicThumb1; else publicAlbum.thumb1 = "";
  48. if (data.publicThumb2) publicAlbum.thumb2 = lychee.upload_path + data.publicThumb2; else publicAlbum.thumb2 = "";
  49. smartData = build.divider("Smart Albums") + build.album(unsortedAlbum) + build.album(starredAlbum) + build.album(publicAlbum);
  50. /* Albums */
  51. if (data.albums) {
  52. albumsData = build.divider("Albums");
  53. $.each(data.album, function() { albumsData += build.album(this); });
  54. } else albumsData = "";
  55. lychee.content.html(smartData + albumsData);
  56. lychee.animate(".album, .photo", "contentZoomIn");
  57. document.title = "Lychee";
  58. lychee.headerTitle.html("Albums").removeClass("editable");
  59. $("img").retina();
  60. loadingBar.hide();
  61. });
  62. })
  63. },
  64. loadInfo: function(albumID) {
  65. if (albumID=="f"||albumID=="s"||albumID==0) {
  66. lychee.headerTitle.removeClass("editable");
  67. lychee.api("getSmartInfo", "json", function(data) {
  68. switch (albumID) {
  69. case "f":
  70. document.title = "Lychee - Starred";
  71. lychee.headerTitle.html("Starred<span> - " + data.starredNum + " photos</span>");
  72. $("#button_edit_album, #button_trash_album, .button_divider").hide();
  73. break;
  74. case "s":
  75. document.title = "Lychee - Public";
  76. lychee.headerTitle.html("Public<span> - " + data.publicNum + " photos</span>");
  77. $("#button_edit_album, #button_trash_album, .button_divider").hide();
  78. break;
  79. case "0":
  80. document.title = "Lychee - Unsorted";
  81. lychee.headerTitle.html("Unsorted<span> - " + data.unsortNum + " photos</span>");
  82. $("#button_edit_album").hide();
  83. $("#button_trash_album, .button_divider").show();
  84. break;
  85. }
  86. loadingBar.hide();
  87. });
  88. } else {
  89. params = "getAlbumInfo&albumID=" + albumID;
  90. lychee.api(params, "json", function(data) {
  91. $("#button_edit_album, #button_trash_album, .button_divider").show();
  92. if (!data.title) data.title = "Untitled";
  93. document.title = "Lychee - " + data.title;
  94. lychee.headerTitle.html(data.title + "<span> - " + data.num + " photos</span>").addClass("editable");
  95. loadingBar.hide();
  96. });
  97. }
  98. },
  99. add: function() {
  100. title = prompt("Please enter a title for this album:", "Untitled");
  101. lychee.closeModal();
  102. if (title.length>2&&title.length<31) {
  103. loadingBar.show();
  104. params = "addAlbum&title=" + escape(title);
  105. lychee.api(params, "text", function(data) {
  106. if (data) lychee.goto("a" + data);
  107. else loadingBar.show("error");
  108. });
  109. } else if (title.length>0) loadingBar.show("error", "Error", "Title to short or too long. Please try another one!");
  110. },
  111. hide: function(albumID) {
  112. $(".album[data-id='" + albumID + "']").css("opacity", 0).animate({
  113. width: 0,
  114. marginLeft: 0
  115. }, 300, function() {
  116. $(this).remove();
  117. });
  118. },
  119. delete: function(albumID, delAll) {
  120. loadingBar.show();
  121. params = "deleteAlbum&albumID=" + albumID + "&delAll=" + delAll;
  122. lychee.api(params, "text", function(data) {
  123. if (data) {
  124. if (visible.albums()) {
  125. albums.hide(albumID);
  126. loadingBar.hide();
  127. } else lychee.goto("");
  128. } else loadingBar.show("error");
  129. });
  130. },
  131. deleteDialog: function(albumID) {
  132. if (albumID==0) {
  133. f1 = "albums.delete(0, true);";
  134. f2 = "";
  135. modal = build.modal("Clear Unsorted", "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!", ["Clear Unsorted", "Keep Photos"], [f1, f2]);
  136. $("body").append(modal);
  137. } else {
  138. if (visible.albums()) albumTitle = $(".album[data-id='" + albumID + "'] .overlay h1").html();
  139. else albumTitle = lychee.title();
  140. f1 = "albums.delete(" + albumID + ", true);";
  141. f2 = "albums.delete(" + albumID + ", false);";
  142. modal = build.modal("Delete Album", "Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!", ["Delete Album and Photos", "Keep Photos"], [f1, f2]);
  143. $("body").append(modal);
  144. }
  145. },
  146. rename: function(albumID) {
  147. if (!albumID) oldTitle = lychee.title(); else oldTitle = "";
  148. if (!albumID) albumID = lychee.content.attr("data-id");
  149. newTitle = prompt("Please enter a new title for this album:", oldTitle);
  150. if (albumID!=""&&albumID!=null&&albumID&&newTitle.length>2&&newTitle.length<31) {
  151. loadingBar.show();
  152. params = "setAlbumTitle&albumID=" + albumID + "&title=" + encodeURI(newTitle);
  153. lychee.api(params, "text", function(data) {
  154. if (data) {
  155. if (visible.albums()) $(".album[data-id='" + albumID + "'] .overlay h1").html(newTitle);
  156. else {
  157. lychee.headerTitle.html(newTitle + "<span>" + $("#title span").html() + "</span>");
  158. document.title = "Lychee - " + newTitle;
  159. }
  160. loadingBar.hide();
  161. } else loadingBar.show("error");
  162. });
  163. } else if (newTitle.length>0) loadingBar.show("error", "Error", "New title to short or too long. Please try another one!");
  164. },
  165. getArchive: function() {
  166. albumID = lychee.content.attr("data-id");
  167. if (location.href.indexOf("index.html")>0) link = location.href.replace(location.hash, "").replace("index.html", "php/api.php?function=getAlbumArchive&albumID=" + albumID);
  168. else link = location.href.replace(location.hash, "") + "php/api.php?function=getAlbumArchive&albumID=" + albumID;
  169. location.href = link;
  170. }
  171. }