From 42ee0571e75548d990be6dcaa7a37aec5775e609 Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Tue, 30 Dec 2014 21:15:42 -0800 Subject: [PATCH] Read-only users get "Details" instead of "Edit" button, remove "Save" option --- cms/djangoapps/contentstore/views/item.py | 2 + cms/djangoapps/contentstore/views/preview.py | 1 + .../js/spec/views/modals/edit_xblock_spec.js | 2 +- cms/static/js/views/modals/edit_xblock.js | 9 ++-- cms/static/js/views/paged_container.js | 1 - cms/static/js/views/pages/container.js | 8 +-- cms/templates/studio_xblock_wrapper.html | 50 +++++++++++-------- 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index a98a5cf193..d535cf11fb 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -234,6 +234,7 @@ def xblock_view_handler(request, usage_key_string, view_name): elif view_name in (PREVIEW_VIEWS + container_views): 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 # 'reorderable_container_child_preview' is only rendered for xblocks that @@ -266,6 +267,7 @@ def xblock_view_handler(request, usage_key_string, view_name): context = { 'is_pages_view': is_pages_view, # This setting disables the recursive wrapping of xblocks 'is_unit_page': is_unit(xblock), + 'can_edit': can_edit, 'root_xblock': xblock if (view_name == 'container_preview') else None, 'reorderable_items': reorderable_items, 'paging': paging, diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 523d8d1846..9f9aca8da1 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -226,6 +226,7 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False): 'content': frag.content, 'is_root': is_root, 'is_reorderable': is_reorderable, + 'can_edit': context.get('can_edit', True), } html = render_to_string('studio_xblock_wrapper.html', template_context) frag = wrap_fragment(frag, html) diff --git a/cms/static/js/spec/views/modals/edit_xblock_spec.js b/cms/static/js/spec/views/modals/edit_xblock_spec.js index 99de1404c8..b159998e7f 100644 --- a/cms/static/js/spec/views/modals/edit_xblock_spec.js +++ b/cms/static/js/spec/views/modals/edit_xblock_spec.js @@ -49,7 +49,7 @@ define(["jquery", "underscore", "js/common_helpers/ajax_helpers", "js/spec_helpe var requests = AjaxHelpers.requests(this); modal = showModal(requests, mockXBlockEditorHtml); 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() { diff --git a/cms/static/js/views/modals/edit_xblock.js b/cms/static/js/views/modals/edit_xblock.js index 67e9de6f88..ef2de588a0 100644 --- a/cms/static/js/views/modals/edit_xblock.js +++ b/cms/static/js/views/modals/edit_xblock.js @@ -65,7 +65,8 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie onDisplayXBlock: function() { 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 editorView.notifyRuntime('modal-shown', this); @@ -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 (!editorView.hasCustomButtons()) { // If the xblock does not support save then disable the save button - if (!editorView.xblock.save) { + if (readOnlyView) { this.disableSave(); } this.getActionBar().show(); @@ -101,8 +102,8 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "js/vie disableSave: function() { var saveButton = this.getActionButton('save'), cancelButton = this.getActionButton('cancel'); - saveButton.hide(); - cancelButton.text(gettext('OK')); + saveButton.parent().hide(); + cancelButton.text(gettext('Close')); cancelButton.addClass('action-primary'); }, diff --git a/cms/static/js/views/paged_container.js b/cms/static/js/views/paged_container.js index 4b300843b5..c2b97f3b54 100644 --- a/cms/static/js/views/paged_container.js +++ b/cms/static/js/views/paged_container.js @@ -53,7 +53,6 @@ define(["jquery", "underscore", "js/views/container", "js/utils/module", "gettex self.handleXBlockFragment(fragment, options); self.processPaging({ requested_page: options.page_number }); self.page.renderAddXBlockComponents(); - self.page.updateBlockActions(); } }); }, diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index 018b03fe8f..cea6c43120 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -140,7 +140,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views onXBlockRefresh: function(xblockView, block_added) { this.xblockView.refresh(block_added); - this.updateBlockActions(); // Update publish and last modified information from the server. this.model.fetch(); }, @@ -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) { var xblockElement = this.findXBlockElement(event.target), self = this, @@ -174,6 +167,7 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views event.preventDefault(); modal.edit(xblockElement, this.model, { + readOnlyView: !this.options.canEdit, refresh: function() { self.refreshXBlock(xblockElement, false); } diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index 914f8ec6e0..44ec7298fa 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -55,30 +55,38 @@ messages = json.dumps(xblock.validate().to_json())