4 * @param object|null oRestApi
5 * @param object|null oSection
7 const Vote
= (function (oRestApi
, oSection
) {
11 // Initialize REST API
16 // Initialize section element
22 * Set REST API object.
24 * @param object|null oRestApi
26 function setRestApi(oRestApi
) {
33 * @param object|null oSection
35 function setSection(oSection
) {
49 * Load list of candidates.
51 async
function loadCandidates() {
52 var ul
= section
.querySelector('ul');
53 var list
= await restapi
.getCandidates();
59 for (var i
= 0; i
< list
.length
; i
++) {
61 var name
= list
[i
].name
;
62 ul
.innerHTML
+= `<li><button data-id="${id}">${name}</button></li>`;
71 function voteCandidate(el
) {
72 var id
= el
.dataset
.id
;
77 * Handle section events.
79 function handleEvents() {
80 section
.querySelector('ul').addEventListener('click', (event
) => {
81 var el
= event
.target
;
82 if (el
.matches('li button')) {
84 event
.stopPropagation();
92 * @param object|null oSection
94 function init(oSection
) {
102 console
.log("Admin section have not been set");
108 console
.log("REST API have not been set");
113 section
.innerHTML
= getHtml();
115 // Load list of candidates
118 // Handle section events