Merge pull request #3412 from Icinga/bugfix/filter-editor-expand-upon-auto-refresh-2964

Preserve collapsed FilterEditor subtrees across auto-refreshes
This commit is contained in:
Johannes Meyer 2018-04-06 14:55:19 +02:00 committed by GitHub
commit 5f24fffe7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class JavaScript
'js/icinga/behavior/actiontable.js',
'js/icinga/behavior/flyover.js',
'js/icinga/behavior/expandable.js',
'js/icinga/behavior/filtereditor.js',
'js/icinga/behavior/selectable.js'
);

View File

@ -0,0 +1,69 @@
/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
/**
* Icinga.Behavior.FilterEditor
*
* Initially expanded, but collapsable subtrees
*/
(function(Icinga, $) {
'use strict';
var containerId = /^col(\d+)$/;
var filterEditors = {};
function FilterEditor(icinga) {
Icinga.EventListener.call(this, icinga);
this.on('beforerender', this.beforeRender, this);
this.on('rendered', this.onRendered, this);
}
FilterEditor.prototype = new Icinga.EventListener();
FilterEditor.prototype.beforeRender = function(event) {
var $container = $(event.target);
var match = containerId.exec($container.attr('id'));
if (match !== null) {
var id = match[1];
var subTrees = {};
filterEditors[id] = subTrees;
$container.find('.tree .handle').each(function () {
var $li = $(this).closest('li');
subTrees[$li.find('select').first().attr('name')] = $li.hasClass('collapsed');
});
}
};
FilterEditor.prototype.onRendered = function(event) {
var $container = $(event.target);
var match = containerId.exec($container.attr('id'));
if (match !== null) {
var id = match[1];
if (typeof filterEditors[id] !== "undefined") {
var subTrees = filterEditors[id];
delete filterEditors[id];
$container.find('.tree .handle').each(function () {
var $li = $(this).closest('li');
var name = $li.find('select').first().attr('name');
if (typeof subTrees[name] !== "undefined" && subTrees[name] !== $li.hasClass('collapsed')) {
$li.toggleClass('collapsed');
}
});
icinga.ui.fixControls($container);
}
}
};
Icinga.Behaviors = Icinga.Behaviors || {};
Icinga.Behaviors.FilterEditor = FilterEditor;
}) (Icinga, jQuery);

View File

@ -163,6 +163,8 @@
} else {
$parent.addClass('collapsed');
}
icinga.ui.fixControls($parent.closest('.container'));
},
onLoad: function (event) {