From f2fc1c3c43a5a22021fac5640c851fecbf0de599 Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Thu, 4 Apr 2024 12:44:31 +0300 Subject: [PATCH] refactor: container_editor template refactoring --- cms/templates/container_editor.html | 507 +++++++++++++--------------- 1 file changed, 241 insertions(+), 266 deletions(-) diff --git a/cms/templates/container_editor.html b/cms/templates/container_editor.html index c091e2500f48..b8f2403ad16c 100644 --- a/cms/templates/container_editor.html +++ b/cms/templates/container_editor.html @@ -1,4 +1,3 @@ - ## coding=utf-8 ## mako @@ -10,7 +9,6 @@ <%namespace name='static' file='static_content.html'/> <%! from django.utils.translation import gettext as _ - from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES from lms.djangoapps.branding import api as branding_api from openedx.core.djangoapps.util.user_messages import PageLevelMessages @@ -29,7 +27,6 @@ <%! from django.urls import reverse from django.utils.translation import gettext as _ - from cms.djangoapps.contentstore.helpers import xblock_studio_url, xblock_type_display_name from openedx.core.djangolib.js_utils import ( dump_js_escaped_json, js_escaped_string @@ -41,297 +38,275 @@ - - - - - - <%block name="title"> -${xblock.display_name_with_default} ${xblock_type_display_name(xblock)} - </%block> | - % if context_course: - <% ctx_loc = context_course.location %> - ${context_course.display_name_with_default} | - % elif context_library: - ${context_library.display_name_with_default} | - % endif - ${settings.STUDIO_NAME} - - - - <% - jsi18n_path = "js/i18n/{language}/djangojs.js".format(language=LANGUAGE_CODE) - %> - - % if getattr(settings, 'CAPTURE_CONSOLE_LOG', False): - + % endif - var messages = JSON.parse(window.localStorage.getItem('console_log_capture')); - messages.push([message, url, lineno, colno, (error || {}).stack]); - window.localStorage.setItem('console_log_capture', JSON.stringify(messages)); + + % if settings.DEBUG: + ## Provides a fallback for gettext functions in development environment + + % endif + + + <%block name="header_meta"> + <% favicon_url = branding_api.get_favicon_url() %> + + <%static:css group='style-vendor'/> + <%static:css group='style-vendor-tinymce-content'/> + <%static:css group='style-vendor-tinymce-skin'/> + - - % if uses_bootstrap: - - % else: - <%static:css group='${self.attr.main_css}'/> - % endif - - <%include file="widgets/segment-io.html" /> - - <%block name="header_extras"> + -% for template_name in templates: - -% endfor - - -% if not settings.STUDIO_FRONTEND_CONTAINER_URL: - - -% endif - - - - - - - - <%block name="view_notes"> - - ${_("Skip to main content")} - - <%static:js group='base_vendor'/> - - <%static:webpack entry="commons"/> - - - - - - -
- <% - banner_messages = list(PageLevelMessages.user_messages(request)) - %> - -
-
- <%block name="content"> - - - - - - + <%include file="widgets/segment-io.html" /> + <%block name="header_extras"> + % for template_name in templates: + + % endfor + + + % if not settings.STUDIO_FRONTEND_CONTAINER_URL: + + + % endif -
-
- + + + + + <%block name="view_notes"> + ${_("Skip to main content")} + <%static:js group='base_vendor'/> + <%static:webpack entry="commons"/> + + + +
+ <% + banner_messages = list(PageLevelMessages.user_messages(request)) + %> +
+
+ <%block name="content"> + + + + + + +
+
- <%block name="modal_placeholder"> - <%block name="jsextra"> % if context_course: - <%static:webpack entry="js/factories/context_course"/> - + <%static:webpack entry="js/factories/context_course"/> + % endif + % if user.is_authenticated: - <%static:webpack entry='js/sock'/> + <%static:webpack entry='js/sock'/> % endif - <%block name='page_bundle'> - - <%static:webpack entry="js/factories/container"> - ContainerFactory( - ${component_templates | n, dump_js_escaped_json}, - ${xblock_info | n, dump_js_escaped_json}, - "${action | n, js_escaped_string}", - { - isUnitPage: ${is_unit_page | n, dump_js_escaped_json}, - canEdit: true, - outlineURL: "${outline_url | n, js_escaped_string}", - clipboardData: ${user_clipboard | n, dump_js_escaped_json}, - } - ); - require(["js/models/xblock_info", "js/views/xblock", "js/views/utils/xblock_utils", "common/js/components/utils/view_utils", "gettext"], function (XBlockInfo, XBlockView, XBlockUtils, ViewUtils, gettext) { - var model = new XBlockInfo({ - id: '${subsection.location|n, decode.utf8}' - }); - var xblockView = new XBlockView({ - model: model, - el: $('#sequence-nav'), - view: 'author_view?position=${position|n, decode.utf8}&next_url=${next_url|n, decode.utf8}&prev_url=${prev_url|n, decode.utf8}', - clipboardData: ${user_clipboard | n, dump_js_escaped_json}, + <%block name='page_bundle'> + + <%static:webpack entry="js/factories/container"> + ContainerFactory( + ${component_templates | n, dump_js_escaped_json}, + ${xblock_info | n, dump_js_escaped_json}, + '${action | n, js_escaped_string}', + { + isUnitPage: ${is_unit_page | n, dump_js_escaped_json}, + canEdit: true, + outlineURL: '${outline_url | n, js_escaped_string}', + clipboardData: ${user_clipboard | n, dump_js_escaped_json}, + } + ); + + require(['js/models/xblock_info', 'js/views/xblock', 'js/views/utils/xblock_utils', 'common/js/components/utils/view_utils', 'gettext'], function (XBlockInfo, XBlockView, XBlockUtils, ViewUtils, gettext) { + var model = new XBlockInfo({ id: '${subsection.location|n, decode.utf8}' }); + var xblockView = new XBlockView({ + model: model, + el: $('#sequence-nav'), + view: 'author_view?position=${position|n, decode.utf8}&next_url=${next_url|n, decode.utf8}&prev_url=${prev_url|n, decode.utf8}', + clipboardData: ${user_clipboard | n, dump_js_escaped_json}, + }); - xblockView.xblockReady = function() { - - var toggleCaretButton = function(clipboardData) { - if (clipboardData && clipboardData.content && clipboardData.source_usage_key.includes("vertical")) { - $('.dropdown-toggle-button').show(); - } else { - $('.dropdown-toggle-button').hide(); - $('.dropdown-options').hide(); - } - }; - this.clipboardBroadcastChannel = new BroadcastChannel("studio_clipboard_channel"); - this.clipboardBroadcastChannel.onmessage = (event) => { - toggleCaretButton(event.data); - }; - toggleCaretButton(this.options.clipboardData); - - $('#new-unit-button').on('click', function(event) { - event.preventDefault(); - XBlockUtils.addXBlock($(this)).done(function(locator) { - ViewUtils.redirect('/container/' + locator + '?action=new'); + xblockView.xblockReady = function() { + var toggleCaretButton = function(clipboardData) { + if (clipboardData && clipboardData.content && clipboardData.source_usage_key.includes('vertical')) { + $('.dropdown-toggle-button').show(); + } else { + $('.dropdown-toggle-button').hide(); + $('.dropdown-options').hide(); + } + }; + this.clipboardBroadcastChannel = new BroadcastChannel('studio_clipboard_channel'); + this.clipboardBroadcastChannel.onmessage = (event) => toggleCaretButton(event.data); + toggleCaretButton(this.options.clipboardData); + + $('#new-unit-button').on('click', function(event) { + event.preventDefault(); + XBlockUtils.addXBlock($(this)).done(function(locator) { + ViewUtils.redirect('/container/' + locator + '?action=new'); + }); }); - }); - $('.custom-dropdown .dropdown-toggle-button').on('click', function(event) { - event.stopPropagation(); // Prevent the event from closing immediately when we open it - $(this).next('.dropdown-options').slideToggle('fast'); // This toggles the dropdown visibility - var isExpanded = $(this).attr('aria-expanded') === 'true'; - $(this).attr('aria-expanded', !isExpanded); - }); + $('.custom-dropdown .dropdown-toggle-button').on('click', function(event) { + event.stopPropagation(); // Prevent the event from closing immediately when we open it + $(this).next('.dropdown-options').slideToggle('fast'); // This toggles the dropdown visibility + var isExpanded = $(this).attr('aria-expanded') === 'true'; + $(this).attr('aria-expanded', !isExpanded); + }); - $('.seq_paste_unit').on('click', function(event) { - event.preventDefault(); - $('.dropdown-options').hide(); - XBlockUtils.pasteXBlock($(this)).done(function(data) { - ViewUtils.redirect('/container/' + data.locator + '?action=new'); + $('.seq_paste_unit').on('click', function(event) { + event.preventDefault(); + $('.dropdown-options').hide(); + XBlockUtils.pasteXBlock($(this)).done(function(data) { + ViewUtils.redirect('/container/' + data.locator + '?action=new'); + }); }); - }); - }; + }; - xblockView.render(); - }); - + xblockView.render(); + }); + + - -