Skip to content

Commit

Permalink
Hide a few useless UI elements when in readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed May 2, 2024
1 parent 62c6636 commit 8253af2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions content_editor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ class ContentEditor(ModelAdmin):

def _content_editor_context(self, request, context):
instance = context.get("original")
show_plugins = True
allow_change = True
if instance is None:
instance = self.model()
else:
show_plugins = self.has_change_permission(request, instance)
allow_change = self.has_change_permission(request, instance)

plugins = []
adding_not_allowed = ["_adding_not_allowed"]
Expand All @@ -142,7 +142,7 @@ def _content_editor_context(self, request, context):
if callable(iaf.opts.regions)
else iaf.opts.regions
)
if show_plugins and iaf.opts.has_add_permission(request, instance)
if allow_change and iaf.opts.has_add_permission(request, instance)
else adding_not_allowed
)
plugins.append(
Expand All @@ -167,6 +167,7 @@ def _content_editor_context(self, request, context):
{
"plugins": plugins,
"regions": regions,
"allowChange": allow_change,
"messages": {
"createNew": gettext("Add new item"),
"empty": gettext("No items."),
Expand Down
10 changes: 8 additions & 2 deletions content_editor/static/content_editor/content_editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ html {
}

.order-machine-wrapper.collapsed {
--control-width: 10px;
--control-width: 20px;
}

@media (min-width: 1024px) {
Expand All @@ -67,7 +67,7 @@ html {
}

.order-machine {
padding: 0 10px 20px 10px;
padding: 0 10px 10px 10px;
border: 1px solid var(--hairline-color, #e8e8e8);
position: relative;

Expand Down Expand Up @@ -408,6 +408,12 @@ h3[draggable] {
}
}

.order-machine-readonly .plugin-buttons + p,
.order-machine-readonly + .order-machine-help,
.order-machine-readonly .inline-related > h3[draggable]::before {
display: none;
}

/* =====| OVERRIDES |===== */

/* JAZZMIN start */
Expand Down
4 changes: 4 additions & 0 deletions content_editor/static/content_editor/content_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,5 +740,9 @@ django.jQuery(function ($) {
`
document.head.appendChild(style)

if (!ContentEditor.allowChange) {
$(".order-machine-wrapper").addClass("order-machine-readonly")
}

$(document).trigger("content-editor:ready")
})

0 comments on commit 8253af2

Please sign in to comment.