aboutsummaryrefslogtreecommitdiff
path: root/court.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'court.mjs')
-rw-r--r--court.mjs84
1 files changed, 43 insertions, 41 deletions
diff --git a/court.mjs b/court.mjs
index cb895f0..3a8e551 100644
--- a/court.mjs
+++ b/court.mjs
@@ -1,50 +1,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-success"` : 'class="button is-danger"';
- return `<button id=${"court_" + this.id} ${type}>${this.name}</button>`;
- }
+ 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;
+ 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();
+ 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));
}
- 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();
+ 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));
}
-} \ No newline at end of file
+ console.log("Generated data for " + this.listData.length + " courts");
+ this.store();
+ this.render();
+ }
+}