From b4531b6b45972f5c3aa53e463bf75f336f84158e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 2 Mar 2021 16:57:49 +0100 Subject: [PATCH] js: Add support for the `search-editor` input enrichment Also makes it possible to enrich inputs in modals --- public/js/icinga/behavior/input-enrichment.js | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/public/js/icinga/behavior/input-enrichment.js b/public/js/icinga/behavior/input-enrichment.js index 85992185f..2fd6e3e0a 100644 --- a/public/js/icinga/behavior/input-enrichment.js +++ b/public/js/icinga/behavior/input-enrichment.js @@ -3,12 +3,13 @@ /** * InputEnrichment - Behavior for forms with enriched inputs */ -(function(Icinga, $) { +(function(Icinga) { "use strict"; try { var SearchBar = require('icinga/ipl/widget/SearchBar'); + var SearchEditor = require('icinga/ipl/widget/SearchEditor'); var FilterInput = require('icinga/ipl/widget/FilterInput'); var TermInput = require('icinga/ipl/widget/TermInput'); var Completer = require('icinga/ipl/widget/Completer'); @@ -26,24 +27,13 @@ var InputEnrichment = function (icinga) { Icinga.EventListener.call(this, icinga); - this.on('beforerender', '.container', this.onBeforeRender, this); - this.on('rendered', '.container', this.onRendered, this); - - /** - * Listen for events emitted by the SearchBar widget - */ - this.on('editor-open', '.container', function (event) { - this.dataset.suspendAutorefresh = ''; - $(event.target.dataset.searchEditor).trigger('rendered', [false, true]); - }); - this.on('editor-close', '.container', function () { - delete this.dataset.suspendAutorefresh; - }); + this.on('beforerender', this.onBeforeRender, this); + this.on('rendered', this.onRendered, this); /** * Enriched inputs * - * @type {WeakMap} + * @type {WeakMap} * @private */ this._enrichments = new WeakMap(); @@ -83,7 +73,7 @@ } let _this = event.data.self; - let inputs = event.currentTarget.querySelectorAll('[data-enrichment-type]'); + let inputs = event.target.querySelectorAll('[data-enrichment-type]'); // Remember current instances inputs.forEach(function (input) { @@ -101,7 +91,7 @@ */ InputEnrichment.prototype.onRendered = function (event, autorefresh, scripted) { let _this = event.data.self; - let container = event.currentTarget; + let container = event.target; if (autorefresh) { // Apply remembered instances @@ -128,6 +118,9 @@ case 'search-bar': enrichment = (new SearchBar(input)).bind(); break; + case 'search-editor': + enrichment = (new SearchEditor(input)).bind(); + break; case 'filter': enrichment = (new FilterInput(input)).bind(); enrichment.restoreTerms(); @@ -152,4 +145,4 @@ Icinga.Behaviors.InputEnrichment = InputEnrichment; -})(Icinga, jQuery); +})(Icinga);