feat: iframe messaging for component picker in problem bank (#35888)
This commit is contained in:
@@ -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) };
|
||||
@@ -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();
|
||||
|
||||
@@ -524,7 +524,7 @@ function($, _, Backbone, gettext, BasePage,
|
||||
ViewUtils.runOperationShowingMessage(gettext('Adding'), () => {
|
||||
return lastAdded.done(() => { doneAddingAllBlocks() });
|
||||
});
|
||||
});
|
||||
}, this.options.isIframeEmbed);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user