-
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: implement V2 libraries usage for library content block
YT: https://youtrack.raccoongang.com/issue/EDX_BLND_CLI-87 - V2 libraries are available for selection in the Random Block edit modal; - selected V2 library blocks are copied to the modulestore and saved as children of the Random Block; - V2 library version validation works the same as for the V1 libraries (with possibility to update block with the latest version); - filtering by problem type can't be done for V2 the same as for V1 because the v2 library problems are not divided by types; - the problem type field is hidden for v2 libraries in the edit mode; - unit tests added/updated.
- Loading branch information
Showing
6 changed files
with
349 additions
and
82 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
xmodule/assets/library_content/public/js/library_content_edit_helpers.js
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,54 @@ | ||
/* JavaScript for special editing operations that can be done on LibraryContentXBlock */ | ||
// This is a temporary UI improvements that will be removed when V2 content libraries became | ||
// fully functional | ||
|
||
/** | ||
* Toggle the "Problem Type" settings section depending on selected library type. | ||
* As for now, the V2 libraries don't support different problem types, so they can't be | ||
* filtered by it. We're hiding the Problem Type field for them. | ||
*/ | ||
function checkProblemTypeShouldBeVisible(editor) { | ||
var libraries = editor.find('.wrapper-comp-settings.metadata_edit.is-active') | ||
.data().metadata.source_library_id.options; | ||
var selectedIndex = $("select[name='Library']", editor)[0].selectedIndex; | ||
var libraryKey = libraries[selectedIndex].value; | ||
var url = URI('/xblock') | ||
.segment(editor.find('.xblock.xblock-studio_view.xblock-studio_view-library_content.xblock-initialized') | ||
.data('usage-id')) | ||
.segment('handler') | ||
.segment('is_v2_library'); | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
url: url, | ||
data: JSON.stringify({'library_key': libraryKey}), | ||
success: function(data) { | ||
var problemTypeSelect = editor.find("select[name='Problem Type']") | ||
.parents("li.field.comp-setting-entry.metadata_entry"); | ||
data.is_v2 ? problemTypeSelect.hide() : problemTypeSelect.show(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Waits untill editor html loaded, than calls checks for Program Type field toggling. | ||
*/ | ||
function waitForEditorLoading() { | ||
var checkContent = setInterval(function() { | ||
var $modal = $('.xblock-editor'); | ||
var content = $modal.html(); | ||
if (content) { | ||
clearInterval(checkContent); | ||
checkProblemTypeShouldBeVisible($modal); | ||
} | ||
}, 10); | ||
} | ||
// Initial call | ||
waitForEditorLoading(); | ||
|
||
var $librarySelect = $("select[name='Library']"); | ||
$(document).on('change', $librarySelect, waitForEditorLoading) | ||
|
||
var $libraryContentEditors = $('.xblock-header.xblock-header-library_content'); | ||
var $editBtns = $libraryContentEditors.find('.action-item.action-edit'); | ||
$(document).on('click', $editBtns, waitForEditorLoading) |
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.