mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
js: Initialize all types of input enrichments
This commit is contained in:
parent
fcd0a0a698
commit
67de8a079a
@ -41,7 +41,7 @@ class JavaScript
|
|||||||
'js/icinga/behavior/filtereditor.js',
|
'js/icinga/behavior/filtereditor.js',
|
||||||
'js/icinga/behavior/selectable.js',
|
'js/icinga/behavior/selectable.js',
|
||||||
'js/icinga/behavior/modal.js',
|
'js/icinga/behavior/modal.js',
|
||||||
'js/icinga/behavior/complete.js'
|
'js/icinga/behavior/input-enrichment.js'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static $vendorFiles = [
|
protected static $vendorFiles = [
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* Icinga Web 2 | (c) 2020 Icinga GmbH | GPLv2+ */
|
/* Icinga Web 2 | (c) 2020 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete - Behavior for forms with auto-completion of terms
|
* InputEnrichment - Behavior for forms with enriched inputs
|
||||||
*/
|
*/
|
||||||
(function(Icinga) {
|
(function(Icinga) {
|
||||||
|
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* @param icinga
|
* @param icinga
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
var Complete = function (icinga) {
|
var InputEnrichment = function (icinga) {
|
||||||
Icinga.EventListener.call(this, icinga);
|
Icinga.EventListener.call(this, icinga);
|
||||||
|
|
||||||
this.on('beforerender', '.container', this.onBeforeRender, this);
|
this.on('beforerender', '.container', this.onBeforeRender, this);
|
||||||
@ -22,7 +22,7 @@
|
|||||||
/**
|
/**
|
||||||
* Enriched inputs
|
* Enriched inputs
|
||||||
*
|
*
|
||||||
* @type {WeakMap<object, FilterInput>}
|
* @type {WeakMap<object, FilterInput|TermInput|Completer>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._enrichments = new WeakMap();
|
this._enrichments = new WeakMap();
|
||||||
@ -37,7 +37,7 @@
|
|||||||
*/
|
*/
|
||||||
this._cachedEnrichments = {};
|
this._cachedEnrichments = {};
|
||||||
};
|
};
|
||||||
Complete.prototype = new Icinga.EventListener();
|
InputEnrichment.prototype = new Icinga.EventListener();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param event
|
* @param event
|
||||||
@ -46,13 +46,13 @@
|
|||||||
* @param autorefresh
|
* @param autorefresh
|
||||||
* @param scripted
|
* @param scripted
|
||||||
*/
|
*/
|
||||||
Complete.prototype.onBeforeRender = function (event, content, action, autorefresh, scripted) {
|
InputEnrichment.prototype.onBeforeRender = function (event, content, action, autorefresh, scripted) {
|
||||||
if (! autorefresh) {
|
if (! autorefresh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _this = event.data.self;
|
let _this = event.data.self;
|
||||||
let inputs = event.currentTarget.querySelectorAll('input[data-term-completion]');
|
let inputs = event.currentTarget.querySelectorAll('input[data-enrichment-type]');
|
||||||
|
|
||||||
// Remember current instances
|
// Remember current instances
|
||||||
inputs.forEach(function (input) {
|
inputs.forEach(function (input) {
|
||||||
@ -68,7 +68,7 @@
|
|||||||
* @param autorefresh
|
* @param autorefresh
|
||||||
* @param scripted
|
* @param scripted
|
||||||
*/
|
*/
|
||||||
Complete.prototype.onRendered = function (event, autorefresh, scripted) {
|
InputEnrichment.prototype.onRendered = function (event, autorefresh, scripted) {
|
||||||
let _this = event.data.self;
|
let _this = event.data.self;
|
||||||
let container = event.currentTarget;
|
let container = event.currentTarget;
|
||||||
|
|
||||||
@ -89,18 +89,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new instances
|
// Create new instances
|
||||||
var inputs = container.querySelectorAll('input[data-term-completion]');
|
var inputs = container.querySelectorAll('input[data-enrichment-type]');
|
||||||
inputs.forEach(function (input) {
|
inputs.forEach(function (input) {
|
||||||
var enrichment = _this._enrichments.get(input);
|
var enrichment = _this._enrichments.get(input);
|
||||||
if (! enrichment) {
|
if (! enrichment) {
|
||||||
enrichment = (new FilterInput(input)).bind();
|
switch (input.dataset.enrichmentType) {
|
||||||
enrichment.restoreTerms();
|
case 'filter':
|
||||||
|
enrichment = (new FilterInput(input)).bind();
|
||||||
|
enrichment.restoreTerms();
|
||||||
|
break;
|
||||||
|
case 'terms':
|
||||||
|
enrichment = (new TermInput(input)).bind();
|
||||||
|
enrichment.restoreTerms();
|
||||||
|
break;
|
||||||
|
case 'completion':
|
||||||
|
enrichment = (new Completer(input)).bind();
|
||||||
|
}
|
||||||
|
|
||||||
_this._enrichments.set(input, enrichment);
|
_this._enrichments.set(input, enrichment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Icinga.Behaviors.Complete = Complete;
|
Icinga.Behaviors.InputEnrichment = InputEnrichment;
|
||||||
|
|
||||||
})(Icinga);
|
})(Icinga);
|
Loading…
x
Reference in New Issue
Block a user