From ebe2ae77a56930edecf3d54d2a3935cb4da8ae27 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 19:18:34 +0200 Subject: [PATCH 1/4] hide error message with response --- InvenTree/templates/js/modals.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index c8ebd90eb4..3ff20a9e5f 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -776,7 +776,8 @@ function handleModalForm(url, options) { // Form was returned, invalid! else { - if (!options.hideErrorMessage) { + // Disable error message with option or response + if (!options.hideErrorMessage && !response.hideErrorMessage) { var warningDiv = $(modal).find('#form-validation-warning'); warningDiv.css('display', 'block'); } From 3d17388b48e30e551766a77fd09a93619bd74026 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 19:22:00 +0200 Subject: [PATCH 2/4] set modal title with response --- InvenTree/templates/js/modals.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index 3ff20a9e5f..a55a62746c 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -792,6 +792,11 @@ function handleModalForm(url, options) { if (options.secondary) { attachSecondaries(modal, options.secondary); } + + // Set modal title with response + if (response.title) { + modalSetTitle(modal, response.title); + } } else { $(modal).modal('hide'); From 96c29847e15acea0e77ec24a44f793a091b9568b Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 19:23:30 +0200 Subject: [PATCH 3/4] add custom buttons with response --- InvenTree/templates/js/modals.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index a55a62746c..7ac19ec4ce 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -797,6 +797,14 @@ function handleModalForm(url, options) { if (response.title) { modalSetTitle(modal, response.title); } + + // Clean custom action buttons + $(modal).find('#modal-footer-buttons').html(''); + + // Add custom action buttons with response + if (response.buttons) { + attachButtons(modal, response.buttons); + } } else { $(modal).modal('hide'); @@ -902,6 +910,11 @@ function launchModalForm(url, options = {}) { attachButtons(modal, options.buttons); } + // Add custom buttons from response + if (response.buttons) { + attachButtons(modal, response.buttons); + } + } else { $(modal).modal('hide'); showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}'); From c74ee4e9251239a737d6f8c265febbc9f8a4e6bb Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 19:24:08 +0200 Subject: [PATCH 4/4] doc for option.buttons --- InvenTree/templates/js/modals.js | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index 7ac19ec4ce..03893a47b8 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -851,6 +851,7 @@ function launchModalForm(url, options = {}) { * secondary - List of secondary modals to attach * callback - List of callback functions to attach to inputs * focus - Select which field to focus on by default + * buttons - additional buttons that should be added as array with [name, title] */ var modal = options.modal || '#modal-form';