From 784b0dec0298807401bd843a64d81445b58e7e70 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 27 Apr 2018 00:06:44 +1000 Subject: [PATCH] Added AjaxDeleteView - AjaxDeleteView handles ajaxified delete GET and POST events - Added modal deletion window - Added launchDeleteForm jQuery function --- InvenTree/InvenTree/views.py | 37 ++++++++++++ InvenTree/part/templates/part/delete.html | 33 +---------- InvenTree/part/templates/part/detail.html | 8 +++ .../part/templates/part/partial_delete.html | 32 +++++++++++ InvenTree/part/views.py | 8 ++- InvenTree/static/script/modal_form.js | 56 ++++++++++++++++++- InvenTree/templates/modal.html | 2 +- InvenTree/templates/modal_delete.html | 21 +++++++ 8 files changed, 161 insertions(+), 36 deletions(-) create mode 100644 InvenTree/part/templates/part/partial_delete.html create mode 100644 InvenTree/templates/modal_delete.html diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 4ea1c09b97..d35284135c 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -101,3 +101,40 @@ class AjaxUpdateView(AjaxView, UpdateView): else: return response + + +class AjaxDeleteView(AjaxView, DeleteView): + + def post(self, request, *args, **kwargs): + + if request.is_ajax(): + obj = self.get_object() + pk = obj.id + obj.delete() + + data = {'id': pk, + 'delete': True} + + return JsonResponse(data) + + else: + return super(DeleteView, self).post(request, *args, **kwargs) + + def get(self, request, *args, **kwargs): + + response = super(DeleteView, self).get(request, *args, **kwargs) + + if request.is_ajax(): + + data = {'id': self.get_object().id, + 'title': self.ajax_form_title, + 'delete': False, + 'html_data': render_to_string(self.getAjaxTemplate(), + self.get_context_data(), + request=request) + } + + return JsonResponse(data) + + else: + return response diff --git a/InvenTree/part/templates/part/delete.html b/InvenTree/part/templates/part/delete.html index 5e536508d9..9e38b07be4 100644 --- a/InvenTree/part/templates/part/delete.html +++ b/InvenTree/part/templates/part/delete.html @@ -7,37 +7,6 @@ {% block del_body %} - {% if part.used_in_count %} -

This part is used in BOMs for {{ part.used_in_count }} other parts. If you delete this part, the BOMs for the following parts will be updated: -