feat: iframe messaging for component picker in problem bank (#35888)

This commit is contained in:
Navin Karkera
2024-11-22 22:14:13 +05:30
committed by GitHub
parent e4404051c4
commit 73ba58ae11
2 changed files with 16 additions and 2 deletions

View File

@@ -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();

View File

@@ -524,7 +524,7 @@ function($, _, Backbone, gettext, BasePage,
ViewUtils.runOperationShowingMessage(gettext('Adding'), () => {
return lastAdded.done(() => { doneAddingAllBlocks() });
});
});
}, this.options.isIframeEmbed);
},
/**