From c9dce91b9a4e8b93d15aef84e9fa456b77eefee9 Mon Sep 17 00:00:00 2001 From: connorhaugh <49422820+connorhaugh@users.noreply.github.com> Date: Tue, 7 Jun 2022 16:30:40 -0400 Subject: [PATCH] feat: studio redirect to new editors (#30523) --- cms/static/js/views/pages/container.js | 27 +++++++++++++++---- cms/templates/studio_xblock_wrapper.html | 14 +++++----- .../xmodule/xmodule/templates/html/raw.yaml | 1 - 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index 286111e7f0..347f7ea77b 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -187,15 +187,15 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page event.preventDefault(); if(!options || options.view !== 'visibility_view' ){ - var useNewTextEditor = this.$('.edit-button').attr("use-new-editor-text"), - useNewVideoEditor = this.$('.edit-button').attr("use-new-editor-video"), - useNewProblemEditor = this.$('.edit-button').attr("use-new-editor-problem"), - blockType = xblockElement.find('.xblock').attr("data-block-type"); + var useNewTextEditor = this.$('.xblock-header-primary').attr("use-new-editor-text"), + useNewVideoEditor = this.$('.xblock-header-primary').attr("use-new-editor-video"), + useNewProblemEditor = this.$('.xblock-header-primary').attr("use-new-editor-problem"), + blockType = xblockElement.find('.xblock').attr("data-block-type"); if( (useNewTextEditor === "True" && blockType === "html") || (useNewVideoEditor === "True" && blockType === "video") || (useNewProblemEditor === "True" && blockType === "problem") ) { - var destinationUrl = this.$('.edit-button').attr("authoring_MFE_base_url") + '/' + blockType + '/' + encodeURI(xblockElement.find('.xblock').attr("data-usage-id")); + var destinationUrl = this.$('.xblock-header-primary').attr("authoring_MFE_base_url") + '/' + blockType + '/' + encodeURI(xblockElement.find('.xblock').attr("data-usage-id")); window.location.href = destinationUrl; return; } @@ -322,6 +322,23 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page }, onNewXBlock: function(xblockElement, scrollOffset, is_duplicate, data) { + var useNewTextEditor = this.$('.xblock-header-primary').attr("use-new-editor-text"), + useNewVideoEditor = this.$('.xblock-header-primary').attr("use-new-editor-video"), + useNewProblemEditor = this.$('.xblock-header-primary').attr("use-new-editor-problem"); + + //find the block type in the locator if availible + if(data.hasOwnProperty('locator')){ + var matchBlockTypeFromLocator = /\@(.*?)\+/; + var blockType = data.locator.match(matchBlockTypeFromLocator); + } + if((useNewTextEditor === "True" && blockType.includes("html")) || + (useNewVideoEditor === "True" && blockType.includes("video"))|| + (useNewProblemEditor === "True" && blockType.includes("problem")) + ){ + var destinationUrl = this.$('.xblock-header-primary').attr("authoring_MFE_base_url") + '/' + blockType[1] + '/' + encodeURI(data.locator); + window.location.href = destinationUrl; + return; + } ViewUtils.setScrollOffset(xblockElement, scrollOffset); xblockElement.data('locator', data.locator); return this.refreshXBlock(xblockElement, true, is_duplicate); diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index 15a2d3a857..2194a5e2f0 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -59,7 +59,12 @@ block_is_unit = is_unit(xblock) % if not show_preview: is-collapsed % endif - "> + " + use-new-editor-text = ${use_new_editor_text} + use-new-editor-video = ${use_new_editor_video} + use-new-editor-problem = ${use_new_editor_problem} + authoring_MFE_base_url = ${get_editor_page_base_url(xblock.location.course_key)} + >