diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:38:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:38:04 +0000 |
commit | 1ff5c35de5dbd70a782875a91dd2232fd01b002b (patch) | |
tree | 77d9ce5e1bf78b3e6ef79f8f6e7861e2ced3c09b /asset/js/widget/SearchBar.js | |
parent | Initial commit. (diff) | |
download | icinga-php-library-upstream/0.10.1.tar.xz icinga-php-library-upstream/0.10.1.zip |
Adding upstream version 0.10.1.upstream/0.10.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'asset/js/widget/SearchBar.js')
-rw-r--r-- | asset/js/widget/SearchBar.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/asset/js/widget/SearchBar.js b/asset/js/widget/SearchBar.js new file mode 100644 index 0000000..276de17 --- /dev/null +++ b/asset/js/widget/SearchBar.js @@ -0,0 +1,81 @@ +define(["../notjQuery"], function ($) { + + "use strict"; + + class SearchBar { + constructor(form) { + this.form = form; + this.filterInput = null; + } + + bind() { + $(this.form.parentNode).on('click', '[data-search-editor-url]', this.onOpenerClick, this); + + return this; + } + + refresh(form) { + if (form === this.form) { + // If the DOM node is still the same, nothing has changed + return; + } + + this.form = form; + this.bind(); + } + + destroy() { + this.form = null; + this.filterInput = null; + } + + setFilterInput(filterInput) { + this.filterInput = filterInput; + + return this; + } + + onOpenerClick(event) { + let opener = event.currentTarget; + let editorUrl = opener.dataset.searchEditorUrl; + let filterQueryString = this.filterInput.getQueryString(); + let layout = document.getElementById('layout'); + + editorUrl += (editorUrl.indexOf('?') > -1 ? '&' : '?') + filterQueryString; + + // Disable pointer events to block further function calls + opener.style.pointerEvents = 'none'; + + let observer = new MutationObserver((mutations) => { + for (let mutation of mutations) { + if (mutation.type === 'childList') { + mutation.removedNodes.forEach((node) => { + // Remove the pointerEvent none style to make the button clickable again + // after the modal has been removed + if (node.id === 'modal') { + opener.style.pointerEvents = ''; + observer.disconnect(); + } + }); + } + } + }); + + observer.observe(layout, {childList: true}); + + // The search editor should open in a modal. We simulate a click on an anchor + // appropriately prepared so that Icinga Web 2 will handle it natively. + let a = document.createElement('a'); + a.classList.add('modal-opener'); + a.href = editorUrl; + a.dataset.noIcingaAjax = ''; + a.dataset.icingaModal = ''; + + opener.parentNode.insertBefore(a, opener.nextSibling); + a.click(); + a.remove(); + } + } + + return SearchBar; +}); |