2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Refactor "attachment" table into template

This commit is contained in:
Oliver Walters
2020-05-12 22:05:38 +10:00
parent 366d4b2143
commit f5b97da5d2
6 changed files with 72 additions and 177 deletions

View File

@ -10,45 +10,7 @@
<hr>
<h4>{% trans "Stock Item Attachments" %}</h4>
<div id='attachment-buttons'>
<div class="btn-group">
<button type='button' class='btn btn-success' id='new-attachment'>{% trans "Add Attachment" %}</button>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#attachment-buttons' id='attachment-table'>
<thead>
<tr>
<th data-field='file' data-sortable='true' data-searchable='true'>{% trans "File" %}</th>
<th data-field='comment' data-sortable='true' data-searchable='true'>{% trans "Comment" %}</th>
<th data-field='user' data-sortable='true' data-searchable='true'>{% trans "Uploaded" %}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for attachment in item.attachments.all %}
<tr>
<td><a href='/media/{{ attachment.attachment }}'>{{ attachment.basename }}</a></td>
<td>{{ attachment.comment }}</td>
<td>
{% if attachment.upload_date %}{{ attachment.upload_date }}{% endif %}
{% if attachment.user %}<span class='badge'>{{ attachment.user.username }}</div>{% endif %}
</td>
<td>
<div class='btn-group' style='float: right;'>
<button type='button' class='btn btn-default btn-glyph attachment-edit-button' url="{% url 'stock-item-attachment-edit' attachment.id %}" data-toggle='tooltip' title='{% trans "Edit attachment" %}'>
<span class='fas fa-edit'/>
</button>
<button type='button' class='btn btn-default btn-glyph attachment-delete-button' url="{% url 'stock-item-attachment-delete' attachment.id %}" data-toggle='tooltip' title='{% trans "Delete attachment" %}'>
<span class='fas fa-trash-alt icon-red'/>
</button>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include "attachment_table.html" with attachments=item.attachments.all %}
{% endblock %}
@ -65,7 +27,9 @@ $("#new-attachment").click(function() {
$("#attachment-table").on('click', '.attachment-edit-button', function() {
var button = $(this);
launchModalForm(button.attr('url'),
var url = `/stock/item/attachment/${button.attr('pk')}/edit/`;
launchModalForm(url,
{
reload: true,
});
@ -74,7 +38,9 @@ $("#attachment-table").on('click', '.attachment-edit-button', function() {
$("#attachment-table").on('click', '.attachment-delete-button', function() {
var button = $(this);
launchModalForm(button.attr('url'), {
var url = `/stock/item/attachment/${button.attr('pk')}/delete/`;
launchModalForm(url, {
success: function() {
location.reload();
}