albums.js 3.0 KB

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