Commit 42ee0571 by Braden MacDonald Committed by E. Kolpakov

Read-only users get "Details" instead of "Edit" button, remove "Save" option

parent d38e69c6
...@@ -234,6 +234,7 @@ def xblock_view_handler(request, usage_key_string, view_name): ...@@ -234,6 +234,7 @@ def xblock_view_handler(request, usage_key_string, view_name):
elif view_name in (PREVIEW_VIEWS + container_views): elif view_name in (PREVIEW_VIEWS + container_views):
is_pages_view = view_name == STUDENT_VIEW # Only the "Pages" view uses student view in Studio is_pages_view = view_name == STUDENT_VIEW # Only the "Pages" view uses student view in Studio
can_edit = has_studio_write_access(request.user, usage_key.course_key)
# Determine the items to be shown as reorderable. Note that the view # Determine the items to be shown as reorderable. Note that the view
# 'reorderable_container_child_preview' is only rendered for xblocks that # 'reorderable_container_child_preview' is only rendered for xblocks that
...@@ -266,6 +267,7 @@ def xblock_view_handler(request, usage_key_string, view_name): ...@@ -266,6 +267,7 @@ def xblock_view_handler(request, usage_key_string, view_name):
context = { context = {
'is_pages_view': is_pages_view, # This setting disables the recursive wrapping of xblocks 'is_pages_view': is_pages_view, # This setting disables the recursive wrapping of xblocks
'is_unit_page': is_unit(xblock), 'is_unit_page': is_unit(xblock),
'can_edit': can_edit,
'root_xblock': xblock if (view_name == 'container_preview') else None, 'root_xblock': xblock if (view_name == 'container_preview') else None,
'reorderable_items': reorderable_items, 'reorderable_items': reorderable_items,
'paging': paging, 'paging': paging,
......
...@@ -226,6 +226,7 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False): ...@@ -226,6 +226,7 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False):
'content': frag.content, 'content': frag.content,
'is_root': is_root, 'is_root': is_root,
'is_reorderable': is_reorderable, 'is_reorderable': is_reorderable,
'can_edit': context.get('can_edit', True),
} }
html = render_to_string('studio_xblock_wrapper.html', template_context) html = render_to_string('studio_xblock_wrapper.html', template_context)
frag = wrap_fragment(frag, html) frag = wrap_fragment(frag, html)
......
...@@ -49,7 +49,7 @@ define(["jquery", "underscore", "js/common_helpers/ajax_helpers", "js/spec_helpe ...@@ -49,7 +49,7 @@ define(["jquery", "underscore", "js/common_helpers/ajax_helpers", "js/spec_helpe
var requests = AjaxHelpers.requests(this); var requests = AjaxHelpers.requests(this);
modal = showModal(requests, mockXBlockEditorHtml); modal = showModal(requests, mockXBlockEditorHtml);
expect(modal.$('.action-save')).not.toBeVisible(); expect(modal.$('.action-save')).not.toBeVisible();
expect(modal.$('.action-cancel').text()).toBe('OK'); expect(modal.$('.action-cancel').text()).toBe('Close');
}); });
it('shows the correct title', function() { it('shows the correct title', function() {
......
...@@ -65,7 +65,8 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie ...@@ -65,7 +65,8 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie
onDisplayXBlock: function() { onDisplayXBlock: function() {
var editorView = this.editorView, var editorView = this.editorView,
title = this.getTitle(); title = this.getTitle(),
readOnlyView = (this.editOptions && this.editOptions.readOnlyView) || !editorView.xblock.save;
// Notify the runtime that the modal has been shown // Notify the runtime that the modal has been shown
editorView.notifyRuntime('modal-shown', this); editorView.notifyRuntime('modal-shown', this);
...@@ -88,7 +89,7 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie ...@@ -88,7 +89,7 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie
// If the xblock is not using custom buttons then choose which buttons to show // If the xblock is not using custom buttons then choose which buttons to show
if (!editorView.hasCustomButtons()) { if (!editorView.hasCustomButtons()) {
// If the xblock does not support save then disable the save button // If the xblock does not support save then disable the save button
if (!editorView.xblock.save) { if (readOnlyView) {
this.disableSave(); this.disableSave();
} }
this.getActionBar().show(); this.getActionBar().show();
...@@ -101,8 +102,8 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie ...@@ -101,8 +102,8 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie
disableSave: function() { disableSave: function() {
var saveButton = this.getActionButton('save'), var saveButton = this.getActionButton('save'),
cancelButton = this.getActionButton('cancel'); cancelButton = this.getActionButton('cancel');
saveButton.hide(); saveButton.parent().hide();
cancelButton.text(gettext('OK')); cancelButton.text(gettext('Close'));
cancelButton.addClass('action-primary'); cancelButton.addClass('action-primary');
}, },
......
...@@ -53,7 +53,6 @@ define(["jquery", "underscore", "js/views/container", "js/utils/module", "gettex ...@@ -53,7 +53,6 @@ define(["jquery", "underscore", "js/views/container", "js/utils/module", "gettex
self.handleXBlockFragment(fragment, options); self.handleXBlockFragment(fragment, options);
self.processPaging({ requested_page: options.page_number }); self.processPaging({ requested_page: options.page_number });
self.page.renderAddXBlockComponents(); self.page.renderAddXBlockComponents();
self.page.updateBlockActions();
} }
}); });
}, },
......
...@@ -140,7 +140,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -140,7 +140,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
onXBlockRefresh: function(xblockView, block_added) { onXBlockRefresh: function(xblockView, block_added) {
this.xblockView.refresh(block_added); this.xblockView.refresh(block_added);
this.updateBlockActions();
// Update publish and last modified information from the server. // Update publish and last modified information from the server.
this.model.fetch(); this.model.fetch();
}, },
...@@ -161,12 +160,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -161,12 +160,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
} }
}, },
updateBlockActions: function() {
if (!this.options.canEdit) {
this.xblockView.$el.find('.action-duplicate, .action-delete, .action-drag').remove();
}
},
editXBlock: function(event) { editXBlock: function(event) {
var xblockElement = this.findXBlockElement(event.target), var xblockElement = this.findXBlockElement(event.target),
self = this, self = this,
...@@ -174,6 +167,7 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -174,6 +167,7 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
event.preventDefault(); event.preventDefault();
modal.edit(xblockElement, this.model, { modal.edit(xblockElement, this.model, {
readOnlyView: !this.options.canEdit,
refresh: function() { refresh: function() {
self.refreshXBlock(xblockElement, false); self.refreshXBlock(xblockElement, false);
} }
......
...@@ -55,31 +55,39 @@ messages = json.dumps(xblock.validate().to_json()) ...@@ -55,31 +55,39 @@ messages = json.dumps(xblock.validate().to_json())
<div class="header-actions"> <div class="header-actions">
<ul class="actions-list"> <ul class="actions-list">
% if not is_root: % if not is_root:
% if not show_inline: % if can_edit:
<li class="action-item action-edit"> % if not show_inline:
<a href="#" class="edit-button action-button"> <li class="action-item action-edit">
<i class="icon fa fa-pencil"></i> <a href="#" class="edit-button action-button">
<span class="action-button-text">${_("Edit")}</span> <i class="icon fa fa-pencil"></i>
<span class="action-button-text">${_("Edit")}</span>
</a>
</li>
<li class="action-item action-duplicate">
<a href="#" data-tooltip="${_("Duplicate")}" class="duplicate-button action-button">
<i class="icon fa fa-copy"></i>
<span class="sr">${_("Duplicate")}</span>
</a>
</li>
% endif
<li class="action-item action-delete">
<a href="#" data-tooltip="${_("Delete")}" class="delete-button action-button">
<i class="icon fa fa-trash-o"></i>
<span class="sr">${_("Delete")}</span>
</a> </a>
</li> </li>
<li class="action-item action-duplicate"> % if is_reorderable:
<a href="#" data-tooltip="${_("Duplicate")}" class="duplicate-button action-button"> <li class="action-item action-drag">
<i class="icon fa fa-copy"></i> <span data-tooltip="${_('Drag to reorder')}" class="drag-handle action"></span>
<span class="sr">${_("Duplicate")}</span> </li>
% endif
% elif not show_inline:
<li class="action-item action-edit action-edit-view-only">
<a href="#" class="edit-button action-button">
<span class="action-button-text">${_("Details")}</span>
</a> </a>
</li> </li>
% endif % endif
<li class="action-item action-delete">
<a href="#" data-tooltip="${_("Delete")}" class="delete-button action-button">
<i class="icon fa fa-trash-o"></i>
<span class="sr">${_("Delete")}</span>
</a>
</li>
% if is_reorderable:
<li class="action-item action-drag">
<span data-tooltip="${_('Drag to reorder')}" class="drag-handle action"></span>
</li>
% endif
% endif % endif
</ul> </ul>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment