Skip to content

Commit

Permalink
feat: [FC-0070] add message events to the unit page container
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-romaniuk committed Nov 15, 2024
1 parent 3e43e33 commit 6f65bcf
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ function($, _, Backbone, gettext, BasePage,

}

if (this.options.isIframeEmbed) {
window.addEventListener('message', (event) => {
if (event.data && event.data.type === 'refreshXBlock') {
this.render();
}
});
}

this.listenTo(Backbone, 'move:onXBlockMoved', this.onXBlockMoved);
},

Expand Down Expand Up @@ -625,26 +633,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();
Expand Down

0 comments on commit 6f65bcf

Please sign in to comment.