Refactor "showAlertDialog" function

This commit is contained in:
Oliver 2021-07-12 20:55:28 +10:00
parent e9bf4b4cef
commit a1579eecfd
2 changed files with 15 additions and 35 deletions

View File

@ -103,6 +103,14 @@ function createNewModal(options={}) {
modalSetSubmitText(modal_name, options.submitText || '{% trans "Submit" %}');
modalSetCloseText(modal_name, options.cancelText || '{% trans "Cancel" %}');
if (options.hideSubmitButton) {
$(modal_name).find('#modal-form-submit').hide();
}
if (options.hideCloseButton) {
$(modal_name).find('#modal-form-cancel').hide();
}
// Return the "name" of the modal
return modal_name;
}
@ -552,25 +560,18 @@ function showAlertDialog(title, content, options={}) {
*
* title - Title text
* content - HTML content of the dialog window
* options:
* modal - modal form to use (default = '#modal-alert-dialog')
*/
var modal = options.modal || '#modal-alert-dialog';
$(modal).on('shown.bs.modal', function() {
$(modal + ' .modal-form-content').scrollTop(0);
var modal = createNewModal({
title: title,
cancelText: '{% trans "Close" %}',
hideSubmitButton: true,
});
modalSetTitle(modal, title);
modalSetContent(modal, content);
modalSetContent(modal, content);
$(modal).modal({
backdrop: 'static',
keyboard: false,
});
$(modal).modal('show');
$(modal).modal('show');
}

View File

@ -77,25 +77,4 @@
</div>
</div>
</div>
</div>
<div class='modal fade modal-fixed-footer' role='dialog' id='modal-alert-dialog'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h3 id='modal-title'>Alert Information</h3>
</div>
<div class='modal-form-content-wrapper'>
<div class='modal-form-content'>
</div>
</div>
<div class='modal-footer'>
<div id='modal-footer-buttons'></div>
<button type='button' class='btn btn-default' data-dismiss='modal'>{% trans "Close" %}</button>
</div>
</div>
</div>
</div>
</div>