mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 10:18:56 +02:00
Allow to add/delete attachments via part edit page.
This commit is contained in:
parent
fcfab982a8
commit
3a11933a89
12 changed files with 370 additions and 50 deletions
61
templates/Parts/edit/_attachments.html.twig
Normal file
61
templates/Parts/edit/_attachments.html.twig
Normal file
|
@ -0,0 +1,61 @@
|
|||
{% 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 %}
|
||||
|
||||
|
||||
<table class="table table-striped" id="attachments_table" data-prototype="{{ form_widget(form.attachments.vars.prototype)|e('html_attr') }}">
|
||||
<tbody>
|
||||
{% for attachment in form.attachments %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ form_widget(attachment) }}
|
||||
</td>
|
||||
<td>
|
||||
{{ delete_btn }}
|
||||
</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>
|
|
@ -40,6 +40,12 @@
|
|||
{% trans %}part.edit.tab.part_lots{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" role="tab" href="#attachments">
|
||||
<i class="fas fa-paperclip fa-fw"></i>
|
||||
{% trans %}part.edit.tab.attachments{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" role="tab" href="#comment">
|
||||
<i class="fas fa-sticky-note fa-fw"></i>
|
||||
|
@ -63,7 +69,9 @@
|
|||
<div class="tab-pane fade p-2" id="part_lots" role="tabpanel">
|
||||
{% include "Parts/edit/_lots.html.twig" %}
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade p-2" id="attachments" role="tabpanel">
|
||||
{% include "Parts/edit/_attachments.html.twig" %}
|
||||
</div>
|
||||
<div class="tab-pane fade p-2" id="comment" role="tabpanel">
|
||||
{{ form_widget(form.comment)}}
|
||||
</div>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
{{ helper.attachment_icon(attachment, attachment_helper) }}
|
||||
</td>
|
||||
<td class="align-middle">{{ attachment.name }}</td>
|
||||
<td class="align-middle">{{ attachment.type.fullPath }}</td>
|
||||
<td class="align-middle">{{ attachment.attachmentType.fullPath }}</td>
|
||||
<td class="align-middle">
|
||||
{% if attachment.external %}
|
||||
<a href="{{ attachment.uRL }}" target="_blank" class="link-external">{{ attachment.host }}</a>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue