Select Git revision
sco_version.py
Forked from
Jean-Marie Place / SCODOC_R6A06
Source project has a limited visibility.
-
Emmanuel Viennet authoredEmmanuel Viennet authored
user.client.js 6.50 KiB
let userlogin;
let userpassword;
let username;
//const displayShowList = require('./utils');
const setup = () => {
username = document.getElementById('username');
getUser();
// document.getElementById('update').addEventListener('click', update);
displayShowList();
displayTicketsList();
document.getElementById('logout').addEventListener('click', logout);
}
window.addEventListener('DOMContentLoaded', setup);
const getUser = async () => {
const requestOptions = {
method :'GET',
};
const response = await fetch('/me', requestOptions);
if (response.ok) {
const user = await response.json();
username.textContent = user.name;
}
else {
const error = await response.json();
handleError(error);
}
}
const displayShowList = async () => {
const requestOptions = {
method : 'GET'
};
const response = await fetch('/admin/items', requestOptions)
const allShows = await response.json();
//(ici : code exploitation de allShows)
const list = document.getElementById('list');
list.textContent = '';
allShows.forEach( show => addToList(show, list) );
}
const addToList = (show,list) => {
const node = document.createElement('div');
node.id = show._id;
const span = document.createElement('span');
span.className = "places";
span.textContent = `${show.places} places`
node.textContent = `${show.description} : `;
node.appendChild(span);
//
//node.addEventListener('mouseover', () => getTask(show._id));
//
const ticketsButton = document.createElement('button');
ticketsButton.className = 'ticket';
ticketsButton.addEventListener('click', addTicketShow);
ticketsButton.textContent = '+1 tickets';
node.appendChild(ticketsButton);
//
list.appendChild(node);
}
const update = async (data) => {
const body = JSON.stringify(data);
const requestOptions = {
method :'PUT',
headers : { "Content-Type": "application/json" },
body : body