diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 2ac56431d2..d9fd5b3c0f 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -83,16 +83,14 @@ {% block js_ready %} {{ block.super }} $("#edit-build").click(function () { - launchModalForm("#modal-form", - "{% url 'build-edit' build.id %}", + launchModalForm("{% url 'build-edit' build.id %}", { reload: true }); }); $("#cancel-build").click(function() { - launchModalForm("#modal-form", - "{% url 'build-cancel' build.id %}", + launchModalForm("{% url 'build-cancel' build.id %}", { reload: true }); diff --git a/InvenTree/build/templates/build/index.html b/InvenTree/build/templates/build/index.html index c79109a4b5..81d2d0dbd4 100644 --- a/InvenTree/build/templates/build/index.html +++ b/InvenTree/build/templates/build/index.html @@ -31,7 +31,7 @@ {% block js_ready %} {{ block.super }} $("#new-build").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'build-create' %}", { follow: true diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index 368d7665e9..44e0110ad7 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -69,7 +69,7 @@ {% block js_ready %} $("#company-thumb").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'company-image' company.id %}", { reload: true diff --git a/InvenTree/company/templates/company/detail.html b/InvenTree/company/templates/company/detail.html index c6f91c7a50..0068d150ae 100644 --- a/InvenTree/company/templates/company/detail.html +++ b/InvenTree/company/templates/company/detail.html @@ -46,7 +46,7 @@ {% block js_ready %} {{ block.super }} $('#edit-company').click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'company-edit' company.id %}", { reload: true @@ -54,7 +54,7 @@ }); $('#delete-company').click(function() { - launchDeleteForm("#modal-delete", + launchDeleteForm( "{% url 'company-delete' company.id %}", { redirect: "{% url 'company-index' %}" diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index b36ec33eef..94412806e1 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -18,7 +18,7 @@ {{ block.super }} $("#part-create").click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'supplier-part-create' %}", { data: { diff --git a/InvenTree/company/templates/company/partdetail.html b/InvenTree/company/templates/company/partdetail.html index 8642250726..fa974ceef6 100644 --- a/InvenTree/company/templates/company/partdetail.html +++ b/InvenTree/company/templates/company/partdetail.html @@ -41,7 +41,7 @@ {% block js_ready %} {{ block.super }} $('#part-edit').click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'supplier-part-edit' part.id %}", { reload: true @@ -50,7 +50,7 @@ }); $('#part-delete').click(function() { - launchDeleteForm("#modal-delete", + launchDeleteForm( "{% url 'supplier-part-delete' part.id %}", { redirect: "{% url 'company-index' %}" diff --git a/InvenTree/part/templates/part/bom.html b/InvenTree/part/templates/part/bom.html index b55879f507..723e0cad00 100644 --- a/InvenTree/part/templates/part/bom.html +++ b/InvenTree/part/templates/part/bom.html @@ -28,7 +28,7 @@ $('#bom-table').on('click', '.delete-button', function () { var button = $(this); - launchDeleteForm("#modal-delete", + launchDeleteForm( button.attr('url'), { success: reloadBom @@ -38,7 +38,7 @@ $("#bom-table").on('click', '.edit-button', function () { var button = $(this); - launchModalForm("#modal-form", + launchModalForm( button.attr('url'), { success: reloadBom @@ -47,7 +47,7 @@ }); $("#new-bom-item").click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'bom-item-create' %}", { reload: true, diff --git a/InvenTree/part/templates/part/build.html b/InvenTree/part/templates/part/build.html index add27df741..acaa70a60c 100644 --- a/InvenTree/part/templates/part/build.html +++ b/InvenTree/part/templates/part/build.html @@ -40,7 +40,7 @@ {% block js_ready %} {{ block.super }} $("#start-build").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'build-create' %}", { follow: true, diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 4a7fc9704e..74a76e7da2 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -53,7 +53,7 @@ {{ block.super }} $("#cat-create").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'category-create' %}", { follow: true, @@ -66,7 +66,7 @@ }) $("#part-create").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'part-create' %}", { follow: true, @@ -80,7 +80,7 @@ {% if category %} $("#cat-edit").click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'category-edit' category.id %}", { reload: true @@ -96,8 +96,7 @@ {% endif %} $('#cat-delete').click(function() { - launchDeleteForm('#modal-delete', - "{% url 'category-delete' category.id %}", + launchDeleteForm("{% url 'category-delete' category.id %}", { redirect: redirect }); diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index fe8d6601c6..919511a25e 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -102,7 +102,7 @@ {% block js_ready %} {{ block.super }} $("#edit-part").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'part-edit' part.id %}", { reload: true, @@ -110,7 +110,7 @@ }); $('#delete-part').click(function() { - launchDeleteForm("#modal-delete", + launchDeleteForm( "{% url 'part-delete' part.id %}", { redirect: {% if part.category %}"{% url 'category-detail' part.category.id %}"{% else %}"{% url 'part-index' %}"{% endif %} diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index f61b04b468..f7314a41a3 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -81,7 +81,7 @@ {% block js_ready %} {{ block.super }} $("#part-thumb").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'part-image' part.id %}", { reload: true diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 48b16a0f99..76d6e846ba 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -42,7 +42,7 @@ {{ block.super }} $('#add-stock-item').click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'stock-item-create' %}", { reload: true, diff --git a/InvenTree/part/templates/part/supplier.html b/InvenTree/part/templates/part/supplier.html index fcaa360e2b..a1201cc1e8 100644 --- a/InvenTree/part/templates/part/supplier.html +++ b/InvenTree/part/templates/part/supplier.html @@ -29,7 +29,7 @@ {{ block.super }} $('#supplier-create').click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'supplier-part-create' %}", { reload: true, diff --git a/InvenTree/static/script/inventree/modals.js b/InvenTree/static/script/inventree/modals.js index ea67abe4f7..32de32da8c 100644 --- a/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/static/script/inventree/modals.js @@ -94,12 +94,22 @@ function openModal(modal, title='', content='') { } -function launchDeleteForm(modal, url, options = {}) { +function launchDeleteForm(url, options = {}) { + + var modal = '#modal-delete'; + + if (options.modal) { + modal = options.modal; + } $(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', @@ -125,9 +135,6 @@ function launchDeleteForm(modal, url, options = {}) { } }); - // Un-bind any attached click listeners - $(modal).off('click', '#modal-form-delete'); - $(modal).on('click', '#modal-form-delete', function() { var form = $(modal).find('#delete-form'); @@ -155,7 +162,13 @@ function injectModalForm(modal, form_html) { attachSelect(modal); } -function handleModalForm(modal, url, options) { +function handleModalForm(url, options) { + + var modal = '#modal-form'; + + if (options.modal) { + modal = options.modal; + } var form = $(modal).find('.js-modal-form'); @@ -217,7 +230,13 @@ function handleModalForm(modal, url, options) { * Opens a model window and fills it with a requested form * If the form is loaded successfully, calls handleModalForm */ -function launchModalForm(modal, url, options = {}) { +function launchModalForm(url, options = {}) { + + var modal = '#modal-form'; + + if (options.modal) { + modal = options.modal; + } // Form the ajax request to retrieve the django form data ajax_data = { diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index 3594cd113b..8abb54eab2 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -132,7 +132,7 @@ {% block js_ready %} {{ block.super }} $("#stock-edit").click(function () { - launchModalForm("#modal-form", + launchModalForm( "{% url 'stock-item-edit' item.id %}", { reload: true @@ -141,7 +141,7 @@ {% if item.in_stock %} $("#stock-move").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'stock-item-move' item.id %}", { reload: true, @@ -149,7 +149,7 @@ }); $("#stock-stocktake").click(function() { - launchModalForm("#modal-form", + launchModalForm( "{% url 'stock-item-stocktake' item.id %}", { reload: true @@ -159,7 +159,7 @@ {% endif %} $("#stock-delete").click(function () { - launchDeleteForm("#modal-delete", + launchDeleteForm( "{% url 'stock-item-delete' item.id %}", { redirect: "{% url 'part-stock' item.part.id %}" diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 3844e997c3..b285af85a8 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -65,8 +65,7 @@ {% block js_ready %} {{ block.super }} $('#location-create').click(function () { - launchModalForm("#modal-form", - "{% url 'stock-location-create' %}", + launchModalForm("{% url 'stock-location-create' %}", { data: { {% if location %} @@ -80,8 +79,7 @@ {% if location %} $('#location-edit').click(function() { - launchModalForm("#modal-form", - "{% url 'stock-location-edit' location.id %}", + launchModalForm("{% url 'stock-location-edit' location.id %}", { reload: true }); @@ -89,8 +87,7 @@ }); $('#location-delete').click(function() { - launchDeleteForm("#modal-delete", - "{% url 'stock-location-delete' location.id %}", + launchDeleteForm("{% url 'stock-location-delete' location.id %}", { redirect: "{% url 'stock-index' %}" }); @@ -100,8 +97,7 @@ {% endif %} $('#item-create').click(function () { - launchModalForm("#modal-form", - "{% url 'stock-item-create' %}", + launchModalForm("{% url 'stock-item-create' %}", { success: function() { $("#stock-table").bootstrapTable('refresh');