mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-26 18:58:54 +02:00
Refine registered actions widget UI
- Use verbose labels (App | Model) for action group headers - Simplify template layout with h5 headers instead of cards - Consolidate Standard/Custom/Additional Actions into single Actions fieldset
This commit is contained in:
@@ -377,9 +377,10 @@ class ObjectPermissionForm(forms.ModelForm):
|
|||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('name', 'description', 'enabled'),
|
FieldSet('name', 'description', 'enabled'),
|
||||||
FieldSet('object_types', name=_('Objects')),
|
FieldSet('object_types', name=_('Objects')),
|
||||||
FieldSet('can_view', 'can_add', 'can_change', 'can_delete', name=_('Standard Actions')),
|
FieldSet(
|
||||||
FieldSet('registered_actions', name=_('Custom Actions')),
|
'can_view', 'can_add', 'can_change', 'can_delete', 'registered_actions', 'actions',
|
||||||
FieldSet('actions', name=_('Additional Actions')),
|
name=_('Actions')
|
||||||
|
),
|
||||||
FieldSet('groups', 'users', name=_('Assignment')),
|
FieldSet('groups', 'users', name=_('Assignment')),
|
||||||
FieldSet('constraints', name=_('Constraints')),
|
FieldSet('constraints', name=_('Constraints')),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.apps import apps
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'RegisteredActionsWidget',
|
'RegisteredActionsWidget',
|
||||||
@@ -18,6 +19,22 @@ class RegisteredActionsWidget(forms.CheckboxSelectMultiple):
|
|||||||
|
|
||||||
def get_context(self, name, value, attrs):
|
def get_context(self, name, value, attrs):
|
||||||
context = super().get_context(name, value, attrs)
|
context = super().get_context(name, value, attrs)
|
||||||
context['widget']['model_actions'] = self.model_actions
|
|
||||||
|
# Build model_actions with labels for v2 template
|
||||||
|
model_actions_with_labels = {}
|
||||||
|
for model_key, actions in self.model_actions.items():
|
||||||
|
app_label, model_name = model_key.split('.')
|
||||||
|
try:
|
||||||
|
model = apps.get_model(app_label, model_name)
|
||||||
|
app_config = apps.get_app_config(app_label)
|
||||||
|
label = f"{app_config.verbose_name} | {model._meta.verbose_name.title()}"
|
||||||
|
except LookupError:
|
||||||
|
label = model_key
|
||||||
|
model_actions_with_labels[model_key] = {
|
||||||
|
'label': label,
|
||||||
|
'actions': actions,
|
||||||
|
}
|
||||||
|
|
||||||
|
context['widget']['model_actions'] = model_actions_with_labels
|
||||||
context['widget']['value'] = value or []
|
context['widget']['value'] = value or []
|
||||||
return context
|
return context
|
||||||
|
|||||||
@@ -1,28 +1,24 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<div class="registered-actions-container" id="id_registered_actions_container">
|
<div class="registered-actions-container" id="id_registered_actions_container">
|
||||||
{% for model_key, actions in widget.model_actions.items %}
|
{% for model_key, model_data in widget.model_actions.items %}
|
||||||
<div class="model-actions card mb-2" data-model="{{ model_key }}" style="display: none;">
|
<div class="model-actions" data-model="{{ model_key }}" style="display: none;">
|
||||||
<div class="card-header py-2">
|
<h5 class="mb-2 mt-3">{{ model_data.label }}</h5>
|
||||||
<strong>{{ model_key }}</strong>
|
{% for action in model_data.actions %}
|
||||||
</div>
|
<div class="form-check">
|
||||||
<div class="card-body py-2">
|
<input type="checkbox"
|
||||||
{% for action in actions %}
|
class="form-check-input"
|
||||||
<div class="form-check">
|
name="{{ widget.name }}"
|
||||||
<input type="checkbox"
|
value="{{ model_key }}.{{ action.name }}"
|
||||||
class="form-check-input"
|
id="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}"
|
||||||
name="{{ widget.name }}"
|
{% if model_key|add:"."|add:action.name in widget.value %}checked{% endif %}>
|
||||||
value="{{ model_key }}.{{ action.name }}"
|
<label class="form-check-label" for="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}">
|
||||||
id="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}"
|
{{ action.name }}
|
||||||
{% if model_key|add:"."|add:action.name in widget.value %}checked{% endif %}>
|
{% if action.help_text %}
|
||||||
<label class="form-check-label" for="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}">
|
<small class="text-muted ms-1">{{ action.help_text }}</small>
|
||||||
{{ action.name }}
|
{% endif %}
|
||||||
{% if action.help_text %}
|
</label>
|
||||||
<small class="text-muted ms-1">{{ action.help_text }}</small>
|
</div>
|
||||||
{% endif %}
|
{% endfor %}
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<p class="text-muted" id="no-custom-actions-message">
|
<p class="text-muted" id="no-custom-actions-message">
|
||||||
|
|||||||
Reference in New Issue
Block a user