From cbf8cfc738120bb96f848cf0dd63887ff68f39b8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 11 Jan 2023 11:40:12 +0100 Subject: [PATCH] js: Transmit `X-Icinga-AutoSubmittedBy` upon autosubmits This header contains the name or id of the element responsible for triggering the automatic form submission. --- public/js/icinga/loader.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index d298cc5d8..2ad05d29f 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -184,7 +184,12 @@ } } - var req = this.loadUrl(url, $target, data, method); + var extraHeaders = {}; + if ($autoSubmittedBy && ($autoSubmittedBy.attr('name') || $autoSubmittedBy.attr('id'))) { + extraHeaders['X-Icinga-AutoSubmittedBy'] = $autoSubmittedBy.attr('name') || $autoSubmittedBy.attr('id'); + } + + var req = this.loadUrl(url, $target, data, method, undefined, undefined, undefined, extraHeaders); req.forceFocus = $autoSubmittedBy ? $autoSubmittedBy : $button.length ? $button : null; req.autosubmit = !! $autoSubmittedBy; req.addToHistory = method === 'GET'; @@ -211,8 +216,9 @@ * @param {string} action How to handle the response ('replace' or 'append'), default is 'replace' * @param {boolean} autorefresh Whether the cause is a autorefresh or not * @param {object} progressTimer A timer to be stopped when the request is done + * @param {object} extraHeaders Extra header entries */ - loadUrl: function (url, $target, data, method, action, autorefresh, progressTimer) { + loadUrl: function (url, $target, data, method, action, autorefresh, progressTimer, extraHeaders) { var id = null; // Default method is GET @@ -280,6 +286,10 @@ headers['X-Icinga-WindowId'] = 'undefined'; } + if (typeof extraHeaders !== 'undefined') { + headers = $.extend(headers, extraHeaders); + } + // This is jQuery's default content type var contentType = 'application/x-www-form-urlencoded; charset=UTF-8';