diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 8c0cf494be..6a0d02263d 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -103,6 +103,7 @@ settings_urls = [ # Some javascript files are served 'dynamically', allowing them to pass through the Django translation layer dynamic_javascript_urls = [ url(r'^api.js', DynamicJsView.as_view(template_name='js/api.js'), name='api.js'), + url(r'^attachment.js', DynamicJsView.as_view(template_name='js/attachment.js'), name='attachment.js'), url(r'^forms.js', DynamicJsView.as_view(template_name='js/forms.js'), name='forms.js'), url(r'^model_renderers.js', DynamicJsView.as_view(template_name='js/model_renderers.js'), name='model_renderers.js'), url(r'^modals.js', DynamicJsView.as_view(template_name='js/modals.js'), name='modals.js'), diff --git a/InvenTree/build/templates/build/attachments.html b/InvenTree/build/templates/build/attachments.html index 728c02fca7..e969756b81 100644 --- a/InvenTree/build/templates/build/attachments.html +++ b/InvenTree/build/templates/build/attachments.html @@ -47,37 +47,38 @@ $('#new-attachment').click(function() { } }, method: 'POST', - reload: true, + onSuccess: reloadAttachmentTable, title: '{% trans "Add Attachment" %}', }); }); -// Callback for editing an attachment -$("#attachment-table").on('click', '.attachment-edit-button', function() { - var pk = $(this).attr('pk'); - - constructForm(`/api/build/attachment/${pk}/`, { - fields: { - attachment: {}, - comment: {}, +loadAttachmentTable( + '{% url "api-build-attachment-list" %}', + { + filters: { + build: {{ build.pk }}, }, - reload: true, - title: '{% trans "Edit Attachment" %}', - }); -}); + onEdit: function(pk) { + var url = `/api/build/attachment/${pk}/`; -// Callback for deleting an attachment -$("#attachment-table").on('click', '.attachment-delete-button', function() { - var pk = $(this).attr('pk'); + constructForm(url, { + fields: { + comment: {}, + }, + onSuccess: reloadAttachmentTable, + title: '{% trans "Edit Attachment" %}', + }); + }, + onDelete: function(pk) { - constructForm(`/api/build/attachment/${pk}/`, { - method: 'DELETE', - confirmMessage: '{% trans "Confirm Delete Operation" %}', - title: '{% trans "Delete Attachment" %}', - reload: true, - }); -}); - -$("#attachment-table").inventreeTable({}); + constructForm(`/api/build/attachment/${pk}/`, { + method: 'DELETE', + confirmMessage: '{% trans "Confirm Delete Operation" %}', + title: '{% trans "Delete Attachment" %}', + onSuccess: reloadAttachmentTable, + }); + } + } +); {% endblock %} diff --git a/InvenTree/order/templates/order/po_attachments.html b/InvenTree/order/templates/order/po_attachments.html index a6ea769aee..07e425016b 100644 --- a/InvenTree/order/templates/order/po_attachments.html +++ b/InvenTree/order/templates/order/po_attachments.html @@ -34,6 +34,35 @@ enableDragAndDrop( } ); +loadAttachmentTable( + '{% url "api-po-attachment-list" %}', + { + filters: { + order: {{ order.pk }}, + }, + onEdit: function(pk) { + var url = `/api/order/po/attachment/${pk}/`; + + constructForm(url, { + fields: { + comment: {}, + }, + onSuccess: reloadAttachmentTable, + title: '{% trans "Edit Attachment" %}', + }); + }, + onDelete: function(pk) { + + constructForm(`/api/order/po/attachment/${pk}/`, { + method: 'DELETE', + confirmMessage: '{% trans "Confirm Delete Operation" %}', + title: '{% trans "Delete Attachment" %}', + onSuccess: reloadAttachmentTable, + }); + } + } +); + $("#new-attachment").click(function() { constructForm('{% url "api-po-attachment-list" %}', { @@ -51,37 +80,4 @@ $("#new-attachment").click(function() { }); }); -$("#attachment-table").on('click', '.attachment-edit-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/order/po/attachment/${pk}/`; - - constructForm(url, { - fields: { - attachment: {}, - comment: {}, - }, - reload: true, - title: '{% trans "Edit Attachment" %}', - }); -}); - -$("#attachment-table").on('click', '.attachment-delete-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - constructForm(`/api/order/po/attachment/${pk}/`, { - method: 'DELETE', - confirmMessage: '{% trans "Confirm Delete Operation" %}', - title: '{% trans "Delete Attachment" %}', - reload: true, - }); -}); - -$("#attachment-table").inventreeTable({ -}); - {% endblock %} \ No newline at end of file diff --git a/InvenTree/order/templates/order/so_attachments.html b/InvenTree/order/templates/order/so_attachments.html index 6df93bbe45..89f09541d1 100644 --- a/InvenTree/order/templates/order/so_attachments.html +++ b/InvenTree/order/templates/order/so_attachments.html @@ -35,6 +35,36 @@ enableDragAndDrop( } ); +loadAttachmentTable( + '{% url "api-so-attachment-list" %}', + { + filters: { + order: {{ order.pk }}, + }, + onEdit: function(pk) { + var url = `/api/order/so/attachment/${pk}/`; + + constructForm(url, { + fields: { + comment: {}, + }, + onSuccess: reloadAttachmentTable, + title: '{% trans "Edit Attachment" %}', + }); + }, + onDelete: function(pk) { + var pk = button.attr('pk'); + + constructForm(`/api/order/so/attachment/${pk}/`, { + method: 'DELETE', + confirmMessage: '{% trans "Confirm Delete Operation" %}', + title: '{% trans "Delete Attachment" %}', + onSuccess: reloadAttachmentTable, + }); + } + } +); + $("#new-attachment").click(function() { constructForm('{% url "api-so-attachment-list" %}', { @@ -47,42 +77,9 @@ $("#new-attachment").click(function() { hidden: true } }, - reload: true, + onSuccess: reloadAttachmentTable, title: '{% trans "Add Attachment" %}' }); }); -$("#attachment-table").on('click', '.attachment-edit-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/order/so/attachment/${pk}/`; - - constructForm(url, { - fields: { - attachment: {}, - comment: {}, - }, - reload: true, - title: '{% trans "Edit Attachment" %}', - }); -}); - -$("#attachment-table").on('click', '.attachment-delete-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - constructForm(`/api/order/so/attachment/${pk}/`, { - method: 'DELETE', - confirmMessage: '{% trans "Confirm Delete Operation" %}', - title: '{% trans "Delete Attachment" %}', - reload: true, - }); -}); - -$("#attachment-table").inventreeTable({ -}); - {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html index 5fca535098..7128980472 100644 --- a/InvenTree/part/templates/part/attachments.html +++ b/InvenTree/part/templates/part/attachments.html @@ -19,6 +19,36 @@ {% block js_ready %} {{ block.super }} + loadAttachmentTable( + '{% url "api-part-attachment-list" %}', + { + filters: { + part: {{ part.pk }}, + }, + onEdit: function(pk) { + var url = `/api/part/attachment/${pk}/`; + + constructForm(url, { + fields: { + comment: {}, + }, + title: '{% trans "Edit Attachment" %}', + onSuccess: reloadAttachmentTable, + }); + }, + onDelete: function(pk) { + var url = `/api/part/attachment/${pk}/`; + + constructForm(url, { + method: 'DELETE', + confirmMessage: '{% trans "Confirm Delete Operation" %}', + title: '{% trans "Delete Attachment" %}', + onSuccess: reloadAttachmentTable, + }); + } + } + ); + enableDragAndDrop( '#attachment-dropzone', '{% url "api-part-attachment-list" %}', @@ -28,7 +58,7 @@ }, label: 'attachment', success: function(data, status, xhr) { - location.reload(); + reloadAttachmentTable(); } } ); @@ -47,43 +77,10 @@ hidden: true, } }, - reload: true, + onSuccess: reloadAttachmentTable, title: '{% trans "Add Attachment" %}', } ) }); - $("#attachment-table").on('click', '.attachment-edit-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/part/attachment/${pk}/`; - - constructForm(url, { - fields: { - attachment: {}, - comment: {}, - }, - title: '{% trans "Edit Attachment" %}', - reload: true, - }); - }); - - $("#attachment-table").on('click', '.attachment-delete-button', function() { - var button = $(this); - var pk = button.attr('pk'); - var url = `/api/part/attachment/${pk}/`; - - constructForm(url, { - method: 'DELETE', - confirmMessage: '{% trans "Confirm Delete Operation" %}', - title: '{% trans "Delete Attachment" %}', - reload: true, - }); - }); - - $("#attachment-table").inventreeTable({ - }); - {% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/item_attachments.html b/InvenTree/stock/templates/stock/item_attachments.html index f58d5db063..34ceecc550 100644 --- a/InvenTree/stock/templates/stock/item_attachments.html +++ b/InvenTree/stock/templates/stock/item_attachments.html @@ -28,11 +28,41 @@ enableDragAndDrop( }, label: 'attachment', success: function(data, status, xhr) { - location.reload(); + reloadAttachmentTable(); } } ); +loadAttachmentTable( + '{% url "api-stock-attachment-list" %}', + { + filters: { + item: {{ item.pk }}, + }, + onEdit: function(pk) { + var url = `/api/stock/attachment/${pk}/`; + + constructForm(url, { + fields: { + comment: {}, + }, + title: '{% trans "Edit Attachment" %}', + onSuccess: reloadAttachmentTable + }); + }, + onDelete: function(pk) { + var url = `/api/stock/attachment/${pk}/`; + + constructForm(url, { + method: 'DELETE', + confirmMessage: '{% trans "Confirm Delete Operation" %}', + title: '{% trans "Delete Attachment" %}', + onSuccess: reloadAttachmentTable, + }); + } + } +); + $("#new-attachment").click(function() { constructForm( @@ -53,39 +83,4 @@ $("#new-attachment").click(function() { ); }); -$("#attachment-table").on('click', '.attachment-edit-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/stock/attachment/${pk}/`; - - constructForm(url, { - fields: { - attachment: {}, - comment: {}, - }, - title: '{% trans "Edit Attachment" %}', - reload: true - }); -}); - -$("#attachment-table").on('click', '.attachment-delete-button', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/stock/attachment/${pk}/`; - - constructForm(url, { - method: 'DELETE', - confirmMessage: '{% trans "Confirm Delete Operation" %}', - title: '{% trans "Delete Attachment" %}', - reload: true, - }); -}); - -$("#attachment-table").inventreeTable({ -}); - {% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/attachment_table.html b/InvenTree/templates/attachment_table.html index 35b114cc05..18a4da9acc 100644 --- a/InvenTree/templates/attachment_table.html +++ b/InvenTree/templates/attachment_table.html @@ -10,35 +10,6 @@
{% 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 %} - | -
-
-
-
-
- |
-