albums.js 3.0 KB

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