Skip to content

Commit e930bc6

Browse files
authored
feat: Changes in xblock_v2 to support studio_view [FC-0076] (#36029)
Updates to support studio_view (editors) in xblock_v2 iframe. - Send a message when cancel button is clicked on xblock_v2 iframe only in studio_view - Send a message when save.end event is notified on xblock_v2 iframe. - Send notify function in runtime. This is to avoid errors when saving the Xblock
1 parent 8aeaaf4 commit e930bc6

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

common/templates/xblock_v2/xblock_iframe.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@
215215
}
216216
return url;
217217
},
218+
notify: (eventName, data) => {
219+
/**
220+
* Used in `studio_view` to notify events and errors
221+
**/
222+
window.parent.postMessage({
223+
type: 'xblock-event',
224+
eventName,
225+
data,
226+
}, '*');
227+
}
218228
};
219229

220230
/**
@@ -258,6 +268,25 @@
258268
const blockJS = { element };
259269
callback(blockJS);
260270
}
271+
272+
if ('{{ view_name | safe }}' === 'studio_view') {
273+
// Used when rendering the `studio_view`, in order to avoid open a new tab on click cancel or save
274+
const selectors = [
275+
'.cancel-button',
276+
'.save-button',
277+
'.action-cancel',
278+
'.action-save',
279+
];
280+
281+
for (const selector of selectors) {
282+
const queryObject = document.querySelector(selector);
283+
if (queryObject) {
284+
queryObject.addEventListener('click', function() {
285+
event.preventDefault();
286+
});
287+
}
288+
}
289+
}
261290
}
262291

263292
// Recursively initialize the JavaScript code of each XBlock:

openedx/core/djangoapps/xblock/rest_api/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def embed_block_view(request, usage_key: UsageKeyV2, view_name: str):
122122
'fragment': fragment,
123123
'handler_urls_json': json.dumps(handler_urls),
124124
'lms_root_url': lms_root_url,
125+
'view_name': view_name,
125126
'is_development': settings.DEBUG,
126127
}
127128
response = render(request, 'xblock_v2/xblock_iframe.html', context, content_type='text/html')
@@ -322,10 +323,6 @@ def post(self, request, usage_key, version: LatestVersion | int = LatestVersion.
322323
# Save after the callback so any changes made in the callback will get persisted.
323324
block.save()
324325

325-
# Signal that we've modified this block
326-
context_impl = get_learning_context_impl(usage_key)
327-
context_impl.send_block_updated_event(usage_key)
328-
329326
block_dict = {
330327
"id": str(block.usage_key),
331328
"display_name": get_block_display_name(block), # note this is also present in metadata

openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ def save_block(self, block):
314314
)
315315
self.authored_data_store.mark_unchanged(block)
316316

317+
# Signal that we've modified this block
318+
learning_context = get_learning_context_impl(usage_key)
319+
learning_context.send_block_updated_event(usage_key)
320+
317321
def _get_component_from_usage_key(self, usage_key):
318322
"""
319323
Note that Components aren't ever really truly deleted, so this will

0 commit comments

Comments
 (0)