Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Imports
import * as Auth from "/services/auth/auth.js";
import * as ElectionModel from "/services/model/election-model.js";
import * as RoundModel from "/services/model/round-model.js";
export async function mount(where, parent) {
const roundSelectionComponent = new RoundSelectionComponent(parent);
await roundSelectionComponent.mount(where);
}
class RoundSelectionComponent {
constructor(parent) {
this.parent = parent;
this.ElectionModel = ElectionModel.getElectionModel();
this.RoundModel = RoundModel.getRoundModel();
}
async mount(where) {
this.ElectionModel.current_user = await Auth.GetUser();
this.RoundModel.current_user = await Auth.GetUser();
const mountpoint = where;
document.getElementById(mountpoint).innerHTML = /* HTML */ `
<div class="container">
<div class="card-no-hover">
<header class="card-header">
<p class="card-header-title">
Tours
</p>
</header>
<div class="card-content">
<div id="round-list" class="content">Liste des tours</div>
</div>
</div>
</div>
`;
this.displayRounds();
}
roundTemplate(round) {
return /* HTML */ `<div class="card card-list">
<div id="rounds-round-${round.ID}" class="card-content">
<div class="content">
<nav class="level">
<div id="rounds-round-desc-${round.ID}" class="level-left">
(tour : ${round.Round}, date :
${new Date(round.Date).toLocaleDateString()})
</div>
</nav>
</div>
</div>
</div>`;
}
async displayRounds() {
let rounds = await this.RoundModel.getRounds();
const markup = rounds.map((round) => this.roundTemplate(round)).join("");
document.getElementById("round-list").innerHTML = markup;
let roundHandler = this;
rounds.map(async (round) => {
let election = await this.ElectionModel.getElection(round.ElectionID);
document.getElementById(`rounds-round-desc-${round.ID}`).innerHTML =
election.Name +
" " +
document.getElementById(`rounds-round-desc-${round.ID}`).innerHTML;
document
.getElementById(`rounds-round-${round.ID}`)
.addEventListener("click", async function () {
roundHandler.activateRound(round);
});
});
}
async activateRound(round) {
await this.parent.displayRound(round);
}
}