From 0881037e3fca297d76cfe6c860dbb0e65bcf0d10 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Thu, 12 Dec 2024 14:49:04 +0100 Subject: [PATCH] sendMessageToIframe and sendCloseMessage --- .../source/class/osparc/data/model/Study.js | 11 ++++++++ .../source/class/osparc/vipMarket/Market.js | 12 +++++++++ .../class/osparc/vipMarket/MarketWindow.js | 5 ++++ .../class/osparc/vipMarket/VipMarket.js | 25 ++++++++----------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index e8929c93adf..af4b639cd44 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -635,6 +635,17 @@ qx.Class.define("osparc.data.model.Study", { return !this.getUi().getSlideshow().isEmpty(); }, + sendMessageToIframe: function(nodeId, msg) { + if (nodeId) { + const node = this.getWorkbench().getNode(nodeId); + if (node && node.getIFrame()) { + node.getIFrame().sendMessageToIframe(msg); + return true; + } + } + return false; + }, + patchStudy: function(studyChanges) { const matches = this.self().OwnPatch.filter(el => Object.keys(studyChanges).indexOf(el) !== -1); if (matches.length) { diff --git a/services/static-webserver/client/source/class/osparc/vipMarket/Market.js b/services/static-webserver/client/source/class/osparc/vipMarket/Market.js index 53d605635e2..dbffeefed8e 100644 --- a/services/static-webserver/client/source/class/osparc/vipMarket/Market.js +++ b/services/static-webserver/client/source/class/osparc/vipMarket/Market.js @@ -92,5 +92,17 @@ qx.Class.define("osparc.vipMarket.Market", { } return false; }, + + sendCloseMessage: function() { + const store = osparc.store.Store.getInstance(); + const currentStudy = store.getCurrentStudy(); + const nodeId = this.getOpenBy(); + if (currentStudy && nodeId) { + const msg = { + "type": "closeMarket", + }; + currentStudy.sendMessageToIframe(nodeId, msg); + } + }, } }); diff --git a/services/static-webserver/client/source/class/osparc/vipMarket/MarketWindow.js b/services/static-webserver/client/source/class/osparc/vipMarket/MarketWindow.js index 74a754693c2..c238f5618b8 100644 --- a/services/static-webserver/client/source/class/osparc/vipMarket/MarketWindow.js +++ b/services/static-webserver/client/source/class/osparc/vipMarket/MarketWindow.js @@ -41,6 +41,11 @@ qx.Class.define("osparc.vipMarket.MarketWindow", { if (osparc.product.Utils.showS4LStore()) { const storeWindow = new osparc.vipMarket.MarketWindow(nodeId, category); storeWindow.getVipMarket().addListener("importMessageSent", () => storeWindow.close()); + storeWindow.addListenerOnce("close", () => { + if (storeWindow.getVipMarket()) { + storeWindow.getVipMarket().sendCloseMessage(); + } + }); storeWindow.center(); storeWindow.open(); return storeWindow; diff --git a/services/static-webserver/client/source/class/osparc/vipMarket/VipMarket.js b/services/static-webserver/client/source/class/osparc/vipMarket/VipMarket.js index 605a4c67f55..f7a0125f3c0 100644 --- a/services/static-webserver/client/source/class/osparc/vipMarket/VipMarket.js +++ b/services/static-webserver/client/source/class/osparc/vipMarket/VipMarket.js @@ -361,22 +361,17 @@ qx.Class.define("osparc.vipMarket.VipMarket", { }, __sendImportModelMessage: function(modelId) { + const store = osparc.store.Store.getInstance(); + const currentStudy = store.getCurrentStudy(); const nodeId = this.getOpenBy(); - if (nodeId) { - const store = osparc.store.Store.getInstance(); - const currentStudy = store.getCurrentStudy(); - if (!currentStudy) { - return; - } - const node = currentStudy.getWorkbench().getNode(nodeId); - if (node && node.getIFrame()) { - const msg = { - "type": "importModel", - "message": { - "modelId": modelId, - }, - }; - node.getIFrame().sendMessageToIframe(msg); + if (currentStudy && nodeId) { + const msg = { + "type": "importModel", + "message": { + "modelId": modelId, + }, + }; + if (currentStudy.sendMessageToIframe(nodeId, msg)) { this.fireEvent("importMessageSent"); } }