Skip to content

Commit

Permalink
feat: iframe messaging for component picker in problem bank (#35888)
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera authored Nov 22, 2024
1 parent e440405 commit 73ba58a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion cms/static/js/views/modals/select_v2_library_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function($, _, gettext, BaseModal) {
this.disableActionButton('add');
}
}
if (event.data?.type === 'addSelectedComponentsToBank') {
this.selections = event.data.payload.selectedComponents;
this.callback(this.selections);
}
};
this.messageListener = window.addEventListener("message", handleMessage);
this.cleanupListener = () => { window.removeEventListener("message", handleMessage) };
Expand Down Expand Up @@ -70,10 +74,20 @@ function($, _, gettext, BaseModal) {
* Show a component picker modal from library.
* @param contentPickerUrl Url for component picker
* @param callback A function to call with the selected block(s)
* @param isIframeEmbed Boolean indicating if the unit is displayed inside an iframe
*/
showComponentPicker: function(contentPickerUrl, callback) {
showComponentPicker: function(contentPickerUrl, callback, isIframeEmbed) {
this.contentPickerUrl = contentPickerUrl;
this.callback = callback;
if (isIframeEmbed) {
window.parent.postMessage(
{
type: 'showMultipleComponentPicker',
payload: {}
}, document.referrer
);
return true;
}

this.render();
this.show();
Expand Down
2 changes: 1 addition & 1 deletion cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ function($, _, Backbone, gettext, BasePage,
ViewUtils.runOperationShowingMessage(gettext('Adding'), () => {
return lastAdded.done(() => { doneAddingAllBlocks() });
});
});
}, this.options.isIframeEmbed);
},

/**
Expand Down

0 comments on commit 73ba58a

Please sign in to comment.