Parcourir la source

Get albums and put them in the select as options

Onestay il y a 7 ans
Parent
commit
e5cd142347
1 fichiers modifiés avec 18 ajouts et 1 suppressions
  1. 18 1
      public/js/home.js

+ 18 - 1
public/js/home.js

@@ -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');