class JobList extends RessourceList { static autoInit() { for (let jobListElement of document.querySelectorAll('.job-list:not(.no-autoinit)')) { new JobList(jobListElement); } } static options = { initialHtmlGenerator: (id) => { return `
search
Service Title and Description Status
`.trim(); }, item: `
delete send `.trim(), ressourceMapper: (job) => { return { 'id': job.id, 'creation-date': job.creation_date, 'description': job.description, 'service': job.service, 'service-1': job.service, 'service-2': job.service, 'status': job.status, 'title': job.title }; }, sortArgs: ['creation-date', {order: 'desc'}], valueNames: [ {data: ['id']}, {data: ['creation-date']}, {data: ['service']}, {name: 'service-1', attr: 'data-service'}, {name: 'service-2', attr: 'data-service'}, {name: 'status', attr: 'data-job-status'}, 'description', 'title' ] }; constructor(listElement, options = {}) { super(listElement, {...JobList.options, ...options}); } init(user) { this._init(user.jobs); } onClick(event) { let actionButtonElement = event.target.closest('.action-button'); let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action; let jobElement = event.target.closest('tr'); let jobId = jobElement.dataset.id; switch (action) { case 'delete-request': { Utils.deleteJobRequest(this.userId, jobId); break; } case 'view': { window.location.href = `/jobs/${jobId}`; break; } default: { break; } } } onPatch(patch) { let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)`); let filteredPatch = patch.filter(operation => re.test(operation.path)); for (let operation of filteredPatch) { switch(operation.op) { case 'add': { let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)$`); if (re.test(operation.path)) {this.add(operation.value);} break; } case 'remove': { let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)$`); if (re.test(operation.path)) { let [match, jobId] = operation.path.match(re); this.remove(jobId); } break; } case 'replace': { let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)/(service|status|description|title)$`); if (re.test(operation.path)) { let [match, jobId, valueName] = operation.path.match(re); this.replace(jobId, valueName, operation.value); } break; } default: { break; } } } } }