album.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * @name album.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2013 by Philipp Maurer, Tobias Reich
  6. *
  7. * Album Module
  8. * Takes care of every action an album can handle and execute.
  9. */
  10. album = {
  11. json: null,
  12. getID: function() {
  13. var id;
  14. if (photo.json) id = photo.json.album;
  15. else if (album.json) id = album.json.id;
  16. else id = $(".album:hover, .album.active").attr("data-id");
  17. // Search
  18. if (!id) id = $(".photo:hover, .photo.active").attr("data-album-id");
  19. if (id) return id;
  20. else return false;
  21. },
  22. load: function(albumID, refresh) {
  23. var startTime,
  24. params,
  25. durationTime,
  26. waitTime,
  27. photosData = "";
  28. password.get(albumID, function() {
  29. if (!refresh) {
  30. loadingBar.show();
  31. lychee.animate(".album, .photo", "contentZoomOut");
  32. lychee.animate(".divider", "fadeOut");
  33. }
  34. startTime = new Date().getTime();
  35. params = "getAlbum&albumID=" + albumID + "&password=" + password.value;
  36. lychee.api(params, "json", function(data) {
  37. if (data=="HTTP/1.1 403 Album private!") {
  38. lychee.setMode("view");
  39. return false;
  40. }
  41. if (data=="HTTP/1.1 403 Wrong password!") {
  42. album.load(albumID, refresh);
  43. return false;
  44. }
  45. album.json = data;
  46. durationTime = (new Date().getTime() - startTime);
  47. if (durationTime>300) waitTime = 0; else if (refresh) waitTime = 0; else waitTime = 300 - durationTime;
  48. if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
  49. setTimeout(function() {
  50. view.album.init();
  51. if (!refresh) {
  52. lychee.animate(".album, .photo", "contentZoomIn");
  53. view.header.mode("album");
  54. }
  55. }, waitTime);
  56. });
  57. });
  58. },
  59. parse: function(photo) {
  60. if (photo&&photo.thumbUrl) photo.thumbUrl = lychee.upload_path_thumb + photo.thumbUrl;
  61. else if (!album.json.title) album.json.title = "Untitled";
  62. },
  63. add: function() {
  64. var title = prompt("Please enter a title for this album:", "Untitled"),
  65. params;
  66. if (title.length>0&&title.length<31) {
  67. modal.close();
  68. params = "addAlbum&title=" + escape(encodeURI(title));
  69. lychee.api(params, "text", function(data) {
  70. if (data) lychee.goto("a" + data);
  71. else loadingBar.show("error");
  72. });
  73. } else if (title.length>0) loadingBar.show("error", "Error", "Title to short or too long. Please try another one!");
  74. },
  75. delete: function(albumID) {
  76. var params,
  77. buttons,
  78. albumTitle;
  79. buttons = [
  80. ["Delete Album and Photos", function() {
  81. params = "deleteAlbum&albumID=" + albumID + "&delAll=true";
  82. lychee.api(params, "text", function(data) {
  83. if (visible.albums()) view.albums.content.delete(albumID);
  84. else lychee.goto("");
  85. if (!data) loadingBar.show("error");
  86. });
  87. }],
  88. ["Keep Album", function() {}]
  89. ];
  90. if (albumID==0) {
  91. buttons[0][0] = "Clear Unsorted";
  92. modal.show("Clear Unsorted", "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!", buttons)
  93. } else {
  94. if (album.json) albumTitle = album.json.title;
  95. else if (albums.json) albumTitle = albums.json.content[albumID].title;
  96. modal.show("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!", buttons);
  97. }
  98. },
  99. setTitle: function(albumID) {
  100. var oldTitle = "",
  101. newTitle,
  102. params;
  103. if (!albumID) albumID = album.getID();
  104. if (album.json) oldTitle = album.json.title;
  105. else if (albums.json) oldTitle = albums.json.content[albumID].title;
  106. newTitle = prompt("Please enter a new title for this album:", oldTitle);
  107. if (albumID!=""&&albumID!=null&&albumID&&newTitle.length>0&&newTitle.length<31) {
  108. if (visible.album()) {
  109. album.json.title = newTitle;
  110. view.album.title();
  111. } else if (visible.albums()) {
  112. albums.json.content[albumID].title = newTitle;
  113. view.albums.content.title(albumID);
  114. }
  115. params = "setAlbumTitle&albumID=" + albumID + "&title=" + escape(encodeURI(newTitle));
  116. lychee.api(params, "text", function(data) {
  117. if (!data) loadingBar.show("error");
  118. });
  119. } else if (newTitle.length>0) loadingBar.show("error", "Error", "New title to short or too long. Please try another one!");
  120. },
  121. setPublic: function(albumID, e) {
  122. var params;
  123. if ($("input.password").length>0&&$("input.password").val().length>0) {
  124. params = "setAlbumPublic&albumID=" + albumID + "&password=" + hex_md5($("input.password").val());
  125. album.json.password = true;
  126. } else {
  127. params = "setAlbumPublic&albumID=" + albumID;
  128. album.json.password = false;
  129. }
  130. if (visible.album()) {
  131. album.json.public = (album.json.public==0) ? 1 : 0;
  132. view.album.public();
  133. if (album.json.public==1) contextMenu.shareAlbum(albumID, e);
  134. }
  135. lychee.api(params, "text", function(data) {
  136. if (!data) loadingBar.show("error");
  137. });
  138. },
  139. share: function(service) {
  140. var link = "",
  141. url = location.href;
  142. switch (service) {
  143. case 0:
  144. link = "https://twitter.com/share?url=" + encodeURI(url);
  145. break;
  146. case 1:
  147. link = "http://www.facebook.com/sharer.php?u=" + encodeURI(url) + "&t=" + encodeURI(album.json.title);
  148. break;
  149. case 2:
  150. link = "mailto:?subject=" + encodeURI(album.json.title) + "&body=" + encodeURI("Hi! Check this out: " + url);
  151. break;
  152. default:
  153. link = "";
  154. break;
  155. }
  156. if (link.length>5) location.href = link;
  157. },
  158. getArchive: function(albumID) {
  159. var link;
  160. if (location.href.indexOf("index.html")>0) link = location.href.replace(location.hash, "").replace("index.html", "php/api.php?function=getAlbumArchive&albumID=" + albumID);
  161. else link = location.href.replace(location.hash, "") + "php/api.php?function=getAlbumArchive&albumID=" + albumID;
  162. location.href = link;
  163. }
  164. }