diff --git a/public/js/icinga/behavior/modal.js b/public/js/icinga/behavior/modal.js index 0083f769b0..0bd849b44c 100644 --- a/public/js/icinga/behavior/modal.js +++ b/public/js/icinga/behavior/modal.js @@ -91,7 +91,7 @@ * @param $autoSubmittedBy {jQuery} The element triggering the auto submit, if any * @returns {boolean} */ - Modal.prototype.onFormSubmit = function(event, $autoSubmittedBy) { + Modal.prototype.onFormSubmit = function(event) { var _this = event.data.self; var $form = $(event.currentTarget).closest('form'); var $modal = $form.closest('#modal'); @@ -105,6 +105,14 @@ $form.removeData('submitButton'); } + let $autoSubmittedBy; + if (! $autoSubmittedBy && event.detail && event.detail.submittedBy) { + $autoSubmittedBy = $(event.detail.submittedBy); + } + + // Prevent our other JS from running + $modal[0].dataset.noIcingaAjax = ''; + var req = _this.icinga.loader.submitForm($form, $autoSubmittedBy, $button); req.addToHistory = false; req.$redirectTarget = $modal.data('redirectTarget'); @@ -117,6 +125,8 @@ if (req.getResponseHeader('X-Icinga-Redirect')) { _this.hide($modal); } + }).always(function () { + delete $modal[0].dataset.noIcingaAjax; }); if (typeof $autoSubmittedBy === 'undefined') { @@ -136,7 +146,17 @@ * @returns {boolean} */ Modal.prototype.onFormAutoSubmit = function(event) { - return event.data.self.onFormSubmit(event, $(event.currentTarget)); + let form = event.currentTarget.form; + let modal = form.closest('#modal'); + + // Prevent our other JS from running + modal.dataset.noIcingaAjax = ''; + + form.dispatchEvent(new CustomEvent('submit', { + cancelable: true, + bubbles: true, + detail: { submittedBy: event.currentTarget } + })); }; /** diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 186a41c7cc..1878d8f604 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -183,7 +183,17 @@ }, autoSubmitForm: function (event) { - return event.data.self.submitForm(event, $(event.currentTarget)); + let form = event.currentTarget.form; + + if (form.closest('[data-no-icinga-ajax]')) { + return; + } + + form.dispatchEvent(new CustomEvent('submit', { + cancelable: true, + bubbles: true, + detail: { submittedBy: event.currentTarget } + })); }, /**