js: Already set window.name prior bootstrapping our js runtime

Makes sure that the Window-Id already generated and utilized by the
server on the first request is used by subsequent requests instead
of a new one.

Also avoids that concurrent running id-less requests compete about
which one may set his assigned id. Now any subsequent request
already transmits the id assigned to the first one.

And it resets `window.name` in case the user performs a manual
refresh so that the id used by the server is set/utilized.

refs #3609
This commit is contained in:
Johannes Meyer 2018-11-07 09:01:29 +01:00
parent aed2e54834
commit 8212c51f8d
2 changed files with 4 additions and 3 deletions

View File

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

View File

@ -696,17 +696,17 @@
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 () {