js: Use a submit event's `submitter` property to identify the submit button
This commit is contained in:
parent
48dcb051d1
commit
eef276be93
|
@ -92,31 +92,39 @@
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
Modal.prototype.onFormSubmit = function(event) {
|
Modal.prototype.onFormSubmit = function(event) {
|
||||||
var _this = event.data.self;
|
const _this = event.data.self;
|
||||||
var $form = $(event.currentTarget).closest('form');
|
const $form = $(event.currentTarget).closest('form');
|
||||||
var $modal = $form.closest('#modal');
|
const $modal = $form.closest('#modal');
|
||||||
|
|
||||||
var $button;
|
let $button;
|
||||||
var $rememberedSubmittButton = $form.data('submitButton');
|
if (typeof event.originalEvent !== 'undefined'
|
||||||
if (typeof $rememberedSubmittButton != 'undefined') {
|
&& typeof event.originalEvent.submitter !== 'undefined'
|
||||||
if ($form.has($rememberedSubmittButton)) {
|
&& event.originalEvent.submitter !== null) {
|
||||||
$button = $rememberedSubmittButton;
|
$button = $(event.originalEvent.submitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safari fallback only
|
||||||
|
const $rememberedSubmitButton = $form.data('submitButton');
|
||||||
|
if (typeof $rememberedSubmitButton !== 'undefined') {
|
||||||
|
if (typeof $button === 'undefined' && $form.has($rememberedSubmitButton)) {
|
||||||
|
$button = $rememberedSubmitButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
$form.removeData('submitButton');
|
$form.removeData('submitButton');
|
||||||
}
|
}
|
||||||
|
|
||||||
let $autoSubmittedBy;
|
let $autoSubmittedBy;
|
||||||
if (! $autoSubmittedBy && event.detail && event.detail.submittedBy) {
|
if (typeof event.detail !== 'undefined' && "submittedBy" in event.detail) {
|
||||||
$autoSubmittedBy = $(event.detail.submittedBy);
|
$autoSubmittedBy = $(event.detail.submittedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent our other JS from running
|
// Prevent our other JS from running
|
||||||
$modal[0].dataset.noIcingaAjax = '';
|
$modal[0].dataset.noIcingaAjax = '';
|
||||||
|
|
||||||
var req = _this.icinga.loader.submitForm($form, $autoSubmittedBy, $button);
|
const req = _this.icinga.loader.submitForm($form, $autoSubmittedBy, $button);
|
||||||
req.addToHistory = false;
|
req.addToHistory = false;
|
||||||
req.done(function (data, textStatus, req) {
|
req.done(function (data, textStatus, req) {
|
||||||
var title = req.getResponseHeader('X-Icinga-Title');
|
const title = req.getResponseHeader('X-Icinga-Title');
|
||||||
if (!! title) {
|
if (!! title) {
|
||||||
_this.setTitle($modal, decodeURIComponent(title).replace(/\s::\s.*/, ''));
|
_this.setTitle($modal, decodeURIComponent(title).replace(/\s::\s.*/, ''));
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,26 +200,34 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
submitForm: function (event, $autoSubmittedBy) {
|
submitForm: function (event, $autoSubmittedBy) {
|
||||||
var _this = event.data.self;
|
const _this = event.data.self;
|
||||||
|
|
||||||
// .closest is not required unless subelements to trigger this
|
// .closest is not required unless subelements to trigger this
|
||||||
var $form = $(event.currentTarget).closest('form');
|
const $form = $(event.currentTarget).closest('form');
|
||||||
|
|
||||||
if ($form.closest('[data-no-icinga-ajax]').length > 0) {
|
if ($form.closest('[data-no-icinga-ajax]').length > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $button;
|
let $button;
|
||||||
var $rememberedSubmittButton = $form.data('submitButton');
|
if (typeof event.originalEvent !== 'undefined'
|
||||||
if (typeof $rememberedSubmittButton != 'undefined') {
|
&& typeof event.originalEvent.submitter !== 'undefined'
|
||||||
if ($form.has($rememberedSubmittButton)) {
|
&& event.originalEvent.submitter !== null) {
|
||||||
$button = $rememberedSubmittButton;
|
$button = $(event.originalEvent.submitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safari fallback only
|
||||||
|
const $rememberedSubmitButton = $form.data('submitButton');
|
||||||
|
if (typeof $rememberedSubmitButton !== 'undefined') {
|
||||||
|
if (typeof $button === 'undefined' && $form.has($rememberedSubmitButton)) {
|
||||||
|
$button = $rememberedSubmitButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
$form.removeData('submitButton');
|
$form.removeData('submitButton');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof $button === 'undefined') {
|
if (typeof $button === 'undefined') {
|
||||||
var $el;
|
let $el;
|
||||||
|
|
||||||
if (typeof event.originalEvent !== 'undefined'
|
if (typeof event.originalEvent !== 'undefined'
|
||||||
&& typeof event.originalEvent.explicitOriginalTarget === 'object') { // Firefox
|
&& typeof event.originalEvent.explicitOriginalTarget === 'object') { // Firefox
|
||||||
|
@ -239,7 +247,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $autoSubmittedBy && event.detail && event.detail.submittedBy) {
|
if (! $autoSubmittedBy && typeof event.detail !== 'undefined' && "submittedBy" in event.detail) {
|
||||||
$autoSubmittedBy = $(event.detail.submittedBy);
|
$autoSubmittedBy = $(event.detail.submittedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue