diff --git a/InvenTree/build/templates/build/attachments.html b/InvenTree/build/templates/build/attachments.html index 9cd7761357..839c275a9b 100644 --- a/InvenTree/build/templates/build/attachments.html +++ b/InvenTree/build/templates/build/attachments.html @@ -70,6 +70,15 @@ $("#attachment-table").on('click', '.attachment-edit-button', function() { $("#attachment-table").on('click', '.attachment-delete-button', function() { var pk = $(this).attr('pk'); + constructForm(`/api/build/attachment/${pk}/`, { + method: 'DELETE', + confirmMessage: '{% trans "Confirm Delete Operation" %}', + title: '{% trans "Delete Attachment" %}', + reload: true, + }); + + return; + var url = `/build/attachment/${pk}/delete/`; launchModalForm( diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index ae9ce1bf87..549a20ee7e 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -36,10 +36,6 @@ build_urls = [ url('^new/', views.BuildItemCreate.as_view(), name='build-item-create'), ])), - url('^attachment/', include([ - url(r'^(?P\d+)/delete/', views.BuildAttachmentDelete.as_view(), name='build-attachment-delete'), - ])), - url(r'new/', views.BuildCreate.as_view(), name='build-create'), url(r'^(?P\d+)/', include(build_detail_urls)), diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 8cdaede60b..a3fd4fbd34 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -1058,18 +1058,3 @@ class BuildItemEdit(AjaxUpdateView): form.fields['install_into'].widget = HiddenInput() return form - - -class BuildAttachmentDelete(AjaxDeleteView): - """ - View for deleting a BuildAttachment - """ - - model = BuildOrderAttachment - ajax_form_title = _('Delete Attachment') - context_object_name = 'attachment' - - def get_data(self): - return { - 'danger': _('Deleted attachment') - } diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index 89b4608c8d..d568e40fe7 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -438,13 +438,25 @@ function constructFormBody(fields, options) { // The "submit" button will be disabled unless "confirm" is checked function insertConfirmButton(options) { + var message = options.confirmMessage || '{% trans "Confirm" %}'; + var confirm = ` - Confirm - + ${message} + `; $(options.modal).find('#modal-footer-buttons').append(confirm); + + // Disable the 'submit' button + $(options.modal).find('#modal-form-submit').prop('disabled', true); + + // Trigger event + $(options.modal).find('#modal-confirm').change(function() { + var enabled = this.checked; + + $(options.modal).find('#modal-form-submit').prop('disabled', !enabled); + }); }