From a78106526a758b5dcc16eb129858ed17dbfe89f4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 13 May 2019 22:47:36 +1000 Subject: [PATCH] Remove launchDeleteForm JS function - All should be consolidated upon launchModalForm - StockItem delete now uses this --- InvenTree/static/script/inventree/modals.js | 62 ------------------- InvenTree/stock/templates/stock/item.html | 2 +- .../stock/templates/stock/item_delete.html | 10 ++- 3 files changed, 9 insertions(+), 65 deletions(-) diff --git a/InvenTree/static/script/inventree/modals.js b/InvenTree/static/script/inventree/modals.js index 9116ba659d..67d4497674 100644 --- a/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/static/script/inventree/modals.js @@ -345,68 +345,6 @@ function openModal(options) { } -function launchDeleteForm(url, options = {}) { - /* Launch a modal form to delete an object - */ - - var modal = options.modal || '#modal-delete'; - - $(modal).on('shown.bs.modal', function() { - $(modal + ' .modal-form-content').scrollTop(0); - }); - - // Un-bind any attached click listeners - $(modal).off('click', '#modal-form-delete'); - - // Request delete form data - $.ajax({ - url: url, - type: 'get', - dataType: 'json', - beforeSend: function() { - openModal({modal: modal}); - }, - success: function (response) { - if (response.title) { - modalSetTitle(modal, response.title); - } - if (response.html_data) { - modalSetContent(modal, response.html_data); - } - else { - - $(modal).modal('hide'); - showAlertDialog('Invalid form response', 'JSON response missing HTML data'); - } - }, - error: function (xhr, ajaxOptions, thrownError) { - $(modal).modal('hide'); - showAlertDialog('Error requesting form data', renderErrorMessage(xhr)); - } - }); - - $(modal).on('click', '#modal-form-delete', function() { - - var form = $(modal).find('#delete-form'); - - $.ajax({ - url: url, - data: form.serialize(), - type: 'post', - dataType: 'json', - success: function (response) { - $(modal).modal('hide'); - afterForm(response, options); - }, - error: function (xhr, ajaxOptions, thrownError) { - $(modal).modal('hide'); - showAlertDialog('Error deleting item', renderErrorMessage(xhr)); - } - }); - }); -} - - function injectModalForm(modal, form_html) { /* Inject form content into the modal. * Updates the HTML of the form content, and then applies some other updates diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index 8bfe5c8e4e..cb54ac6f5e 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -194,7 +194,7 @@ {% endif %} $("#stock-delete").click(function () { - launchDeleteForm( + launchModalForm( "{% url 'stock-item-delete' item.id %}", { redirect: "{% url 'part-stock' item.part.id %}" diff --git a/InvenTree/stock/templates/stock/item_delete.html b/InvenTree/stock/templates/stock/item_delete.html index 9f3f863d75..9e908a0d67 100644 --- a/InvenTree/stock/templates/stock/item_delete.html +++ b/InvenTree/stock/templates/stock/item_delete.html @@ -1,5 +1,11 @@ +{% extends "modal_delete_form.html" %} + +{% block pre_form_content %} + +
Are you sure you want to delete this stock item? -
- This will remove {{ item.quantity }} units of {{ item.part.full_name }} from stock. +
+ +{% endblock %} \ No newline at end of file