nopaque/app/static/js/RessourceLists/TesseractOCRPipelineModelList.js
2022-11-15 15:11:16 +01:00

100 lines
3.7 KiB
JavaScript

class TesseractOCRPipelineModelList extends RessourceList {
static autoInit() {
for (let tesseractOCRPipelineModelListElement of document.querySelectorAll('.tesseract-ocr-pipeline-model-list:not(.no-autoinit)')) {
new TesseractOCRPipelineModelList(tesseractOCRPipelineModelListElement);
}
}
static options = {
initialHtmlGenerator: (id) => {
return `
<div class="input-field">
<i class="material-icons prefix">search</i>
<input id="${id}-search" class="search" type="search"></input>
<label for="${id}-search">Search Tesseract OCR Pipeline Model</label>
</div>
<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Biblio</th>
<th></th>
</tr>
</thead>
<tbody class="list"></tbody>
</table>
<ul class="pagination"></ul>
`.trim();
},
item: `
<tr class="clickable hoverable">
<td><span class="title"></span></td>
<td><span class="description"></span></td>
<td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>), <span class="title-2"></span> <span class="version"></span>, <a class="publishing-url"><span class="publishing-url-2"></span></a></td>
<td class="right-align">
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
<a class="action-button btn-floating service-color darken waves-effect waves-light service-2" data-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim(),
ressourceMapper: (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
};
},
sortArgs: ['creation-date', {order: 'desc'}],
valueNames: [
{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'
]
};
constructor(listElement, options = {}) {
super(listElement, {...TesseractOCRPipelineModelList.options, ...options});
}
init (user) {
this._init(user.tesseract_ocr_pipeline_models);
}
onClick(event) {
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
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;
}
}
}
}