From 57b4a31bc34fcbc91f9c065b1ec00f2c719aef08 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 17 Feb 2021 12:51:26 +0100 Subject: [PATCH] js: Don't navigate right when opening a modal Isn't the prettiest fix. I would have liked to completely remove the target preparation from `getLinkTargetFor`. But this is the easiest fix since it's only for modals that preparation is not desired. It's also the most compatible change. --- public/js/icinga/behavior/modal.js | 2 +- public/js/icinga/loader.js | 19 ++++++++++--------- public/js/icinga/ui.js | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/public/js/icinga/behavior/modal.js b/public/js/icinga/behavior/modal.js index 109e1053e..f08c87cfc 100644 --- a/public/js/icinga/behavior/modal.js +++ b/public/js/icinga/behavior/modal.js @@ -40,7 +40,7 @@ var $a = $(event.currentTarget); var url = $a.attr('href'); var $modal = _this.$ghost.clone(); - var $urlTarget = _this.icinga.loader.getLinkTargetFor($a); + var $urlTarget = _this.icinga.loader.getLinkTargetFor($a, false); // Add showCompact, we don't want controls in a modal url = _this.icinga.utils.addUrlFlag(url, 'showCompact'); diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 53d7033db..75326bc12 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -1060,9 +1060,16 @@ /** * Detect the link/form target for a given element (link, form, whatever) + * + * @param {object} $el jQuery set with the element + * @param {boolean} prepare Pass `false` to disable column preparation */ - getLinkTargetFor: function($el) + getLinkTargetFor: function($el, prepare) { + if (typeof prepare === 'undefined') { + prepare = true; + } + // If everything else fails, our target is the first column... var $col1 = $('#col1'); var $target = $col1; @@ -1083,17 +1090,12 @@ 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) { @@ -1102,9 +1104,8 @@ } } - // Hardcoded layout switch unless columns are dynamic - if ($target.attr('id') === 'col2') { - this.icinga.ui.layout2col(); + if (prepare) { + this.icinga.ui.prepareColumnFor($el, $target); } return $target; diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js index 3dc21fa52..97d2a69cf 100644 --- a/public/js/icinga/ui.js +++ b/public/js/icinga/ui.js @@ -340,6 +340,26 @@ $('#layout').trigger('layout-change'); }, + prepareColumnFor: function ($el, $target) { + var explicitTarget; + + if ($target.attr('id') === 'col2') { + if ($el.closest('#col2').length) { + explicitTarget = $el.closest('[data-base-target]').data('baseTarget'); + if (typeof explicitTarget !== 'undefined' && explicitTarget === '_next') { + this.moveToLeft(); + } + } else { + this.layout2col(); + } + } else { // if ($target.attr('id') === 'col1') + explicitTarget = $el.closest('[data-base-target]').data('baseTarget'); + if (typeof explicitTarget !== 'undefined' && explicitTarget === '_main') { + this.layout1col(); + } + } + }, + getAvailableColumnSpace: function () { return $('#main').width() / this.getDefaultFontSize(); },