From 24165e6d2f880ca5bd6ad28a24598e0b3fa67d28 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 30 Oct 2018 16:32:31 +0100 Subject: [PATCH] js: auto-suggestion should respect DB instance --- public/js/module.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/public/js/module.js b/public/js/module.js index 5599058a..fce0e86c 100644 --- a/public/js/module.js +++ b/public/js/module.js @@ -277,18 +277,38 @@ */ refreshSuggestionList: function($suggestions, $el) { - $suggestions.load(this.module.icinga.config.baseUrl + '/director/suggest', { - value: $el.val(), - context: $el.data('suggestion-context'), - for_host: $el.data('suggestion-for-host') - }, function (responseText, textStatus, jqXHR) { + // Not sure whether we need this Accept-header + var headers = { 'X-Icinga-Accept': 'text/html' }; + var icinga = this.module.icinga; + + // Ask for a new window id in case we don't already have one + if (icinga.ui.hasWindowId()) { + headers['X-Icinga-WindowId'] = icinga.ui.getWindowId(); + } else { + headers['X-Icinga-WindowId'] = 'undefined'; + } + + var onResponse = function (data, textStatus, req) { + $suggestions.html(data); var $li = $suggestions.find('li'); if ($li.length) { $suggestions.show(); } else { $suggestions.hide(); } + }; + + var req = $.ajax({ + type: 'POST', + url: this.module.icinga.config.baseUrl + '/director/suggest', + data: { + value: $el.val(), + context: $el.data('suggestion-context'), + for_host: $el.data('suggestion-for-host') + }, + headers: headers }); + req.done(onResponse); return $suggestions; },