From b73a608742584870eeed8218431268c523a142c3 Mon Sep 17 00:00:00 2001 From: Florian Strohmaier Date: Mon, 7 Jan 2019 16:07:52 +0100 Subject: [PATCH] JS: Check collapsible containers for unique collapsible-id --- .../icinga/behavior/collapsibleContainer.js | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/public/js/icinga/behavior/collapsibleContainer.js b/public/js/icinga/behavior/collapsibleContainer.js index 8fd513551..730ef9d0b 100644 --- a/public/js/icinga/behavior/collapsibleContainer.js +++ b/public/js/icinga/behavior/collapsibleContainer.js @@ -34,16 +34,18 @@ $(event.target).find('.collapsible-container').each(function() { var $this = $(this); - if ($this.find('.collapsible').length > 0) { - $this.addClass('has-collapsible'); - if ($this.find('.collapsible').innerHeight() > ($this.data('height') || defaultHeight)) { - $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); - $this.addClass('can-collapse'); - } - } else { - if ($this.innerHeight() > ($this.data('height') || defaultHeight)) { - $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); - $this.addClass('can-collapse'); + if ($this.data('collapsible-id') && $('[data-collapsible-id=' + $this.data('collapsible-id') + ']').length < 2) { + if ($this.find('.collapsible').length > 0) { + $this.addClass('has-collapsible'); + if ($this.find('.collapsible').innerHeight() > ($this.data('height') || defaultHeight)) { + $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); + $this.addClass('can-collapse'); + } + } else { + if ($this.innerHeight() > ($this.data('height') || defaultHeight)) { + $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); + $this.addClass('can-collapse'); + } } } updateCollapsedState($this); @@ -52,16 +54,18 @@ $(event.target).find('.collapsible-table-container').each(function() { var $this = $(this); - if ($this.find('.collapsible').length > 0) { - $this.addClass('has-collapsible'); - if ($this.find('tr').length > ($this.attr('data-numofrows') || defaultNumOfRows)) { - $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); - $this.addClass('can-collapse'); - } + if ($this.data('collapsible-id') && $('[data-collapsible-id=' + $this.data('collapsible-id') + ']').length < 2) { + if ($this.find('.collapsible').length > 0) { + $this.addClass('has-collapsible'); + if ($this.find('tr').length > ($this.attr('data-numofrows') || defaultNumOfRows)) { + $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); + $this.addClass('can-collapse'); + } - if ($this.find('li').length > ($this.attr('data-numofrows') || defaultNumOfRows)) { - $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); - $this.addClass('can-collapse'); + if ($this.find('li').length > ($this.attr('data-numofrows') || defaultNumOfRows)) { + $this.append($('#collapsible-control-ghost').clone().removeAttr('id')); + $this.addClass('can-collapse'); + } } } updateCollapsedState($this); @@ -81,11 +85,13 @@ if (expandedContainers.length > maxLength - 1) { expandedContainers.shift(); } - expandedContainers.push($c.attr('id')); + expandedContainers.push($c.data('collapsible-id')); } else { - expandedContainers.splice(expandedContainers.indexOf($c.attr('id')), 1); + expandedContainers.splice(expandedContainers.indexOf($c.data('collapsible-id')), 1); } + console.log(expandedContainers); + updateCollapsedState($c); }; @@ -102,7 +108,7 @@ } else { $collapsible = $container; } - if (expandedContainers.indexOf($container.attr('id')) > -1) { + if (expandedContainers.indexOf($container.data('collapsible-id')) > -1) { $container.removeClass('collapsed'); $collapsible.css({ maxHeight: 'none' }); } else {