nopaque/app/static/js/RessourceDisplays/RessourceDisplay.js

41 lines
926 B
JavaScript
Raw Normal View History

class RessourceDisplay {
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) {
app.subscribeUser(this.userId).then((response) => {
app.socket.on('PATCH', (patch) => {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-07-04 14:09:17 +02:00
onPATCH(patch) {throw 'Not implemented';}
setElement(element, value) {
switch (element.tagName) {
case 'INPUT':
element.value = value;
M.updateTextFields();
break;
default:
element.innerText = value;
break;
}
}
2021-12-01 14:15:20 +01:00
setElements(elements, value) {
let element;
for (element of elements) {
this.setElement(element, value);
}
}
}