From 3ff19f8c752724cdf6876e05ce3f37696aa25f1b Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 2 Jul 2021 11:06:52 +1000 Subject: [PATCH] Refactorin' --- InvenTree/templates/js/forms.js | 19 ++++++------------- InvenTree/templates/js/modals.js | 7 ++++++- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index 5bee4f57a6..3f0ae6fffb 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -237,11 +237,6 @@ function constructForm(url, options) { // Default HTTP method options.method = options.method || 'PATCH'; - // Create a new modal if one does not exists - if (!options.modal) { - options.modal = createNewModal(); - } - // Request OPTIONS endpoint from the API getApiEndpointOptions(url, function(OPTIONS) { @@ -396,17 +391,15 @@ function constructFormBody(fields, options) { // TODO: Dynamically create the modals, // so that we can have an infinite number of stacks! - options.modal = options.modal || '#modal-form'; - + // Create a new modal if one does not exists + if (!options.modal) { + options.modal = createNewModal(options); + } + var modal = options.modal; modalEnable(modal, true); - - // Set the form title and button labels - modalSetTitle(modal, options.title || '{% trans "Form Title" %}'); - modalSetSubmitText(modal, options.submitText || '{% trans "Submit" %}'); - modalSetCloseText(modal, options.cancelText || '{% trans "Cancel" %}'); - + // Insert generated form content $(modal).find('.modal-form-content').html(html); diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index ddce2fe109..180f3bed95 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -31,7 +31,7 @@ function createNewModal(options={}) { @@ -48,6 +48,11 @@ function createNewModal(options={}) { $(modal_name).remove(); }); + // Set labels based on supplied options + modalSetTitle(modal_name, options.title || '{% trans "Form Title" %}'); + modalSetSubmitText(modal_name, options.submitText || '{% trans "Submit" %}'); + modalSetCloseText(modal_name, options.cancelText || '{% trans "Cancel" %}'); + // Return the "name" of the modal return modal_name; }