mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 13:54:26 +02:00
Merge pull request #3610 from Icinga/fix/window-id-cannot-be-used-to-differentiate-containers-3609
Fix window id cannot be used to differentiate containers
This commit is contained in:
commit
f72aa291bc
@ -85,6 +85,7 @@ $innerLayoutScript = $this->layout()->innerLayout . '.phtml';
|
|||||||
<script type="text/javascript" src="<?= $this->href($jsfile) ?>"></script>
|
<script type="text/javascript" src="<?= $this->href($jsfile) ?>"></script>
|
||||||
<!--<![endif]-->
|
<!--<![endif]-->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
window.name = '<?= $this->protectId('Icinga') ?>';
|
||||||
var icinga = new Icinga({
|
var icinga = new Icinga({
|
||||||
baseUrl: '<?= $this->baseUrl(); ?>'
|
baseUrl: '<?= $this->baseUrl(); ?>'
|
||||||
});
|
});
|
||||||
|
@ -107,7 +107,12 @@
|
|||||||
|
|
||||||
// Ask for a new window id in case we don't already have one
|
// Ask for a new window id in case we don't already have one
|
||||||
if (this.icinga.ui.hasWindowId()) {
|
if (this.icinga.ui.hasWindowId()) {
|
||||||
headers['X-Icinga-WindowId'] = this.icinga.ui.getWindowId();
|
var windowId = this.icinga.ui.getWindowId();
|
||||||
|
var containerId = this.icinga.ui.getUniqueContainerId($target);
|
||||||
|
if (containerId) {
|
||||||
|
windowId = windowId + '_' + containerId;
|
||||||
|
}
|
||||||
|
headers['X-Icinga-WindowId'] = windowId;
|
||||||
} else {
|
} else {
|
||||||
headers['X-Icinga-WindowId'] = 'undefined';
|
headers['X-Icinga-WindowId'] = 'undefined';
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,8 @@
|
|||||||
'data-icinga-title': $col.data('icingaTitle'),
|
'data-icinga-title': $col.data('icingaTitle'),
|
||||||
'data-icinga-refresh': $col.data('icingaRefresh'),
|
'data-icinga-refresh': $col.data('icingaRefresh'),
|
||||||
'data-last-update': $col.data('lastUpdate'),
|
'data-last-update': $col.data('lastUpdate'),
|
||||||
'data-icinga-module': $col.data('icingaModule')
|
'data-icinga-module': $col.data('icingaModule'),
|
||||||
|
'data-icinga-container-id': $col.data('icingaContainerId')
|
||||||
},
|
},
|
||||||
'class': $col.attr('class')
|
'class': $col.attr('class')
|
||||||
};
|
};
|
||||||
@ -207,6 +208,7 @@
|
|||||||
$col.removeData('icingaRefresh');
|
$col.removeData('icingaRefresh');
|
||||||
$col.removeData('lastUpdate');
|
$col.removeData('lastUpdate');
|
||||||
$col.removeData('icingaModule');
|
$col.removeData('icingaModule');
|
||||||
|
$col.removeData('icingaContainerId');
|
||||||
$col.removeAttr('class').attr('class', 'container');
|
$col.removeAttr('class').attr('class', 'container');
|
||||||
return props;
|
return props;
|
||||||
},
|
},
|
||||||
@ -219,6 +221,7 @@
|
|||||||
$col.data('icingaRefresh', backup['data']['data-icinga-refresh']);
|
$col.data('icingaRefresh', backup['data']['data-icinga-refresh']);
|
||||||
$col.data('lastUpdate', backup['data']['data-last-update']);
|
$col.data('lastUpdate', backup['data']['data-last-update']);
|
||||||
$col.data('icingaModule', backup['data']['data-icinga-module']);
|
$col.data('icingaModule', backup['data']['data-icinga-module']);
|
||||||
|
$col.data('icingaContainerId', backup['data']['data-icinga-container-id']);
|
||||||
},
|
},
|
||||||
|
|
||||||
triggerWindowResize: function () {
|
triggerWindowResize: function () {
|
||||||
@ -703,21 +706,44 @@
|
|||||||
this.fixControls();
|
this.fixControls();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getUniqueContainerId: function ($cont) {
|
||||||
|
if (typeof $cont === 'undefined' || !$cont.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var containerId = $cont.data('icingaContainerId');
|
||||||
|
if (typeof containerId === 'undefined') {
|
||||||
|
/**
|
||||||
|
* Only generate an id if it's not for col1 or the menu (which are using the non-suffixed window id).
|
||||||
|
* This is based on the assumption that the server only knows about the menu and first column
|
||||||
|
* and therefore does not need to protect its ids. (As the menu is most likely part of the sidebar)
|
||||||
|
*/
|
||||||
|
if ($cont.attr('id') === 'menu' || $cont.attr('id') === 'col1') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
containerId = this.icinga.utils.generateId(6); // Random because the content may move
|
||||||
|
$cont.data('icingaContainerId', containerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return containerId;
|
||||||
|
},
|
||||||
|
|
||||||
getWindowId: function () {
|
getWindowId: function () {
|
||||||
if (! this.hasWindowId()) {
|
if (! this.hasWindowId()) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return window.name.match(/^Icinga_([a-zA-Z0-9]+)$/)[1];
|
return window.name.match(/^Icinga-([a-zA-Z0-9]+)$/)[1];
|
||||||
},
|
},
|
||||||
|
|
||||||
hasWindowId: function () {
|
hasWindowId: function () {
|
||||||
var res = window.name.match(/^Icinga_([a-zA-Z0-9]+)$/);
|
var res = window.name.match(/^Icinga-([a-zA-Z0-9]+)$/);
|
||||||
return typeof res === 'object' && null !== res;
|
return typeof res === 'object' && null !== res;
|
||||||
},
|
},
|
||||||
|
|
||||||
setWindowId: function (id) {
|
setWindowId: function (id) {
|
||||||
this.icinga.logger.debug('Setting new window id', id);
|
this.icinga.logger.debug('Setting new window id', id);
|
||||||
window.name = 'Icinga_' + id;
|
window.name = 'Icinga-' + id;
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
|
@ -286,8 +286,7 @@
|
|||||||
while (true) {
|
while (true) {
|
||||||
var id = $node.attr('id');
|
var id = $node.attr('id');
|
||||||
|
|
||||||
// Ignore forms and form controls because id generation is unreliable :(
|
if (typeof id !== 'undefined') {
|
||||||
if (typeof id !== 'undefined' && ! $node.is(':input') && ! $node.is('form')) {
|
|
||||||
path.push('#' + id);
|
path.push('#' + id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -412,6 +411,37 @@
|
|||||||
str = padding + str;
|
str = padding + str;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffle a string
|
||||||
|
*
|
||||||
|
* @param {String} str The string to shuffle
|
||||||
|
*
|
||||||
|
* @returns {String} The shuffled string
|
||||||
|
*/
|
||||||
|
shuffleString: function(str) {
|
||||||
|
var a = str.split(""),
|
||||||
|
n = a.length;
|
||||||
|
|
||||||
|
for(var i = n - 1; i > 0; i--) {
|
||||||
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
|
var tmp = a[i];
|
||||||
|
a[i] = a[j];
|
||||||
|
a[j] = tmp;
|
||||||
|
}
|
||||||
|
return a.join("");
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an id
|
||||||
|
*
|
||||||
|
* @param {Number} len The desired length of the id
|
||||||
|
*
|
||||||
|
* @returns {String} The id
|
||||||
|
*/
|
||||||
|
generateId: function(len) {
|
||||||
|
return this.shuffleString('abcefghijklmnopqrstuvwxyz').substr(0, len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user