mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-27 03:44:19 +00:00
136 lines
5.0 KiB
JavaScript
136 lines
5.0 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 and Description</th>
|
|
<th>Publisher</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="list"></tbody>
|
|
</table>
|
|
<ul class="pagination"></ul>
|
|
`.trim();
|
|
},
|
|
item: `
|
|
<tr class="clickable hoverable">
|
|
<td><b><span class="title"></span> <span class="version"></span></b><br><i><span class="description"></span></i></td>
|
|
<td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>)<br><a class="publishing-url"><span class="publishing-url-2"></span></a></td>
|
|
<td>
|
|
<div class="switch action-switch center-align" data-action="share-request">
|
|
<span class="share"></span>
|
|
<label>
|
|
<input type="checkbox" class="shared">
|
|
<span class="lever"></span>
|
|
shared
|
|
</label>
|
|
</div>
|
|
</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,
|
|
'shared': tesseractOCRPipelineModel.shared ? 'True' : 'False'
|
|
};
|
|
},
|
|
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',
|
|
{name: 'shared', attr: 'data-checked'}
|
|
]
|
|
};
|
|
|
|
constructor(listElement, options = {}) {
|
|
super(listElement, {...TesseractOCRPipelineModelList.options, ...options});
|
|
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
|
}
|
|
|
|
init (user) {
|
|
this._init(user.tesseract_ocr_pipeline_models);
|
|
}
|
|
|
|
_init(ressources) {
|
|
super._init(ressources);
|
|
for (let uncheckedCheckbox of this.listjs.list.querySelectorAll('input[data-checked="True"]')) {
|
|
uncheckedCheckbox.setAttribute('checked', '');
|
|
}
|
|
}
|
|
|
|
onClick(event) {
|
|
if (event.target.closest('.action-switch')) {return;}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
onChange(event) {
|
|
let actionSwitchElement = event.target.closest('.action-switch');
|
|
let action = actionSwitchElement.dataset.action;
|
|
let tesseractOCRPipelineModelElement = event.target.closest('tr');
|
|
let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id;
|
|
switch (action) {
|
|
case 'share-request': {
|
|
let shared = actionSwitchElement.querySelector('input').checked;
|
|
Utils.shareTesseractOCRPipelineModelRequest(this.userId, tesseractOCRPipelineModelId, shared);
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|