From 4a259dc146090929ae5ab6b218851b2aa8d924ca Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 22 Mar 2020 19:55:46 +1100 Subject: [PATCH] Can now successfully edit or delete a purchase-order attachment --- .../order/templates/order/po_attachments.html | 12 ++++--- .../order/templates/order/po_delete.html | 7 ++++ InvenTree/order/urls.py | 3 +- InvenTree/order/views.py | 35 +++++++++++++++++++ .../templates/part/attachment_delete.html | 4 +-- InvenTree/part/views.py | 1 + 6 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 InvenTree/order/templates/order/po_delete.html diff --git a/InvenTree/order/templates/order/po_attachments.html b/InvenTree/order/templates/order/po_attachments.html index 4ba54a9c91..173b0e1fb6 100644 --- a/InvenTree/order/templates/order/po_attachments.html +++ b/InvenTree/order/templates/order/po_attachments.html @@ -33,10 +33,10 @@ {{ attachment.comment }}
- -
@@ -62,13 +62,17 @@ $("#new-attachment").click(function() { $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); - // TODO + launchModalForm(button.attr('url'), { + reload: true, + }); }); $("#attachment-table").on('click', '.attachment-delete-button', function() { var button = $(this); - // TODO + launchModalForm(button.attr('url'), { + reload: true, + }); }); $("#attachment-table").inventreeTable({ diff --git a/InvenTree/order/templates/order/po_delete.html b/InvenTree/order/templates/order/po_delete.html new file mode 100644 index 0000000000..4ee7f03cb1 --- /dev/null +++ b/InvenTree/order/templates/order/po_delete.html @@ -0,0 +1,7 @@ +{% extends "modal_delete_form.html" %} +{% load i18n %} + +{% block pre_form_content %} +{% trans "Are you sure you want to delete this attachment?" %} +
+{% endblock %} \ No newline at end of file diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index c7fbc1e890..3346d7c44d 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -11,7 +11,8 @@ from . import views purchase_order_attachment_urls = [ 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+)/edit/', views.PurchaseOrderAttachmentEdit.as_view(), name='po-attachment-edit'), + url(r'^(?P\d+)/delete/', views.PurchaseOrderAttachmentDelete.as_view(), name='po-attachment-delete'), ] purchase_order_detail_urls = [ diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 09866f91dc..67d5b926d7 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -113,6 +113,41 @@ class PurchaseOrderAttachmentCreate(AjaxCreateView): return form +class PurchaseOrderAttachmentEdit(AjaxUpdateView): + """ View for editing a PurchaseOrderAttachment object """ + + model = PurchaseOrderAttachment + form_class = order_forms.EditPurchaseOrderAttachmentForm + ajax_form_title = _("Edit Attachment") + + def get_data(self): + return { + 'success': _('Attachment updated') + } + + def get_form(self): + form = super(AjaxUpdateView, self).get_form() + + # Hide the 'order' field + form.fields['order'].widget = HiddenInput() + + return form + + +class PurchaseOrderAttachmentDelete(AjaxDeleteView): + """ View for deleting a PurchaseOrderAttachment """ + + model = PurchaseOrderAttachment + ajax_form_title = _("Delete Attachment") + ajax_template_name = "order/po_delete.html" + context_object_name = "attachment" + + def get_data(self): + return { + "danger": _("Deleted attachment") + } + + class PurchaseOrderNotes(UpdateView): """ View for updating the 'notes' field of a PurchaseOrder """ diff --git a/InvenTree/part/templates/part/attachment_delete.html b/InvenTree/part/templates/part/attachment_delete.html index 1adffcc710..4ee7f03cb1 100644 --- a/InvenTree/part/templates/part/attachment_delete.html +++ b/InvenTree/part/templates/part/attachment_delete.html @@ -1,7 +1,7 @@ {% extends "modal_delete_form.html" %} +{% load i18n %} {% block pre_form_content %} -Are you sure you wish to delete this attachment? +{% trans "Are you sure you want to delete this attachment?" %}
-This will remove the file '{{ attachment.basename }}'. {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 1752607d2a..01f8ff41bb 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -112,6 +112,7 @@ class PartAttachmentCreate(AjaxCreateView): class PartAttachmentEdit(AjaxUpdateView): """ View for editing a PartAttachment object """ + model = PartAttachment form_class = part_forms.EditPartAttachmentForm ajax_template_name = 'modal_form.html'