Files
timelapse-frontend/js/utilities/populate.js
2025-01-09 10:12:17 +01:00

44 lines
1.3 KiB
JavaScript

async function PopulateSelect(mySelect,id){
let data=[]
if(mySelect.name=="videos" && id!=null){
data=await getDataProjectVideosFromApi(id);
for(let i = 0 ; i < data.length ; i++){
const selectObj=document.createElement("option")
selectObj.value=data[i].id
selectObj.innerHTML=data[i].name
mySelect.appendChild(selectObj)
}
}
}
async function getDataProjectVideosFromApi(id) {
try {
const response = await $.ajax({
url: api_url.concat(`/projects/${id}/videos`),
method: "GET",
dataType: "json",
});
// If the request is successful, store the data in the cache and return it
return response;
} catch (error) {
console.error("Error fetching data:", error);
throw error; // Re-throw the error to handle it outside the function if needed
}
}
async function getDataVideoFromApi(id) {
try {
const response = await $.ajax({
url: api_url.concat(`/videos/${id}`),
method: "GET",
dataType: "json",
});
// If the request is successful, store the data in the cache and return it
return response;
} catch (error) {
console.error("Error fetching data:", error);
throw error; // Re-throw the error to handle it outside the function if needed
}
}