albums.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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('.album, .photo', 'contentZoomOut');
  13. lychee.animate('.divider', 'fadeOut');
  14. startTime = new Date().getTime();
  15. if (albums.json===null) {
  16. api.post('Album::getAll', {}, function(data) {
  17. /* Smart Albums */
  18. if (lychee.publicMode===false) albums._createSmartAlbums(data.smartalbums);
  19. albums.json = data;
  20. // Calculate delay
  21. durationTime = (new Date().getTime() - startTime);
  22. if (durationTime>300) waitTime = 0;
  23. else waitTime = 300 - durationTime;
  24. // Skip delay when opening a blank Lychee
  25. if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
  26. if (visible.album()&&lychee.content.html()==='') waitTime = 0;
  27. setTimeout(function() {
  28. header.setMode('albums');
  29. view.albums.init();
  30. lychee.animate('.album', 'contentZoomIn');
  31. }, waitTime);
  32. });
  33. } else {
  34. setTimeout(function() {
  35. header.setMode('albums');
  36. view.albums.init();
  37. lychee.animate('.album, .photo', 'contentZoomIn');
  38. }, 300);
  39. }
  40. }
  41. albums.parse = function(album) {
  42. if (album.password==='1'&&lychee.publicMode===true) {
  43. album.thumbs[0] = 'src/images/password.svg';
  44. album.thumbs[1] = 'src/images/password.svg';
  45. album.thumbs[2] = 'src/images/password.svg';
  46. } else {
  47. if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg';
  48. if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg';
  49. if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg';
  50. }
  51. }
  52. albums._createSmartAlbums = function(data) {
  53. data.unsorted = {
  54. id: 0,
  55. title: 'Unsorted',
  56. sysdate: data.unsorted.num + ' photos',
  57. unsorted: '1',
  58. thumbs: data.unsorted.thumbs
  59. };
  60. data.starred = {
  61. id: 'f',
  62. title: 'Starred',
  63. sysdate: data.starred.num + ' photos',
  64. star: '1',
  65. thumbs: data.starred.thumbs
  66. };
  67. data.public = {
  68. id: 's',
  69. title: 'Public',
  70. sysdate: data.public.num + ' photos',
  71. public: '1',
  72. thumbs: data.public.thumbs
  73. };
  74. data.recent = {
  75. id: 'r',
  76. title: 'Recent',
  77. sysdate: data.recent.num + ' photos',
  78. recent: '1',
  79. thumbs: data.recent.thumbs
  80. };
  81. }
  82. albums.refresh = function() {
  83. albums.json = null;
  84. }