Refactor "showQuestionDialog" function

This commit is contained in:
Oliver 2021-07-12 21:03:01 +10:00
parent a1579eecfd
commit edf4aab063
2 changed files with 5 additions and 42 deletions

View File

@ -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');
}

View File

@ -57,24 +57,3 @@
</div>
</div>
</div>
<div class='modal fade modal-fixed-footer' role='dialog' id='modal-question-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'>Question Here</h3>
</div>
<div class='modal-form-content'>
</div>
<div class='modal-footer'>
<div id='modal-footer-buttons'></div>
<button type='button' class='btn btn-default' id='modal-form-cancel' data-dismiss='modal'>{% trans "Cancel" %}</button>
<button type='button' class='btn btn-primary' id='modal-form-accept'>{% trans "Accept" %}</button>
</div>
</div>
</div>
</div>