Get albums and put them in the select as options

This commit is contained in:
Onestay 2017-04-23 14:29:09 +02:00
parent 81f1707835
commit e5cd142347

View File

@ -62,7 +62,24 @@ upload.verifyToken = function(token, reloadOnError){
upload.prepareUpload = function(){
if (upload.token) {
document.getElementById('albumDiv').style.display = 'block';
const select = document.querySelector('select');
axios.get('/api/albums', { headers: { token: upload.token }})
.then((res) => {
console.log(res);
let albums = res.data.albums;
if (albums.length === 0) return;
for (let i = 0; i < albums.length; i++) {
let opt = document.createElement('option');
opt.value = albums[i].id;
opt.innerHTML = albums[i].name;
select.appendChild(opt);
}
document.getElementById('albumDiv').style.display = 'block';
})
.catch((e) => {
console.log(e);
})
}
div = document.createElement('div');