nopaque/app/static/js/ResourceDisplays/ResourceDisplay.js

45 lines
1009 B
JavaScript
Raw Normal View History

2023-03-08 11:42:53 +01:00
class ResourceDisplay {
constructor(displayElement) {
this.displayElement = displayElement;
2021-11-30 16:22:16 +01:00
this.userId = this.displayElement.dataset.userId;
this.isInitialized = false;
if (this.userId) {
2022-09-02 13:07:30 +02:00
app.subscribeUser(this.userId)
.then((response) => {
app.socket.on('PATCH', (patch) => {
if (this.isInitialized) {this.onPatch(patch);}
});
});
app.getUser(this.userId)
.then((user) => {
this.init(user);
this.isInitialized = true;
});
}
}
2021-11-30 16:22:16 +01:00
init(user) {throw 'Not implemented';}
2022-09-02 13:07:30 +02:00
onPatch(patch) {throw 'Not implemented';}
setElement(element, value) {
switch (element.tagName) {
2022-09-02 13:07:30 +02:00
case 'INPUT': {
element.value = value;
M.updateTextFields();
break;
2022-09-02 13:07:30 +02:00
}
default: {
element.innerText = value;
break;
2022-09-02 13:07:30 +02:00
}
}
}
2021-12-01 14:15:20 +01:00
setElements(elements, value) {
2022-09-02 13:07:30 +02:00
for (let element of elements) {
2021-12-01 14:15:20 +01:00
this.setElement(element, value);
}
}
}