blob: 3a8e551f42bb761eba48412c947be2a237e5e3d3 (
plain) (
blame)
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
|
import { Manager } from "./utils.mjs";
class Court {
constructor(id, status) {
this.id = id;
this.status = typeof status !== "undefined" ? status : true;
this.name = "Court " + (id + 1);
}
toggle() {
this.status = !this.status;
this.print();
}
print() {
let status = this.status ? "active" : "inactive";
console.log(this.name + " is currently " + status);
}
render() {
let type = this.status
? `class="button is-medium is-success"`
: 'class="button is-medium is-danger"';
return `<button id=${"court_" + this.id} ${type}>${this.name}</button>`;
}
}
export class CourtManager extends Manager {
maxCourtCount = 12;
constructor() {
super("court", []);
console.log("Loading court data.");
let data = JSON.parse(localStorage.getItem(this.description));
if (data === null || data.length != this.maxCourtCount) {
console.log("Court data unavailable: " + data);
this.generate();
return;
}
for (let i = 0; i < this.maxCourtCount; i++) {
this.listData.push(new Court(data[i].id, data[i].status));
}
console.log("Loaded " + this.listData.length + " courts.");
this.render();
}
generate() {
console.log("Generating court data.");
for (let i = 0; i < this.maxCourtCount; i++) {
this.listData.push(new Court(i));
}
console.log("Generated data for " + this.listData.length + " courts");
this.store();
this.render();
}
}
|