class TesseractOCRPipelineModelList extends ResourceList { static autoInit() { for (let tesseractOCRPipelineModelListElement of document.querySelectorAll('.tesseract-ocr-pipeline-model-list:not(.no-autoinit)')) { new TesseractOCRPipelineModelList(tesseractOCRPipelineModelListElement); } } constructor(listContainerElement, options = {}) { super(listContainerElement, options); this.listjs.list.addEventListener('change', (event) => {this.onChange(event)}); this.listjs.list.addEventListener('click', (event) => {this.onClick(event)}); this.isInitialized = false; this.userId = listContainerElement.dataset.userId; app.subscribeUser(this.userId).then((response) => { app.socket.on('PATCH', (patch) => { if (this.isInitialized) {this.onPatch(patch);} }); }); app.getUser(this.userId).then((user) => { this.add(Object.values(user.tesseract_ocr_pipeline_models)); for (let uncheckedCheckbox of this.listjs.list.querySelectorAll('input[data-checked="True"]')) { uncheckedCheckbox.setAttribute('checked', ''); } if (user.role.name !== ('Administrator' || 'Contributor')) { for (let switchElement of this.listjs.list.querySelectorAll('.is_public')) { switchElement.setAttribute('disabled', ''); } } this.isInitialized = true; }); } get item() { return `
()
delete send `.trim(); } get valueNames() { return [ {data: ['id']}, {data: ['creation-date']}, {name: 'publisher-url', attr: 'href'}, {name: 'publishing-url', attr: 'href'}, 'description', 'publisher', 'publishing-url-2', 'publishing-year', 'title', 'title-2', 'version', {name: 'is_public', attr: 'data-checked'} ]; } initListContainerElement() { if (!this.listContainerElement.hasAttribute('id')) { this.listContainerElement.id = Utils.generateElementId('tesseract-ocr-pipeline-model-list-'); } let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`); this.listContainerElement.innerHTML = `
search
Title and Description Publisher
`.trim(); } mapResourceToValue(tesseractOCRPipelineModel) { return { 'id': tesseractOCRPipelineModel.id, 'creation-date': tesseractOCRPipelineModel.creation_date, 'description': tesseractOCRPipelineModel.description, 'publisher': tesseractOCRPipelineModel.publisher, 'publisher-url': tesseractOCRPipelineModel.publisher_url, 'publishing-url': tesseractOCRPipelineModel.publishing_url, 'publishing-url-2': tesseractOCRPipelineModel.publishing_url, 'publishing-year': tesseractOCRPipelineModel.publishing_year, 'title': tesseractOCRPipelineModel.title, 'title-2': tesseractOCRPipelineModel.title, 'version': tesseractOCRPipelineModel.version, 'is_public': tesseractOCRPipelineModel.is_public ? 'True' : 'False' }; } sort() { this.listjs.sort('creation-date', {order: 'desc'}); } onChange(event) { let actionSwitchElement = event.target.closest('.list-action-trigger'); let action = actionSwitchElement.dataset.listAction; let tesseractOCRPipelineModelElement = event.target.closest('tr'); let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id; switch (action) { case 'share-request': { let is_public = actionSwitchElement.querySelector('input').checked; Utils.shareTesseractOCRPipelineModelRequest(this.userId, tesseractOCRPipelineModelId, is_public); break; } default: { break; } } } onClick(event) { if (event.target.closest('.action-switch')) { let userRole = app.data.users[this.userId].role.name; if (userRole !== ('Administrator' || 'Contributor')) { app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error'); } return; } let actionButtonElement = event.target.closest('.list-action-trigger'); let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.listAction; let tesseractOCRPipelineModelElement = event.target.closest('tr'); let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id; switch (action) { case 'delete-request': { Utils.deleteTesseractOCRPipelineModelRequest(this.userId, tesseractOCRPipelineModelId); break; } case 'view': { window.location.href = `/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModelId}`; break; } default: { break; } } } }