Skip to content

Commit

Permalink
Merge pull request #5026 from Icinga/let-autosubmits-trigger-real-sub…
Browse files Browse the repository at this point in the history
…mits

Let autosubmits trigger real submits
  • Loading branch information
nilmerg authored May 19, 2023
2 parents 63eae12 + cb6a0c1 commit e0e2ff7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
24 changes: 22 additions & 2 deletions public/js/icinga/behavior/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -117,6 +125,8 @@
if (req.getResponseHeader('X-Icinga-Redirect')) {
_this.hide($modal);
}
}).always(function () {
delete $modal[0].dataset.noIcingaAjax;
});

if (typeof $autoSubmittedBy === 'undefined') {
Expand All @@ -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 }
}));
};

/**
Expand Down
12 changes: 11 additions & 1 deletion public/js/icinga/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}));
},

/**
Expand Down

0 comments on commit e0e2ff7

Please sign in to comment.