Skip to content

Commit

Permalink
refactor: some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 5, 2024
1 parent a5b3b19 commit b64202e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
14 changes: 6 additions & 8 deletions cms/djangoapps/contentstore/views/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,24 @@ def xblock_view_handler(request, usage_key_string, view_name):


@xframe_options_exempt
@require_http_methods("GET")
@require_http_methods(["GET"])
@login_required
def xblock_actions_view(request, usage_key_string, action_name):
def xblock_edit_view(request, usage_key_string):
"""
Return rendered xblock action view.
The action name should be provided as an argument.
Valid options for action names are edit and move.
Return rendered xblock edit view.
Allows editing of an XBlock specified by the usage key.
"""
usage_key = usage_key_with_run(usage_key_string)
if not has_studio_read_access(request.user, usage_key.course_key):
raise PermissionDenied()
if action_name not in ['edit', 'move']:
return HttpResponse(status=404)

store = modulestore()

with store.bulk_operations(usage_key.course_key):
course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key)
container_handler_context = get_container_handler_context(request, usage_key, course, xblock)
container_handler_context.update({'action_name': action_name})
container_handler_context.update({'action_name': 'edit'})
return render_to_response('container_editor.html', container_handler_context)


Expand Down
23 changes: 4 additions & 19 deletions cms/static/js/views/utils/move_xblock_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,9 @@ function($, _, Backbone, Feedback, AlertView, XBlockViewUtils, MoveXBlockUtils,
// hide modal
Backbone.trigger('move:hideMoveModal');
if (data.sourceXBlockElement) {
// hide xblock element
data.sourceXBlockElement.hide();
// hide xblock element
data.sourceXBlockElement.hide();
}

window.parent.postMessage({
method: 'move_xblock',
msg: 'Sends a message when the xblock is moved',
params: {
sourceDisplayName: data.sourceDisplayName,
sourceLocator: data.sourceLocator,
targetParentLocator: data.targetParentLocator,
}
}, '*');
window.parent.postMessage({
method: 'close_modal',
msg: 'Sends a message when the modal window is closed'
}, '*');

showMovedNotification(
StringUtils.interpolate(
gettext('Success! "{displayName}" has been moved.'),
Expand All @@ -53,7 +38,7 @@ function($, _, Backbone, Feedback, AlertView, XBlockViewUtils, MoveXBlockUtils,
}
),
{
sourceXBlockElement: data.sourceXBlockElement ? data.sourceXBlockElement : null,
sourceXBlockElement: data.sourceXBlockElement,
sourceDisplayName: data.sourceDisplayName,
sourceLocator: data.sourceLocator,
sourceParentLocator: data.sourceParentLocator,
Expand Down Expand Up @@ -95,7 +80,7 @@ function($, _, Backbone, Feedback, AlertView, XBlockViewUtils, MoveXBlockUtils,
click: function() {
undoMoveXBlock(
{
sourceXBlockElement: data.sourceXBlockElement ? data.sourceXBlockElement : null,
sourceXBlockElement: data.sourceXBlockElement,
sourceDisplayName: data.sourceDisplayName,
sourceLocator: data.sourceLocator,
sourceParentLocator: data.sourceParentLocator,
Expand Down
4 changes: 2 additions & 2 deletions cms/static/sass/course-unit-mfe-iframe-bundle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ html body {
@extend %button-styles;

position: relative;
top: 7px;
top: -7px;

.fa-pencil {
display: none;
Expand Down Expand Up @@ -450,7 +450,7 @@ html body {
@extend %primary-button;
}

.wrapper-comp-settings {
div.wrapper-comp-settings {
.list-input.settings-list {
.metadata-list-enum .create-setting {
@extend %modal-actions-button;
Expand Down
6 changes: 3 additions & 3 deletions cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import openedx.core.djangoapps.lang_pref.views
from cms.djangoapps.contentstore import toggles
from cms.djangoapps.contentstore import views as contentstore_views
from cms.djangoapps.contentstore.views.block import xblock_actions_view
from cms.djangoapps.contentstore.views.block import xblock_edit_view
from cms.djangoapps.contentstore.views.organization import OrganizationListView
from openedx.core.apidocs import api_info
from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance
Expand Down Expand Up @@ -151,8 +151,8 @@
name='xblock_outline_handler'),
re_path(fr'^xblock/container/{settings.USAGE_KEY_PATTERN}$', contentstore_views.xblock_container_handler,
name='xblock_container_handler'),
re_path(fr'^xblock/{settings.USAGE_KEY_PATTERN}/actions/(?P<action_name>[^/]+)$', xblock_actions_view,
name='xblock_actions_handler'),
re_path(fr'^xblock/{settings.USAGE_KEY_PATTERN}/action/edit$', xblock_edit_view,
name='xblock_edit_handler'),
re_path(fr'^xblock/{settings.USAGE_KEY_PATTERN}/(?P<view_name>[^/]+)$', contentstore_views.xblock_view_handler,
name='xblock_view_handler'),
re_path(fr'^xblock/{settings.USAGE_KEY_PATTERN}?$', contentstore_views.xblock_handler,
Expand Down

0 comments on commit b64202e

Please sign in to comment.