class RessourceList { /* 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 ressource list implementations. */ static autoInit() { const nopaqueRessourceListElements = document.querySelectorAll('.nopaque-ressource-list[data-ressource-type]:not(.no-autoinit)'); let nopaqueRessourceListElement; for (nopaqueRessourceListElement of nopaqueRessourceListElements) { switch (nopaqueRessourceListElement.dataset.ressourceType) { case 'Corpus': new CorpusList(nopaqueRessourceListElement); break; case 'CorpusFile': new CorpusFileList(nopaqueRessourceListElement); break; case 'Job': new JobList(nopaqueRessourceListElement); break; case 'JobInput': new JobInputList(nopaqueRessourceListElement); break; case 'JobResult': new JobResultList(nopaqueRessourceListElement); break; case 'QueryResult': new QueryResultList(nopaqueRessourceListElement); break; case 'User': new UserList(nopaqueRessourceListElement); break; default: break; } } } static options = {page: 5, pagination: {innerWindow: 4, outerWindow: 1}}; constructor(listElement, options = {}) { let i; if (!(listElement.hasAttribute('id'))) { for (i = 0; true; i++) { if (document.querySelector(`#ressource-list-${i}`)) {continue;} listElement.id = `ressource-list-${i}`; break; } } options = { ...{pagination: {item: `
  • `}}, ...options } if ('ressourceMapper' in options) { this.ressourceMapper = options.ressourceMapper; delete options.ressourceMapper; } if ('sortValueName' in options) { this.sortValueName = options.sortValueName; delete options.sortValueName; } this.listjs = new List(listElement, {...RessourceList.options, ...options}); this.listjs.list.innerHTML = `
     
    Waiting for data...

    This list is not initialized yet.

    `.trim(); this.listjs.list.style.cursor = 'pointer'; this.userId = this.listjs.listContainer.dataset.userId; this.listjs.list.addEventListener('click', event => this.onclick(event)); if (this.userId) { app.addEventListener('users.patch', patch => this.usersPatchHandler(patch)); app.getUserById(this.userId).then( user => this.init(user), error => {throw JSON.stringify(error);} ); } } _init(ressources) { this.listjs.clear(); this.add(Object.values(ressources)); let emptyListElementHTML = ` file_downloadNothing here...

    No ressource available.

    `.trim(); this.listjs.list.insertAdjacentHTML('afterbegin', emptyListElementHTML); } init(user) {throw 'Not implemented';} onclick(event) {throw 'Not implemented';} usersPatchHandler(patch) {throw 'Not implemented';} add(ressources) { let values = Array.isArray(ressources) ? ressources : [ressources]; if ('ressourceMapper' in this) { values = values.map(value => this.ressourceMapper(value)); } this.listjs.add(values, () => { if ('sortValueName' in this) { this.listjs.sort(this.sortValueName, {order: 'desc'}); } }); } remove(id) { this.listjs.remove('id', id); } replace(id, valueName, newValue) { this.listjs.get('id', id)[0].values({[valueName]: newValue}); } }