mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-13 22:07:17 +01: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 = (
|
||||
FieldSet('name', 'description', 'enabled'),
|
||||
FieldSet('object_types', name=_('Objects')),
|
||||
FieldSet('can_view', 'can_add', 'can_change', 'can_delete', name=_('Standard Actions')),
|
||||
FieldSet('registered_actions', name=_('Custom Actions')),
|
||||
FieldSet('actions', name=_('Additional Actions')),
|
||||
FieldSet(
|
||||
'can_view', 'can_add', 'can_change', 'can_delete', 'registered_actions', 'actions',
|
||||
name=_('Actions')
|
||||
),
|
||||
FieldSet('groups', 'users', name=_('Assignment')),
|
||||
FieldSet('constraints', name=_('Constraints')),
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.apps import apps
|
||||
|
||||
__all__ = (
|
||||
'RegisteredActionsWidget',
|
||||
@@ -18,6 +19,22 @@ class RegisteredActionsWidget(forms.CheckboxSelectMultiple):
|
||||
|
||||
def get_context(self, 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 []
|
||||
return context
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
{% load i18n %}
|
||||
<div class="registered-actions-container" id="id_registered_actions_container">
|
||||
{% for model_key, actions in widget.model_actions.items %}
|
||||
<div class="model-actions card mb-2" data-model="{{ model_key }}" style="display: none;">
|
||||
<div class="card-header py-2">
|
||||
<strong>{{ model_key }}</strong>
|
||||
</div>
|
||||
<div class="card-body py-2">
|
||||
{% for action in actions %}
|
||||
<div class="form-check">
|
||||
<input type="checkbox"
|
||||
class="form-check-input"
|
||||
name="{{ widget.name }}"
|
||||
value="{{ model_key }}.{{ action.name }}"
|
||||
id="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}"
|
||||
{% if model_key|add:"."|add:action.name in widget.value %}checked{% endif %}>
|
||||
<label class="form-check-label" for="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}">
|
||||
{{ action.name }}
|
||||
{% if action.help_text %}
|
||||
<small class="text-muted ms-1">{{ action.help_text }}</small>
|
||||
{% endif %}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% for model_key, model_data in widget.model_actions.items %}
|
||||
<div class="model-actions" data-model="{{ model_key }}" style="display: none;">
|
||||
<h5 class="mb-2 mt-3">{{ model_data.label }}</h5>
|
||||
{% for action in model_data.actions %}
|
||||
<div class="form-check">
|
||||
<input type="checkbox"
|
||||
class="form-check-input"
|
||||
name="{{ widget.name }}"
|
||||
value="{{ model_key }}.{{ action.name }}"
|
||||
id="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}"
|
||||
{% if model_key|add:"."|add:action.name in widget.value %}checked{% endif %}>
|
||||
<label class="form-check-label" for="id_{{ widget.name }}_{{ forloop.parentloop.counter }}_{{ forloop.counter }}">
|
||||
{{ action.name }}
|
||||
{% if action.help_text %}
|
||||
<small class="text-muted ms-1">{{ action.help_text }}</small>
|
||||
{% endif %}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% empty %}
|
||||
<p class="text-muted" id="no-custom-actions-message">
|
||||
|
||||
Reference in New Issue
Block a user