blob: 0ac9195c1087dc23275fb7242af2ae4e8ac05c4a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
import apiConnector from "./connector.js"
class Album {
static albums = []
static albumTemplate = null
static albumContainer = null
constructor(data) {
this.data = data
// create clone element
const e = Album.albumTemplate.content.cloneNode(true)
e.firstElementChild.dataset.key = data.id
e.querySelector("a").href = apiConnector.albumSrc(data.id)
e.querySelector("img").src = apiConnector.assetThumbnailSrc(data.albumThumbnailAssetId)
e.querySelector(".album-name").textContent = data.albumName
e.querySelector(".album-assets-count").textContent = data.assetCount.toLocaleString()
if (!data.shared)
e.querySelector(".album-shared").remove()
Album.albums.push(this)
Album.albumsContainer.appendChild(e)
this.element = Album.albumsContainer.lastElementChild
if (data.selected)
this.element.dataset.selected = "1"
}
toggleVisibility(visible) { this.element.classList.toggle("hidden!", !visible) }
static albumSelect(e) {
// find album element
let album = e.target
while (album && !album.classList.contains("album"))
album = album.parentElement
if (album === null)
return
if (album.dataset.selected)
delete album.dataset.selected
else
album.dataset.selected = "1"
}
static albumsFilter(e) {
const q = e.target.value.toLowerCase()
for (const album of Album.albums) {
const match = album.data.albumName.toLowerCase().includes(q)
album.toggleVisibility(match)
}
}
static getSelected() {
const s = []
for (const album of Album.albums)
if (album.element.dataset.selected)
s.push(album.data.id)
return s
}
static submitSelected() {
apiConnector.updateAlbums(Album.getSelected())
}
static async initAlbums(albumsPageContainer) {
Album.albumsContainer = albumsPageContainer.querySelector("#albums-container")
Album.albumTemplate = albumsPageContainer.querySelector("#album-template")
const albumSearch = albumsPageContainer.querySelector("#album-search")
const albumsSubmit = albumsPageContainer.querySelector("#albums-submit")
// create albums
const albumsResponse = await apiConnector.fetchAlbums()
if (!albumsResponse.length)
return false
for (const res of albumsResponse)
new Album(res)
// album selection
Album.albumsContainer.addEventListener("click", Album.albumSelect)
albumSearch.addEventListener("input", Album.albumsFilter)
albumsSubmit.addEventListener("click", Album.submitSelected)
return true
}
}
export default Album.initAlbums
|