From edf4aab063d875d21b229db451481afda634f7ba Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 12 Jul 2021 21:03:01 +1000 Subject: [PATCH] Refactor "showQuestionDialog" function --- InvenTree/templates/js/modals.js | 26 +++++--------------------- InvenTree/templates/modals.html | 21 --------------------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index 1b685cb2a8..b404af364c 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -12,7 +12,6 @@ */ function createNewModal(options={}) { - var id = 1; // Check out what modal forms are already being displayed @@ -588,22 +587,15 @@ function showQuestionDialog(title, content, options={}) { * cancel - Functino to run if the user presses 'Cancel' */ - var modal = options.modal || '#modal-question-dialog'; - - $(modal).on('shown.bs.modal', function() { - $(modal + ' .modal-form-content').scrollTop(0); + var modal = createNewModal({ + title: title, + submitText: options.accept_text || '{% trans "Accept" %}', + cancelText: options.cancel_text || '{% trans "Cancel" %}', }); - modalSetTitle(modal, title); modalSetContent(modal, content); - var accept_text = options.accept_text || '{% trans "Accept" %}'; - var cancel_text = options.cancel_text || '{% trans "Cancel" %}'; - - $(modal).find('#modal-form-cancel').html(cancel_text); - $(modal).find('#modal-form-accept').html(accept_text); - - $(modal).on('click', '#modal-form-accept', function() { + $(modal).on('click', "#modal-form-submit", function() { $(modal).modal('hide'); if (options.accept) { @@ -611,14 +603,6 @@ function showQuestionDialog(title, content, options={}) { } }); - $(modal).on('click', 'modal-form-cancel', function() { - $(modal).modal('hide'); - - if (options.cancel) { - options.cancel(); - } - }); - $(modal).modal('show'); } diff --git a/InvenTree/templates/modals.html b/InvenTree/templates/modals.html index 7b1c54bfb7..11ddc40938 100644 --- a/InvenTree/templates/modals.html +++ b/InvenTree/templates/modals.html @@ -56,25 +56,4 @@ - - - - \ No newline at end of file