Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Changes in xblock_v2 to support studio_view [FC-0076] #36029

Merged
merged 11 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions common/templates/xblock_v2/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@
}
return url;
},
notify: (eventName, data) => {
/**
* Used in `studio_view` to notify events and errors
**/
if (eventName == 'save' && data.state == 'end') {
window.parent.postMessage('save-end', '*');
} else if (eventName == 'error') {
window.parent.postMessage('error', '*');
}
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved
}
};

/**
Expand Down Expand Up @@ -258,6 +268,14 @@
const blockJS = { element };
callback(blockJS);
}

if ('{{ view_name | safe }}' === 'studio_view') {
// Used when rendering the `studio_view`, in order to intercept and handle the cancel button event
document.querySelector('.cancel-button').addEventListener('click', function() {
event.preventDefault();
window.parent.postMessage('cancel-clicked', '*');
});
}
}

// Recursively initialize the JavaScript code of each XBlock:
Expand Down
7 changes: 7 additions & 0 deletions openedx/core/djangoapps/xblock/rest_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def embed_block_view(request, usage_key: UsageKeyV2, view_name: str):
'fragment': fragment,
'handler_urls_json': json.dumps(handler_urls),
'lms_root_url': lms_root_url,
'view_name': view_name,
'is_development': settings.DEBUG,
}
response = render(request, 'xblock_v2/xblock_iframe.html', context, content_type='text/html')
Expand Down Expand Up @@ -211,6 +212,12 @@ def xblock_handler(
block = load_block(usage_key, user, version=version)
# Run the handler, and save any resulting XBlock field value changes:
response_webob = block.handle(handler_name, request_webob, suffix)

if handler_name == "studio_submit":
# Signal that we've modified this block
context_impl = get_learning_context_impl(usage_key)
context_impl.send_block_updated_event(usage_key)
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved

response = webob_to_django_response(response_webob)
return response

Expand Down
Loading