From 50bf126d36ce037b424ce7052b908cc449cbf948 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 24 Oct 2019 14:02:47 +0200 Subject: [PATCH] js: Move function events.getLinkTargetFor to loader.js --- public/js/icinga/behavior/actiontable.js | 4 +- public/js/icinga/events.js | 65 ++---------------------- public/js/icinga/loader.js | 52 +++++++++++++++++++ 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/public/js/icinga/behavior/actiontable.js b/public/js/icinga/behavior/actiontable.js index a8d17698c..579018db8 100644 --- a/public/js/icinga/behavior/actiontable.js +++ b/public/js/icinga/behavior/actiontable.js @@ -414,9 +414,9 @@ var count = table.selections().length; if (count > 0) { var query = table.toQuery(); - _this.icinga.loader.loadUrl(query, _this.icinga.events.getLinkTargetFor($tr)); + _this.icinga.loader.loadUrl(query, _this.icinga.loader.getLinkTargetFor($tr)); } else { - if (_this.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') { + if (_this.icinga.loader.getLinkTargetFor($tr).attr('id') === 'col2') { _this.icinga.ui.layout1col(); } } diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 363ef5045..b1e7e9e22 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -298,9 +298,9 @@ $button.addClass('active'); } - $target = _this.getLinkTargetFor($button); + $target = icinga.loader.getLinkTargetFor($button); } else { - $target = _this.getLinkTargetFor($form); + $target = icinga.loader.getLinkTargetFor($form); } if (! url) { @@ -516,7 +516,7 @@ } return false; } - $target = _this.getLinkTargetFor($a); + $target = icinga.loader.getLinkTargetFor($a); formerUrl = $target.data('icingaUrl'); if (typeof formerUrl !== 'undefined' && formerUrl.split(/#/)[0] === href.split(/#/)[0]) { @@ -528,7 +528,7 @@ return false; } } else { - $target = _this.getLinkTargetFor($a); + $target = icinga.loader.getLinkTargetFor($a); } // Load link URL @@ -542,63 +542,6 @@ return false; }, - /** - * Detect the link/form target for a given element (link, form, whatever) - */ - getLinkTargetFor: function($el) - { - var targetId; - - // If everything else fails, our target is the first column... - var $target = $('#col1'); - - // ...but usually we will use our own container... - var $container = $el.closest('.container'); - if ($container.length) { - $target = $container; - } - - // You can of course override the default behaviour: - if ($el.closest('[data-base-target]').length) { - targetId = $el.closest('[data-base-target]').data('baseTarget'); - - // Simulate _next to prepare migration to dynamic column layout - // YES, there are duplicate lines right now. - if (targetId === '_next') { - if (this.icinga.ui.hasOnlyOneColumn()) { - targetId = 'col1'; - $target = $('#' + targetId); - } else { - if ($el.closest('#col2').length) { - this.icinga.ui.moveToLeft(); - } - targetId = 'col2'; - $target = $('#' + targetId); - } - } else if (targetId === '_self') { - $target = $el.closest('.container'); - targetId = $target.attr('id'); - } else if (targetId === '_main') { - targetId = 'col1'; - $target = $('#' + targetId); - this.icinga.ui.layout1col(); - } else { - $target = $('#' + targetId); - if (! $target.length) { - this.icinga.logger.warn('Link target "#' + targetId + '" does not exist in DOM.'); - } - } - - } - - // Hardcoded layout switch unless columns are dynamic - if ($target.attr('id') === 'col2') { - this.icinga.ui.layout2col(); - } - - return $target; - }, - clearSearch: function (event) { $(event.target).parent().find('#search').attr('value', ''); }, diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 8cfcfe1f1..abd7cc9c7 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -772,6 +772,58 @@ return $notice; }, + /** + * Detect the link/form target for a given element (link, form, whatever) + */ + getLinkTargetFor: function($el) + { + // If everything else fails, our target is the first column... + var $col1 = $('#col1'); + var $target = $col1; + + // ...but usually we will use our own container... + var $container = $el.closest('.container'); + if ($container.length) { + $target = $container; + } + + // You can of course override the default behaviour: + if ($el.closest('[data-base-target]').length) { + var targetId = $el.closest('[data-base-target]').data('baseTarget'); + + // Simulate _next to prepare migration to dynamic column layout + // YES, there are duplicate lines right now. + if (targetId === '_next') { + if (this.icinga.ui.hasOnlyOneColumn()) { + $target = $col1; + } else { + if ($el.closest('#col2').length) { + this.icinga.ui.moveToLeft(); + } + + $target = $('#col2'); + } + } else if (targetId === '_self') { + $target = $el.closest('.container'); + } else if (targetId === '_main') { + $target = $col1; + this.icinga.ui.layout1col(); + } else { + $target = $('#' + targetId); + if (! $target.length) { + this.icinga.logger.warn('Link target "#' + targetId + '" does not exist in DOM.'); + } + } + } + + // Hardcoded layout switch unless columns are dynamic + if ($target.attr('id') === 'col2') { + this.icinga.ui.layout2col(); + } + + return $target; + }, + /** * Smoothly render given HTML to given container */