diff --git a/InvenTree/static/script/inventree/modals.js b/InvenTree/static/script/inventree/modals.js index dd730b0c92..4f8ec88b6b 100644 --- a/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/static/script/inventree/modals.js @@ -126,6 +126,61 @@ function modalSubmit(modal, callback) { } +function renderErrorMessage(xhr) { + + var html = '' + xhr.statusText + '
'; + + html += 'Status Code - ' + xhr.status + '

'; + + html += ` +
+
+ +
+
`; + + html += xhr.responseText; + + html += ` +
+
+
+
`; + + return html; +} + + +function showDialog(title, content, options={}) { + /* Display a modal dialog message box. + * + * title - Title text + * content - HTML content of the dialog window + * options: + * modal - modal form to use (default = '#modal-dialog') + */ + + var modal = options.modal || '#modal-dialog'; + + $(modal).on('shown.bs.modal', function() { + $(modal + ' .modal-form-content').scrollTop(0); + }); + + modalSetTitle(modal, title); + modalSetContent(modal, content); + + $(modal).modal({ + backdrop: 'static', + keyboard: false, + }); + + $(modal).modal('show'); +} + function openModal(options) { /* Open a modal form, and perform some action based on the provided options object: * @@ -317,8 +372,10 @@ function handleModalForm(url, options) { } }, error: function(xhr, ajaxOptions, thrownError) { - alert('Error posting form data:\n' + thrownError); - $(modal).modal('hide'); + // There was an error submitting form data via POST + + $(modal).modal('hide'); + showDialog('Error posting form data', renderErrorMessage(xhr)); }, complete: function(xhr) { //TODO diff --git a/InvenTree/templates/modals.html b/InvenTree/templates/modals.html index 9ba0335572..7238c5cf2a 100644 --- a/InvenTree/templates/modals.html +++ b/InvenTree/templates/modals.html @@ -37,4 +37,22 @@ + + + \ No newline at end of file