class RessourceList { constructor(idOrElement, options = {}) { this.list = new List(idOrElement, {...RessourceList.options, ...options}); } init(ressources) { this.list.clear(); this.add(Object.values(ressources)); this.list.sort('id', {order: 'desc'}); } update(patch) { let item, pathArray; for (let operation of patch) { /* * '/{ressourceName}/{ressourceId}/{valueName}' -> ['{ressourceId}', {valueName}] * Example: '/jobs/1/status' -> ['1', 'status'] */ let [id, valueName] = operation.path.split("/").slice(2); switch(operation.op) { case 'add': this.add(operation.value); break; case 'remove': this.remove(id); break; case 'replace': this.replace(id, valueName, operation.value); break; default: break; } } } add(values) { /* WORKAROUND: Set a callback function ('() => {return;}') to force List.js perform the add method asynchronous. * https://listjs.com/api/#add */ this.list.add(values, () => {return;}); } remove(id) { this.list.remove('id', id); } replace(id, valueName, newValue) { if (!this.list.valuesNames.includes(valueName)) {return;} let item = this.list.get('id', id); item.values({[valueName]: newValue}); } } RessourceList.options = {page: 5, pagination: [{innerWindow: 4, outerWindow: 1}]}; class CorpusList extends RessourceList { constructor(listElementId, options = {}) { let listElement = document.querySelector(`#${listElementId}`); super(listElement, {...CorpusList.options, ...options}); listElement.addEventListener('click', (event) => { let actionButtonElement = event.target.closest('.action-button'); if (actionButtonElement === null) {return;} let corpusId = event.target.closest('tr').dataset.id; let action = actionButtonElement.dataset.action; switch (action) { case 'analyse': window.location.href = nopaque.user.corpora[corpusId].analysis_url; } }); nopaque.corporaSubscribers.push(this); } } CorpusList.options = { item: `