Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,57 @@
// Data Tables
new DataTable('.dataTables');
});

/*
|---------------------------------------------------------------
| Nested Modal Fix for ITFlow AJAX Modals
| Each modal gets a unique container, parent modals remain open
|---------------------------------------------------------------
*/

(function() {
if (!window.createAjaxModal) return;

Check warning on line 413 in js/app.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AZsJPKcROxOAOSjhJR01&open=AZsJPKcROxOAOSjhJR01&pullRequest=1252

// Keep original function just in case
const originalCreateAjaxModal = window.createAjaxModal;

Check warning on line 416 in js/app.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AZsJPKcROxOAOSjhJR04&open=AZsJPKcROxOAOSjhJR04&pullRequest=1252

Check warning on line 416 in js/app.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of the unused 'originalCreateAjaxModal' variable.

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AZsJPKcROxOAOSjhJR02&open=AZsJPKcROxOAOSjhJR02&pullRequest=1252

Check warning on line 416 in js/app.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless assignment to variable "originalCreateAjaxModal".

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AZsJPKcROxOAOSjhJR03&open=AZsJPKcROxOAOSjhJR03&pullRequest=1252

window.createAjaxModal = function(contentHtml) {

Check warning on line 418 in js/app.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=itflow-org_itflow&issues=AZsJPKcROxOAOSjhJR05&open=AZsJPKcROxOAOSjhJR05&pullRequest=1252
// Generate a unique ID for this modal
const modalId = 'ajaxModal_' + Date.now();

// Create a new modal container
const $modal = $('<div class="modal fade" tabindex="-1" aria-hidden="true">')
.attr('id', modalId)
.html(contentHtml)
.appendTo('body');

// Initialize Bootstrap modal
$modal.modal('show');

// Ensure only this modal is removed when hidden
$modal.on('hidden.bs.modal', function () {
$(this).remove();
});

return $modal;
};

// Optional: Keep proper z-index stacking for multiple nested modals
$(document).on('show.bs.modal', '.modal', function () {
const zIndex = 1040 + (10 * $('.modal:visible').length);
$(this).css('z-index', zIndex);
setTimeout(() => {
$('.modal-backdrop').not('.modal-stack')
.css('z-index', zIndex - 1)
.addClass('modal-stack');
}, 0);
});

$(document).on('hidden.bs.modal', '.modal', function () {
if ($('.modal:visible').length > 0) {
$('body').addClass('modal-open');
}
});

})();