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.
This commit is contained in:
Johannes Meyer 2021-02-17 12:51:26 +01:00
parent 712e74b3ce
commit 57b4a31bc3
3 changed files with 31 additions and 10 deletions

View File

@ -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');

View File

@ -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;

View File

@ -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();
},