nopaque/app/static/js/resource-displays/resource-display.js
2024-12-02 09:34:17 +01:00

47 lines
1.1 KiB
JavaScript

nopaque.resource_displays.ResourceDisplay = class ResourceDisplay {
static htmlClass;
constructor(displayElement) {
this.displayElement = displayElement;
this.userId = this.displayElement.dataset.userId;
this.isInitialized = false;
if (this.userId) {
app.users.subscribe(this.userId)
.then((response) => {
app.socket.on('users.patch', (patch) => {
if (this.isInitialized) {this.onPatch(patch);}
});
});
app.users.get(this.userId)
.then((user) => {
this.init(user);
this.isInitialized = true;
});
}
}
init(user) {throw 'Not implemented';}
onPatch(patch) {throw 'Not implemented';}
setElement(element, value) {
switch (element.tagName) {
case 'INPUT': {
element.value = value;
M.updateTextFields();
break;
}
default: {
element.innerText = value;
break;
}
}
}
setElements(elements, value) {
for (let element of elements) {
this.setElement(element, value);
}
}
};