nopaque/app/static/js/resource-displays/resource-display.js

42 lines
997 B
JavaScript
Raw Normal View History

nopaque.resource_displays.ResourceDisplay = class ResourceDisplay {
static htmlClass;
constructor(displayElement) {
this.displayElement = displayElement;
this.userId = this.displayElement.dataset.userId;
this.isInitialized = false;
2024-12-03 14:59:08 +00:00
if (this.userId === undefined) {return;}
2024-12-05 13:26:05 +00:00
app.userHub.addEventListener('patch', (event) => {
2024-12-03 14:59:08 +00:00
if (this.isInitialized) {this.onPatch(event.detail);}
});
2024-12-05 13:26:05 +00:00
app.userHub.get(this.userId).then((user) => {
2024-12-03 14:59:08 +00:00
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);
}
}
};