From ca2d3a1a7b9bc7f407c460edab77b16870bbd36f Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 8 May 2018 20:46:23 +1000 Subject: [PATCH] Consolidated modal code - Default modal passed down through the chain --- InvenTree/static/script/inventree/modals.js | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/InvenTree/static/script/inventree/modals.js b/InvenTree/static/script/inventree/modals.js index 624ba23997..562ad67413 100644 --- a/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/static/script/inventree/modals.js @@ -65,7 +65,9 @@ function closeModal(modal='#modal-form') { $(modal).modal('hide'); } -function openModal(modal, title='', content='') { +function openModal(options) { + + var modal = options.modal || '#modal-form'; $(modal).on('shown.bs.modal', function() { $(modal + ' .modal-form-content').scrollTop(0); @@ -83,8 +85,17 @@ function openModal(modal, title='', content='') { } }); - modalSetTitle(modal, title); - modalSetContent(modal, content); + if (options.title) { + modalSetTitle(modal, options.title); + } + + if (options.content) { + modalSetContent(modal, options.content); + } + + if (options.buttonText) { + modalSetButtonText(modal, options.buttonText); + } $(modal).modal({ backdrop: 'static', @@ -111,7 +122,7 @@ function launchDeleteForm(url, options = {}) { type: 'get', dataType: 'json', beforeSend: function() { - openModal(modal); + openModal({modal: modal}); }, success: function (response) { if (response.title) { @@ -232,7 +243,7 @@ function launchModalForm(url, options = {}) { type: 'get', dataType: 'json', beforeSend: function () { - openModal(modal); + openModal({modal: modal}); }, success: function(response) { if (response.title) { @@ -245,7 +256,7 @@ function launchModalForm(url, options = {}) { if (response.html_form) { injectModalForm(modal, response.html_form); - handleModalForm(modal, url, options); + handleModalForm(url, options); } else { alert('JSON response missing form data');