intermediate update on displays and forms 1/2

This commit is contained in:
Patrick Jentsch
2023-10-10 11:06:44 +02:00
parent 9fe38fab52
commit c7dab5e502
6 changed files with 216 additions and 210 deletions

View File

@ -1,31 +1,37 @@
class ResourceList {
var ResourceLists = {};
ResourceLists.autoInit = () => {
for (let propertyName in ResourceLists) {
let property = ResourceLists[propertyName];
// Call autoInit of all properties that are subclasses of `ResourceLists.BaseList`.
// This does not include `ResourceLists.BaseList` itself.
if (property.prototype instanceof ResourceLists.BaseList) {
// Check if the static `htmlClass` property is defined.
if (property.htmlClass === undefined) {return;}
// Gather all HTML elements that have the `this.htmlClass` class
// and do not have the `no-autoinit` class.
let listElements = document.querySelectorAll(`.${property.htmlClass}:not(.no-autoinit)`);
// Create an instance of this class for each display element.
for (let listElement of listElements) {new property(listElement);}
}
}
};
ResourceLists.defaultOptions = {
page: 5,
pagination: {
innerWindow: 2,
outerWindow: 2
}
};
ResourceLists.BaseList = class BaseList {
/* A wrapper class for the list.js list.
* This class is not meant to be used directly, instead it should be used as
* a base class for concrete resource list implementations.
*/
static autoInit() {
CorpusList.autoInit();
CorpusFileList.autoInit();
JobList.autoInit();
JobInputList.autoInit();
JobResultList.autoInit();
SpaCyNLPPipelineModelList.autoInit();
TesseractOCRPipelineModelList.autoInit();
UserList.autoInit();
AdminUserList.autoInit();
CorpusFollowerList.autoInit();
CorpusTextInfoList.autoInit();
CorpusTokenList.autoInit();
}
static defaultOptions = {
page: 5,
pagination: {
innerWindow: 2,
outerWindow: 2
}
};
static htmlClass;
constructor(listContainerElement, options = {}) {
if ('items' in options) {
@ -36,7 +42,7 @@ class ResourceList {
}
let _options = Utils.mergeObjectsDeep(
{item: this.item, valueNames: this.valueNames},
ResourceList.defaultOptions,
ResourceLists.defaultOptions,
options
);
this.listContainerElement = listContainerElement;