js: Move function events.getLinkTargetFor to loader.js

This commit is contained in:
Johannes Meyer 2019-10-24 14:02:47 +02:00
parent 8a16349fe4
commit 2ea18a5a16
3 changed files with 58 additions and 63 deletions

View File

@ -414,9 +414,9 @@
var count = table.selections().length; var count = table.selections().length;
if (count > 0) { if (count > 0) {
var query = table.toQuery(); 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 { } else {
if (_this.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') { if (_this.icinga.loader.getLinkTargetFor($tr).attr('id') === 'col2') {
_this.icinga.ui.layout1col(); _this.icinga.ui.layout1col();
} }
} }

View File

@ -298,9 +298,9 @@
$button.addClass('active'); $button.addClass('active');
} }
$target = _this.getLinkTargetFor($button); $target = icinga.loader.getLinkTargetFor($button);
} else { } else {
$target = _this.getLinkTargetFor($form); $target = icinga.loader.getLinkTargetFor($form);
} }
if (! url) { if (! url) {
@ -516,7 +516,7 @@
} }
return false; return false;
} }
$target = _this.getLinkTargetFor($a); $target = icinga.loader.getLinkTargetFor($a);
formerUrl = $target.data('icingaUrl'); formerUrl = $target.data('icingaUrl');
if (typeof formerUrl !== 'undefined' && formerUrl.split(/#/)[0] === href.split(/#/)[0]) { if (typeof formerUrl !== 'undefined' && formerUrl.split(/#/)[0] === href.split(/#/)[0]) {
@ -528,7 +528,7 @@
return false; return false;
} }
} else { } else {
$target = _this.getLinkTargetFor($a); $target = icinga.loader.getLinkTargetFor($a);
} }
// Load link URL // Load link URL
@ -542,63 +542,6 @@
return false; 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) { clearSearch: function (event) {
$(event.target).parent().find('#search').attr('value', ''); $(event.target).parent().find('#search').attr('value', '');
}, },

View File

@ -772,6 +772,58 @@
return $notice; 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 * Smoothly render given HTML to given container
*/ */