From f5b97da5d2dc913623e379464217e40520d88be1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 12 May 2020 22:05:38 +1000 Subject: [PATCH] Refactor "attachment" table into template --- .../order/templates/order/po_attachments.html | 48 +++----------- .../order/templates/order/so_attachments.html | 47 +++----------- InvenTree/order/urls.py | 4 +- .../part/templates/part/attachments.html | 62 +++---------------- .../templates/stock/item_attachments.html | 48 +++----------- InvenTree/templates/attachment_table.html | 40 ++++++++++++ 6 files changed, 72 insertions(+), 177 deletions(-) create mode 100644 InvenTree/templates/attachment_table.html diff --git a/InvenTree/order/templates/order/po_attachments.html b/InvenTree/order/templates/order/po_attachments.html index 79a0105a61..a08b618fca 100644 --- a/InvenTree/order/templates/order/po_attachments.html +++ b/InvenTree/order/templates/order/po_attachments.html @@ -12,44 +12,8 @@
-
-
- -
-
+{% include "attachment_table.html" with attachments=order.attachments.all %} - - - - - - - - - - - {% for attachment in order.attachments.all %} - - - - - - - {% endfor %} - -
{% trans "File" %}{% trans "Comment" %}{% trans "Uploaded" %}
{{ attachment.basename }}{{ attachment.comment }} - {% if attachment.upload_date %}{{ attachment.upload_date }}{% endif %} - {% if attachment.user %}{{ attachment.user.username }}{% endif %} - -
- - -
-
{% endblock %} @@ -66,8 +30,10 @@ $("#new-attachment").click(function() { $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); + + var url = `/order/purchase-order/attachment/${button.attr('pk')}/edit/`; - launchModalForm(button.attr('url'), { + launchModalForm(url, { reload: true, }); }); @@ -75,7 +41,11 @@ $("#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 = `/order/purchase-order/attachment/${button.attr('pk')}/delete/`; + + console.log("url: " + url); + + launchModalForm(url, { reload: true, }); }); diff --git a/InvenTree/order/templates/order/so_attachments.html b/InvenTree/order/templates/order/so_attachments.html index 228d42c445..aff62213e5 100644 --- a/InvenTree/order/templates/order/so_attachments.html +++ b/InvenTree/order/templates/order/so_attachments.html @@ -12,44 +12,7 @@
-
-
- -
-
- - - - - - - - - - - - {% for attachment in order.attachments.all %} - - - - - - - {% endfor %} - -
{% trans "File" %}{% trans "Comment" %}{% trans "Uploaded" %}
{{ attachment.basename }}{{ attachment.comment }} - {% if attachment.upload_date %}{{ attachment.upload_date }}{% endif %} - {% if attachment.user %}{{ attachment.user.username }}{% endif %} - -
- - -
-
+{% include "attachment_table.html" with attachments=order.attachments.all %} {% endblock %} @@ -67,7 +30,9 @@ $("#new-attachment").click(function() { $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); - launchModalForm(button.attr('url'), { + var url = `/order/sales-order/attachment/${button.attr('pk')}/edit/`; + + launchModalForm(url, { reload: true, }); }); @@ -75,7 +40,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 = `/order/sales-order/attachment/${button.attr('pk')}/delete/`; + + launchModalForm(url, { reload: true, }); }); diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index daa83eb5ab..22104df5c7 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -42,7 +42,7 @@ purchase_order_urls = [ ])), ])), - url(r'^attachments/', include([ + url(r'^attachment/', include([ url(r'^new/', views.PurchaseOrderAttachmentCreate.as_view(), name='po-attachment-create'), url(r'^(?P\d+)/edit/', views.PurchaseOrderAttachmentEdit.as_view(), name='po-attachment-edit'), url(r'^(?P\d+)/delete/', views.PurchaseOrderAttachmentDelete.as_view(), name='po-attachment-delete'), @@ -86,7 +86,7 @@ sales_order_urls = [ ])), ])), - url(r'^attachments/', include([ + url(r'^attachment/', include([ url(r'^new/', views.SalesOrderAttachmentCreate.as_view(), name='so-attachment-create'), url(r'^(?P\d+)/edit/', views.SalesOrderAttachmentEdit.as_view(), name='so-attachment-edit'), url(r'^(?P\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'), diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html index f569ae207a..965645b748 100644 --- a/InvenTree/part/templates/part/attachments.html +++ b/InvenTree/part/templates/part/attachments.html @@ -9,59 +9,7 @@
-
-
- -
-
- - - - - - - - - - - - - {% for attachment in part.attachments.all %} - - - - - - - {% endfor %} - -{% if part.variant_of and part.variant_of.attachments.count > 0 %} - - - -{% for attachment in part.variant_of.attachments.all %} - - - - - -{% endfor %} -{% endif %} -
{% trans "File" %}{% trans "Comment" %}{% trans "Uploaded" %}
{{ attachment.basename }}{{ attachment.comment }} - {% if attachment.upload_date %}{{ attachment.upload_date }}{% endif %} - {% if attachment.user %}{{ attachment.user.username }}{% endif %} - -
- - -
-
- Attachments for template part {{ part.variant_of.full_name }} -
{{ attachment.basename }}{{ attachment.comment }}
+{% include "attachment_table.html" with attachments=part.attachments.all %} {% endblock %} @@ -78,7 +26,9 @@ $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); - launchModalForm(button.attr('url'), + var url = `/part/attachment/${button.attr('pk')}/edit/`; + + launchModalForm(url, { reload: true, }); @@ -87,7 +37,9 @@ $("#attachment-table").on('click', '.attachment-delete-button', function() { var button = $(this); - launchModalForm(button.attr('url'), { + var url = `/part/attachment/${button.attr('pk')}/delete/`; + + launchModalForm(url, { success: function() { location.reload(); } diff --git a/InvenTree/stock/templates/stock/item_attachments.html b/InvenTree/stock/templates/stock/item_attachments.html index 34eaa61703..2d056afbcf 100644 --- a/InvenTree/stock/templates/stock/item_attachments.html +++ b/InvenTree/stock/templates/stock/item_attachments.html @@ -10,45 +10,7 @@

{% trans "Stock Item Attachments" %}

- -
-
- -
-
- - - - - - - - - - - - {% for attachment in item.attachments.all %} - - - - - - - {% endfor %} - -
{% trans "File" %}{% trans "Comment" %}{% trans "Uploaded" %}
{{ attachment.basename }}{{ attachment.comment }} - {% if attachment.upload_date %}{{ attachment.upload_date }}{% endif %} - {% if attachment.user %}{{ attachment.user.username }}{% endif %} - -
- - -
-
+{% 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(); } diff --git a/InvenTree/templates/attachment_table.html b/InvenTree/templates/attachment_table.html new file mode 100644 index 0000000000..090ae566f6 --- /dev/null +++ b/InvenTree/templates/attachment_table.html @@ -0,0 +1,40 @@ +{% load i18n %} + +
+
+ +
+
+ + + + + + + + + + + + {% for attachment in attachments %} + + + + + + + {% endfor %} + +
{% trans "File" %}{% trans "Comment" %}{% trans "Uploaded" %}
{{ attachment.basename }}{{ attachment.comment }} + {% if attachment.upload_date %}{{ attachment.upload_date }}{% endif %} + {% if attachment.user %}{{ attachment.user.username }}{% endif %} + +
+ + +
+
\ No newline at end of file