-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds Library Content (v2) button to Studio Unit page (#35670)
Requires that v2 libraries are enabled.
- Loading branch information
1 parent
e2d6765
commit 7e8fb43
Showing
16 changed files
with
220 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Provides utilities to open and close the library content picker. | ||
* | ||
*/ | ||
define(['jquery', 'underscore', 'gettext', 'js/views/modals/base_modal'], | ||
function($, _, gettext, BaseModal) { | ||
'use strict'; | ||
|
||
var AddLibraryContent = BaseModal.extend({ | ||
options: $.extend({}, BaseModal.prototype.options, { | ||
modalName: 'add-component-from-library', | ||
modalSize: 'lg', | ||
view: 'studio_view', | ||
viewSpecificClasses: 'modal-add-component-picker confirm', | ||
// Translators: "title" is the name of the current component being edited. | ||
titleFormat: gettext('Add library content'), | ||
addPrimaryActionButton: false, | ||
}), | ||
|
||
initialize: function() { | ||
BaseModal.prototype.initialize.call(this); | ||
// Add event listen to close picker when the iframe tells us to | ||
const handleMessage = (event) => { | ||
if (event.data?.type === 'pickerComponentSelected') { | ||
var requestData = { | ||
library_content_key: event.data.usageKey, | ||
category: event.data.category, | ||
} | ||
this.refreshFunction(requestData); | ||
this.hide(); | ||
} | ||
}; | ||
this.messageListener = window.addEventListener("message", handleMessage); | ||
this.cleanupListener = () => { window.removeEventListener("message", handleMessage) }; | ||
}, | ||
|
||
hide: function() { | ||
BaseModal.prototype.hide.call(this); | ||
this.cleanupListener(); | ||
}, | ||
|
||
/** | ||
* Adds the action buttons to the modal. | ||
*/ | ||
addActionButtons: function() { | ||
this.addActionButton('cancel', gettext('Cancel')); | ||
}, | ||
|
||
/** | ||
* Show a component picker modal from library. | ||
* @param contentPickerUrl Url for component picker | ||
* @param refreshFunction A function to refresh the block after it has been updated | ||
*/ | ||
showComponentPicker: function(contentPickerUrl, refreshFunction) { | ||
this.contentPickerUrl = contentPickerUrl; | ||
this.refreshFunction = refreshFunction; | ||
|
||
this.render(); | ||
this.show(); | ||
}, | ||
|
||
getContentHtml: function() { | ||
return `<iframe src="${this.contentPickerUrl}" onload="this.contentWindow.focus()" frameborder="0" style="width: 100%; height: 100%;"/>`; | ||
}, | ||
}); | ||
|
||
return AddLibraryContent; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.