nopaque/app/static/js/RessourceLists/JobInputList.js
2023-01-03 17:03:47 +01:00

82 lines
2.4 KiB
JavaScript

class JobInputList extends RessourceList {
static autoInit() {
for (let jobInputListElement of document.querySelectorAll('.job-input-list:not(.no-autoinit)')) {
new JobInputList(jobInputListElement);
}
}
static options = {
listContainerInnerHTMLGenerator: (listContainerElement) => {
listContainerElement.innerHTML = `
<div class="input-field">
<i class="material-icons prefix">search</i>
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
<label for="${listContainerElement.id}-search">Search job input</label>
</div>
<table>
<thead>
<tr>
<th>Filename</th>
<th></th>
</tr>
</thead>
<tbody class="list"></tbody>
</table>
<ul class="pagination"></ul>
`.trim();
},
ressourceMapper: (jobInput) => {
return {
'id': jobInput.id,
'creation-date': jobInput.creation_date,
'filename': jobInput.filename
};
},
sortParams: ['filename', {order: 'asc'}],
listjs: {
item: `
<tr class="clickable hoverable">
<td><span class="filename"></span></td>
<td class="right-align">
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
</td>
</tr>
`.trim(),
valueNames: [
{data: ['id']},
{data: ['creation-date']},
'filename'
]
}
};
constructor(listContainerElement, options={}) {
super(listContainerElement, _.merge({}, JobInputList.options, options));
this.jobId = listContainerElement.dataset.jobId;
}
init(user) {
this._init(user.jobs[this.jobId].inputs);
}
onClick(event) {
let jobInputElement = event.target.closest('tr');
if (jobInputElement === null) {return;}
let jobInputId = jobInputElement.dataset.id;
if (jobInputId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
switch (action) {
case 'download': {
window.location.href = `/jobs/${this.jobId}/inputs/${jobInputId}/download`;
break;
}
default: {
break;
}
}
}
onPatch(patch) {return;}
}