Fix CMMS config timing: read from URL params, not window.MESH_TOOL_CONFIG
A parent iframe cannot inject window.MESH_TOOL_CONFIG into this app's window before init() runs - by the time the iframe's load event fires (the only cross-frame signal available for a same-origin page this app's own server generates, not the CMMS), init() has already executed and already decided to call restore_space() instead. Query params are read synchronously during init() itself, before the existing 'hide url params' cleanup strips them - self.MESH_TOOL_CONFIG is still set from them so util.download() (src/mesh/build.js) has one stable place to read from.
This commit is contained in:
parent
ee5b863f02
commit
0acf40cac2
1 changed files with 24 additions and 8 deletions
|
|
@ -150,14 +150,30 @@ function init() {
|
||||||
// trigger space event binding
|
// trigger space event binding
|
||||||
call.space_init({ space: space, platform });
|
call.space_init({ space: space, platform });
|
||||||
|
|
||||||
// CMMS embedding (not upstream): window.MESH_TOOL_CONFIG is set by the
|
// CMMS embedding (not upstream): the host page (public/mesh-edit.php)
|
||||||
// host page (public/mesh-edit.php) when this is launched job-scoped to
|
// iframes this at /mesh/?cmms_load=...&cmms_save=...&cmms_owner=...
|
||||||
// repair one specific attachment, rather than the normal freestanding
|
// &cmms_csrf=...&cmms_name=... when launched job-scoped to repair one
|
||||||
// app. When present, load that file instead of restoring whatever
|
// specific attachment, rather than the normal freestanding app.
|
||||||
// workspace happened to be in this browser's local IndexedDB - the
|
// Query params, not a window.MESH_TOOL_CONFIG global set by the parent
|
||||||
// whole point of a job-scoped launch is "this exact file", not
|
// frame: this app's own served index.html isn't something the CMMS
|
||||||
// whatever was last open here.
|
// renders, so there's no point to inject a <script> into before this
|
||||||
if (self.MESH_TOOL_CONFIG && self.MESH_TOOL_CONFIG.loadUrl) {
|
// module runs, and by the time an iframe's `load` event fires (the
|
||||||
|
// only parent->child signal available for a same-origin but
|
||||||
|
// externally-served page) this init() has already run. Query params
|
||||||
|
// are readable synchronously, before the "hide url params" cleanup
|
||||||
|
// below strips them - self.MESH_TOOL_CONFIG is still set from them
|
||||||
|
// here so util.download() (src/mesh/build.js) has one stable place to
|
||||||
|
// read from regardless of how config arrived.
|
||||||
|
const cmmsParams = new URLSearchParams(location.search);
|
||||||
|
const cmmsLoadUrl = cmmsParams.get('cmms_load');
|
||||||
|
if (cmmsLoadUrl) {
|
||||||
|
self.MESH_TOOL_CONFIG = {
|
||||||
|
loadUrl: cmmsLoadUrl,
|
||||||
|
saveUrl: cmmsParams.get('cmms_save'),
|
||||||
|
ownerToken: cmmsParams.get('cmms_owner'),
|
||||||
|
csrfToken: cmmsParams.get('cmms_csrf'),
|
||||||
|
originalName: cmmsParams.get('cmms_name'),
|
||||||
|
};
|
||||||
motoClient.on('ready', () => cmms_load_from_url(self.MESH_TOOL_CONFIG));
|
motoClient.on('ready', () => cmms_load_from_url(self.MESH_TOOL_CONFIG));
|
||||||
} else {
|
} else {
|
||||||
// reload stored space when worker is ready
|
// reload stored space when worker is ready
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue