lychee/src/scripts/albums.js

164 lines
3.1 KiB
JavaScript
Raw Normal View History

/**
2015-07-11 12:16:11 +00:00
* @description Takes care of every action albums can handle and execute.
* @copyright 2015 by Tobias Reich
*/
2014-11-20 22:27:41 +00:00
albums = {
2014-11-20 21:28:30 +00:00
2014-11-20 22:27:41 +00:00
json: null
}
2014-11-20 21:28:30 +00:00
albums.load = function() {
2015-07-11 11:47:43 +00:00
let startTime = new Date().getTime()
2014-11-20 21:28:30 +00:00
2015-09-28 16:47:50 +00:00
lychee.animate('.content', 'contentZoomOut')
2014-11-20 21:28:30 +00:00
if (albums.json===null) {
params = {
parent: 0
}
api.post('Albums::get', params, function(data) {
2014-11-20 21:28:30 +00:00
2015-07-11 11:47:43 +00:00
let waitTime = 0
// Smart Albums
if (lychee.publicMode===false) albums._createSmartAlbums(data.smartalbums)
2014-11-20 21:28:30 +00:00
2015-07-11 11:47:43 +00:00
albums.json = data
2014-11-20 21:28:30 +00:00
// Calculate delay
2015-07-11 11:47:43 +00:00
let durationTime = (new Date().getTime() - startTime)
if (durationTime>300) waitTime = 0
else waitTime = 300 - durationTime
2014-11-20 21:28:30 +00:00
// Skip delay when opening a blank Lychee
2015-07-11 11:47:43 +00:00
if (!visible.albums() && !visible.photo() && !visible.album()) waitTime = 0
if (visible.album() && lychee.content.html()==='') waitTime = 0
2014-09-17 21:11:02 +00:00
2015-07-11 11:47:43 +00:00
setTimeout(() => {
header.setMode('albums')
view.albums.init()
2015-09-28 16:47:50 +00:00
lychee.animate(lychee.content, 'contentZoomIn')
2015-07-11 11:47:43 +00:00
}, waitTime)
2015-06-28 15:47:31 +00:00
2015-07-11 11:47:43 +00:00
})
2014-09-17 21:11:02 +00:00
2014-11-20 21:28:30 +00:00
} else {
2015-07-11 11:47:43 +00:00
setTimeout(() => {
header.setMode('albums')
view.albums.init()
2015-09-28 16:47:50 +00:00
lychee.animate(lychee.content, 'contentZoomIn')
2015-07-11 11:47:43 +00:00
}, 300)
2014-11-20 21:28:30 +00:00
}
}
albums.parse = function(album) {
2015-07-11 11:47:43 +00:00
if (album.password==='1' && lychee.publicMode===true) {
album.thumbs[0] = 'src/images/password.svg'
album.thumbs[1] = 'src/images/password.svg'
album.thumbs[2] = 'src/images/password.svg'
2014-11-20 21:28:30 +00:00
} else {
2015-07-11 11:47:43 +00:00
if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg'
if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg'
if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg'
2014-11-20 21:28:30 +00:00
}
2014-09-17 21:11:02 +00:00
2014-11-20 21:28:30 +00:00
}
2014-09-17 21:11:02 +00:00
2015-02-27 21:14:19 +00:00
albums._createSmartAlbums = function(data) {
data.unsorted = {
2015-07-11 11:47:43 +00:00
id : 0,
title : 'Unsorted',
sysdate : data.unsorted.num + ' photos',
unsorted : '1',
thumbs : data.unsorted.thumbs
}
2015-02-27 21:14:19 +00:00
data.starred = {
2015-07-11 11:47:43 +00:00
id : 'f',
title : 'Starred',
sysdate : data.starred.num + ' photos',
star : '1',
thumbs : data.starred.thumbs
}
2015-02-27 21:14:19 +00:00
data.public = {
2015-07-11 11:47:43 +00:00
id : 's',
title : 'Public',
sysdate : data.public.num + ' photos',
public : '1',
thumbs : data.public.thumbs
}
2015-02-27 21:14:19 +00:00
data.recent = {
2015-07-11 11:47:43 +00:00
id : 'r',
title : 'Recent',
sysdate : data.recent.num + ' photos',
recent : '1',
thumbs : data.recent.thumbs
}
2015-02-27 21:14:19 +00:00
}
albums.getByID = function(albumID) {
// Function returns the JSON of an album
2015-07-11 11:47:43 +00:00
if (albumID==null) return undefined
if (albumID instanceof Array)
albumID = albumID[0]
2015-07-11 11:47:43 +00:00
let json = undefined
let func = function() {
if (this.id==albumID) json = this
}
if (albums.json && albums.json.albums) {
$.each(albums.json.albums, func)
}
else if (album.subjson && album.subjson.albums) {
$.each(album.subjson.albums, func)
}
2015-07-11 11:47:43 +00:00
return json
}
albums.deleteByID = function(albumID) {
// Function returns the JSON of an album
2015-07-11 11:47:43 +00:00
if (albumID==null) return false
if (!albums.json) return false
if (!albums.json.albums) return false
2016-01-24 14:16:03 +00:00
let deleted = false
$.each(albums.json.albums, function(i) {
if (albums.json.albums[i].id==albumID) {
2015-07-11 11:47:43 +00:00
albums.json.albums.splice(i, 1)
deleted = true
return false
}
2015-07-11 11:47:43 +00:00
})
2015-07-11 11:47:43 +00:00
return deleted
}
2014-11-20 21:28:30 +00:00
albums.refresh = function() {
2014-09-17 21:11:02 +00:00
2015-07-11 11:47:43 +00:00
albums.json = null
2014-11-20 21:28:30 +00:00
}