albums.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * @description Takes care of every action albums can handle and execute.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. albums = {
  6. json: null
  7. }
  8. albums.load = function() {
  9. var startTime,
  10. durationTime,
  11. waitTime;
  12. lychee.animate('#content', 'contentZoomOut');
  13. startTime = new Date().getTime();
  14. if (albums.json===null) {
  15. api.post('Album::getAll', {}, function(data) {
  16. /* Smart Albums */
  17. if (lychee.publicMode===false) albums._createSmartAlbums(data.smartalbums);
  18. albums.json = data;
  19. // Calculate delay
  20. durationTime = (new Date().getTime() - startTime);
  21. if (durationTime>300) waitTime = 0;
  22. else waitTime = 300 - durationTime;
  23. // Skip delay when opening a blank Lychee
  24. if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
  25. if (visible.album()&&lychee.content.html()==='') waitTime = 0;
  26. setTimeout(function() {
  27. header.setMode('albums');
  28. view.albums.init();
  29. lychee.animate('#content', 'contentZoomIn');
  30. }, waitTime);
  31. });
  32. } else {
  33. setTimeout(function() {
  34. header.setMode('albums');
  35. view.albums.init();
  36. lychee.animate('#content', 'contentZoomIn');
  37. }, 300);
  38. }
  39. }
  40. albums.parse = function(album) {
  41. if (album.password==='1'&&lychee.publicMode===true) {
  42. album.thumbs[0] = 'src/images/password.svg';
  43. album.thumbs[1] = 'src/images/password.svg';
  44. album.thumbs[2] = 'src/images/password.svg';
  45. } else {
  46. if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg';
  47. if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg';
  48. if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg';
  49. }
  50. }
  51. albums._createSmartAlbums = function(data) {
  52. data.unsorted = {
  53. id: 0,
  54. title: 'Unsorted',
  55. sysdate: data.unsorted.num + ' photos',
  56. unsorted: '1',
  57. thumbs: data.unsorted.thumbs
  58. };
  59. data.starred = {
  60. id: 'f',
  61. title: 'Starred',
  62. sysdate: data.starred.num + ' photos',
  63. star: '1',
  64. thumbs: data.starred.thumbs
  65. };
  66. data.public = {
  67. id: 's',
  68. title: 'Public',
  69. sysdate: data.public.num + ' photos',
  70. public: '1',
  71. thumbs: data.public.thumbs
  72. };
  73. data.recent = {
  74. id: 'r',
  75. title: 'Recent',
  76. sysdate: data.recent.num + ' photos',
  77. recent: '1',
  78. thumbs: data.recent.thumbs
  79. };
  80. }
  81. albums.getByID = function(albumID) {
  82. // Function returns the JSON of an album
  83. if (albumID===undefined||albumID===null) return undefined;
  84. if (!albums.json) return undefined;
  85. if (!albums.json.albums) return undefined;
  86. var json = undefined;
  87. $.each(albums.json.albums, function(i) {
  88. let elem = albums.json.albums[i];
  89. if (elem.id==albumID) json = elem;
  90. });
  91. return json;
  92. }
  93. albums.deleteByID = function(albumID) {
  94. // Function returns the JSON of an album
  95. if (albumID===undefined||albumID===null) return false;
  96. if (!albums.json) return false;
  97. if (!albums.json.albums) return false;
  98. var deleted = false;
  99. $.each(albums.json.albums, function(i) {
  100. if (albums.json.albums[i].id==albumID) {
  101. albums.json.albums.splice(i, 1);
  102. deleted = true;
  103. return false;
  104. }
  105. });
  106. return deleted;
  107. }
  108. albums.refresh = function() {
  109. albums.json = null;
  110. }