From 661ecde10691a37e45d57511e9d10124f9772e42 Mon Sep 17 00:00:00 2001 From: ihor-romaniuk Date: Tue, 22 Oct 2024 12:53:45 +0200 Subject: [PATCH] feat: [FC-0070] add message events to the unit page container --- cms/static/js/views/pages/container.js | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index be7088746ff8..ed167d563489 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -128,6 +128,12 @@ function($, _, Backbone, gettext, BasePage, } + window.addEventListener('message', (event) => { + if (event.data && event.data.type === 'refreshXBlock') { + this.render(); + } + }); + this.listenTo(Backbone, 'move:onXBlockMoved', this.onXBlockMoved); }, @@ -625,26 +631,40 @@ function($, _, Backbone, gettext, BasePage, }, showMoveXBlockModal: function(event) { + var xblockElement = this.findXBlockElement(event.target), + parentXBlockElement = xblockElement.parents('.studio-xblock-wrapper'), + sourceXBlockInfo = XBlockUtils.findXBlockInfo(xblockElement, this.model), + sourceParentXBlockInfo = XBlockUtils.findXBlockInfo(parentXBlockElement, this.model), + modal = new MoveXBlockModal({ + sourceXBlockInfo: sourceXBlockInfo, + sourceParentXBlockInfo: sourceParentXBlockInfo, + XBlockURLRoot: this.getURLRoot(), + outlineURL: this.options.outlineURL + }); + try { if (this.options.isIframeEmbed) { window.parent.postMessage( { type: 'showMoveXBlockModal', - payload: {} + payload: { + sourceXBlockInfo: { + id: sourceXBlockInfo.attributes.id, + displayName: sourceXBlockInfo.attributes.display_name, + }, + sourceParentXBlockInfo: { + id: sourceParentXBlockInfo.attributes.id, + category: sourceParentXBlockInfo.attributes.category, + hasChildren: sourceParentXBlockInfo.attributes.has_children, + }, + }, }, document.referrer ); + return true; } } catch (e) { console.error(e); } - var xblockElement = this.findXBlockElement(event.target), - parentXBlockElement = xblockElement.parents('.studio-xblock-wrapper'), - modal = new MoveXBlockModal({ - sourceXBlockInfo: XBlockUtils.findXBlockInfo(xblockElement, this.model), - sourceParentXBlockInfo: XBlockUtils.findXBlockInfo(parentXBlockElement, this.model), - XBlockURLRoot: this.getURLRoot(), - outlineURL: this.options.outlineURL - }); event.preventDefault(); modal.show();