mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-24 12:54:44 +02:00
Added possibility to add/edit attachments on Admin pages.
This commit is contained in:
parent
97cb91a3b2
commit
eb1d8fd4e4
28 changed files with 247 additions and 25 deletions
|
@ -57,16 +57,20 @@
|
|||
|
||||
{{ form_start(form) }}
|
||||
|
||||
{% if block('additional_pills') is not empty %}
|
||||
|
||||
<ul class="nav nav-pills mb-2">
|
||||
<li class="nav-item"><a data-toggle="tab" class="nav-link link-anchor active" href="#home_common">{% trans %}admin.common{% endtrans %}</a></li>
|
||||
<li class="nav-item">
|
||||
<a data-toggle="tab" class="nav-link link-anchor active" href="#common">{% trans %}admin.common{% endtrans %}</a>
|
||||
</li>
|
||||
{% block additional_pills %}{% endblock %}
|
||||
<li class="nav-item">
|
||||
<a data-toggle="tab" class="nav-link link-anchor" href="#attachments">{% trans %}admin.attachments{% endtrans %}</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="home_common">
|
||||
<div class="tab-pane active" id="common">
|
||||
{{ form_row(form.name) }}
|
||||
{% if form.parent%}
|
||||
{{ form_row(form.parent) }}
|
||||
|
@ -83,6 +87,10 @@
|
|||
|
||||
</div>
|
||||
{% block additional_panes %}{% endblock %}
|
||||
|
||||
<div class="tab-pane" id="attachments">
|
||||
{% include "AdminPages/_attachments.html.twig" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_row(form.save) }}
|
||||
|
|
94
templates/AdminPages/_attachments.html.twig
Normal file
94
templates/AdminPages/_attachments.html.twig
Normal file
|
@ -0,0 +1,94 @@
|
|||
{% set delete_btn %}
|
||||
<button type="button" class="btn btn-danger lot_btn_delete" onclick="delete_attachment_entry(this);">
|
||||
<i class="fas fa-trash-alt fa-fw"></i>
|
||||
{% trans %}attachment.delete{% endtrans %}
|
||||
</button>
|
||||
{% endset %}
|
||||
|
||||
{#{{ form_row(form.master_picture_attachment) }} #}
|
||||
|
||||
<table class="table table-striped table-sm" id="attachments_table" data-prototype="{% if form.attachments.vars.prototype is defined %}{{ form_widget(form.attachments.vars.prototype)|e('html_attr') }}{% endif %}">
|
||||
<tbody>
|
||||
{% for attachment in form.attachments %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ form_widget(attachment) }}
|
||||
</td>
|
||||
<td>
|
||||
{{ delete_btn }}
|
||||
|
||||
{% set attach = attachment.vars.value %}
|
||||
|
||||
{% if attachment_helper.fileExisting(attach) %}
|
||||
{% if not attach.external %}
|
||||
<br><br>
|
||||
<h6>
|
||||
<span class="badge badge-primary">
|
||||
<i class="fas fa-fw fa-file"></i> {{ attach.filename }}
|
||||
</span>
|
||||
<br>
|
||||
<span class="badge badge-secondary">
|
||||
<i class="fas fa-hdd fa-fw"></i> {{ attachment_helper.humanFileSize(attach) }}
|
||||
</span>
|
||||
</h6>
|
||||
{% else %}
|
||||
<br><br>
|
||||
<h6>
|
||||
<span class="badge badge-primary">
|
||||
<i class="fas fa-fw fa-globe"></i> {% trans %}attachment.external{% endtrans %}
|
||||
</span>
|
||||
</h6>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<br><br>
|
||||
<h6>
|
||||
<span class="badge badge-warning">
|
||||
<i class="fas fa-exclamation-circle fa-fw"></i> {% trans %}attachment.file_not_found{% endtrans %}
|
||||
</span>
|
||||
</h6>
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="button" class="btn btn-success" onclick="create_attachment_entry(this)">
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}attachment.create{% endtrans %}
|
||||
</button>
|
||||
|
||||
<script>
|
||||
function delete_attachment_entry(btn) {
|
||||
window.bootbox.confirm('{% trans %}part_lot.edit.delete.confirm{% endtrans %}', function (result) {
|
||||
if(result) {
|
||||
$(btn).parents("tr").remove();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function create_attachment_entry(btn) {
|
||||
//Determine the table, so we can determine, how many entries there are already.
|
||||
$holder = $("#attachments_table");
|
||||
|
||||
var index = $holder.find(":input").length;
|
||||
var newForm = $holder.data("prototype");
|
||||
|
||||
//Increase the index
|
||||
newForm = newForm.replace(/__name__/g, index);
|
||||
newForm = '<td>' + newForm + '</td>';
|
||||
$newFormRow = $('<tr></tr>').html(newForm);
|
||||
|
||||
//Add delete button
|
||||
$btn = '<td>' + '{{ delete_btn|e('js') }}' + '</td>';
|
||||
$newFormRow.append($btn);
|
||||
|
||||
$holder.append($newFormRow);
|
||||
|
||||
//Reinit the selectpickers
|
||||
$(".selectpicker").selectpicker();
|
||||
$(".file").fileinput();
|
||||
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue