mes trucs
This commit is contained in:
41
js/index.js
Normal file
41
js/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// Function to display projects in a table
|
||||
function display_projects() {
|
||||
// Get data from API and then generate HTML code to display the data in a table
|
||||
const table = document.getElementById("table-projects");
|
||||
let datas = `<tr>
|
||||
<th>Id</th>
|
||||
<th>Name</th>
|
||||
<th>Actions</th>
|
||||
</tr> `;
|
||||
for (let i = 0; i < global_project_list.rows.length; i++) {
|
||||
datas += `<tr>
|
||||
<th>${global_project_list.rows[i].id}</th>
|
||||
<th>${global_project_list.rows[i].name}</th>
|
||||
<th><button class="project_detail btn btn-primary">détails de ${global_project_list.rows[i].name}</button></th>
|
||||
</tr>`;
|
||||
}
|
||||
table.innerHTML = datas;
|
||||
|
||||
// Select all the buttons with the class button_project
|
||||
const buttons = document.getElementsByClassName("project_detail");
|
||||
// Add an event listener to each button
|
||||
for (let i = 0; i < buttons.length; i++) {
|
||||
buttons[i].addEventListener("click", (event) => {
|
||||
// Send data to API and then navigate to projet_detail.html page
|
||||
window.location.href = `html/projet_detail.html?id=${global_project_list.rows[i].id}`;
|
||||
});
|
||||
buttons[i].addEventListener("onclick", (event) => {
|
||||
// Send data to API and then navigate to projet_detail.html page
|
||||
current_project=change_current_project(i);
|
||||
});
|
||||
}
|
||||
}
|
||||
getDataFromApi()
|
||||
.then(project_list => {
|
||||
global_project_list = project_list;
|
||||
// Call the next function here
|
||||
display_projects();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
Reference in New Issue
Block a user