mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 20:06:25 -06:00
Misc cleanup
This commit is contained in:
parent
284cf8f82c
commit
06705595b6
@ -51,6 +51,7 @@ class ProviderAccountForm(NetBoxModelForm):
|
|||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
|
selector=True,
|
||||||
quick_add=True
|
quick_add=True
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
comments = CommentField()
|
||||||
@ -66,6 +67,7 @@ class ProviderNetworkForm(NetBoxModelForm):
|
|||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
|
selector=True,
|
||||||
quick_add=True
|
quick_add=True
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
comments = CommentField()
|
||||||
|
@ -239,6 +239,8 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
|||||||
'form': form,
|
'form': form,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If the form is being displayed within a "quick add" widget,
|
||||||
|
# use the appropriate template
|
||||||
if request.GET.get('_quickadd'):
|
if request.GET.get('_quickadd'):
|
||||||
return render(request, 'htmx/quick_add.html', context)
|
return render(request, 'htmx/quick_add.html', context)
|
||||||
|
|
||||||
@ -262,6 +264,7 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
|||||||
"""
|
"""
|
||||||
logger = logging.getLogger('netbox.views.ObjectEditView')
|
logger = logging.getLogger('netbox.views.ObjectEditView')
|
||||||
obj = self.get_object(**kwargs)
|
obj = self.get_object(**kwargs)
|
||||||
|
model = self.queryset.model
|
||||||
|
|
||||||
# Take a snapshot for change logging (if editing an existing object)
|
# Take a snapshot for change logging (if editing an existing object)
|
||||||
if obj.pk and hasattr(obj, 'snapshot'):
|
if obj.pk and hasattr(obj, 'snapshot'):
|
||||||
@ -334,14 +337,15 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
|||||||
logger.debug("Form validation failed")
|
logger.debug("Form validation failed")
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
|
'model': model,
|
||||||
'object': obj,
|
'object': obj,
|
||||||
'form': form,
|
'form': form,
|
||||||
'return_url': self.get_return_url(request, obj),
|
'return_url': self.get_return_url(request, obj),
|
||||||
**self.get_extra_context(request, obj),
|
**self.get_extra_context(request, obj),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Form was submitted via a "quick add" widget
|
||||||
if '_quickadd' in request.POST:
|
if '_quickadd' in request.POST:
|
||||||
context['model'] = self.queryset.model
|
|
||||||
return render(request, 'htmx/quick_add.html', context)
|
return render(request, 'htmx/quick_add.html', context)
|
||||||
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -22,13 +22,9 @@ function slugify(slug: string, chars: number): string {
|
|||||||
export function initReslug(): void {
|
export function initReslug(): void {
|
||||||
for (const slugButton of getElements<HTMLButtonElement>('button#reslug')) {
|
for (const slugButton of getElements<HTMLButtonElement>('button#reslug')) {
|
||||||
const form = slugButton.form;
|
const form = slugButton.form;
|
||||||
if (form == null) {
|
if (form == null) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const slugField = form.querySelector('#id_slug') as HTMLInputElement;
|
const slugField = form.querySelector('#id_slug') as HTMLInputElement;
|
||||||
if (slugField == null) {
|
if (slugField == null) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const sourceId = slugField.getAttribute('slug-source');
|
const sourceId = slugField.getAttribute('slug-source');
|
||||||
const sourceField = form.querySelector(`#id_${sourceId}`) as HTMLInputElement;
|
const sourceField = form.querySelector(`#id_${sourceId}`) as HTMLInputElement;
|
||||||
|
|
||||||
|
@ -2,34 +2,24 @@ import { Modal } from 'bootstrap';
|
|||||||
|
|
||||||
function handleQuickAddObject(): void {
|
function handleQuickAddObject(): void {
|
||||||
const quick_add = document.getElementById('quick-add-object');
|
const quick_add = document.getElementById('quick-add-object');
|
||||||
if (quick_add == null) {
|
if (quick_add == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const object_id = quick_add.getAttribute('data-object-id');
|
const object_id = quick_add.getAttribute('data-object-id');
|
||||||
if (object_id == null) {
|
if (object_id == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
const object_repr = quick_add.getAttribute('data-object-repr');
|
const object_repr = quick_add.getAttribute('data-object-repr');
|
||||||
if (object_repr == null) {
|
if (object_repr == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const target_id = quick_add.getAttribute('data-target-id');
|
const target_id = quick_add.getAttribute('data-target-id');
|
||||||
if (target_id == null) {
|
if (target_id == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
const target = document.getElementById(target_id);
|
const target = document.getElementById(target_id);
|
||||||
if (target == null) {
|
if (target == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-expect-error tomselect added on init
|
||||||
target.tomselect.addOption({
|
target.tomselect.addOption({
|
||||||
id: object_id,
|
id: object_id,
|
||||||
display: object_repr,
|
display: object_repr,
|
||||||
});
|
});
|
||||||
//@ts-ignore
|
//@ts-expect-error tomselect added on init
|
||||||
target.tomselect.addItem(object_id);
|
target.tomselect.addItem(object_id);
|
||||||
|
|
||||||
const modal_element = document.getElementById('htmx-modal');
|
const modal_element = document.getElementById('htmx-modal');
|
||||||
@ -39,7 +29,6 @@ function handleQuickAddObject(): void {
|
|||||||
modal.hide();
|
modal.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initQuickAdd(): void {
|
export function initQuickAdd(): void {
|
||||||
|
@ -3,15 +3,23 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">{% trans "Quick Add" %} {{ model|meta:"verbose_name"|bettertitle }}</h5>
|
<h2 class="modal-title">
|
||||||
|
{% trans "Quick Add" %} {{ model|meta:"verbose_name"|bettertitle }}
|
||||||
|
</h2>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body row">
|
<div class="modal-body row">
|
||||||
<form hx-post="{% url model|viewname:"add" %}?_quickadd=True&target={{ request.GET.target }}" hx-target="#htmx-modal-content" enctype="multipart/form-data">
|
<form
|
||||||
|
hx-post="{% url model|viewname:"add" %}?_quickadd=True&target={{ request.GET.target }}"
|
||||||
|
hx-target="#htmx-modal-content"
|
||||||
|
enctype="multipart/form-data"
|
||||||
|
>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% include 'htmx/form.html' %}
|
{% include 'htmx/form.html' %}
|
||||||
<div class="text-end">
|
<div class="text-end">
|
||||||
<button type="button" class="btn btn-outline-secondary btn-float" data-bs-dismiss="modal" aria-label="Cancel">{% trans "Cancel" %}</button>
|
<button type="button" class="btn btn-outline-secondary btn-float" data-bs-dismiss="modal" aria-label="Cancel">
|
||||||
|
{% trans "Cancel" %}
|
||||||
|
</button>
|
||||||
<button type="submit" name="_quickadd" class="btn btn-primary">
|
<button type="submit" name="_quickadd" class="btn btn-primary">
|
||||||
{% trans "Create" %}
|
{% trans "Create" %}
|
||||||
</button>
|
</button>
|
||||||
|
@ -3,10 +3,13 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h2 class="modal-title">{{ object|meta:"verbose_name"|bettertitle }} {% trans "Created" %}</h2>
|
<h2 class="modal-title">
|
||||||
|
{{ object|meta:"verbose_name"|bettertitle }} {% trans "Created" %}
|
||||||
|
</h2>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body row">
|
<div class="modal-body row">
|
||||||
|
{# This content is intended to be scraped and populated in the targeted selection field. #}
|
||||||
<p id="quick-add-object"
|
<p id="quick-add-object"
|
||||||
data-object-repr="{{ object }}"
|
data-object-repr="{{ object }}"
|
||||||
data-object-id="{{ object.pk }}"
|
data-object-id="{{ object.pk }}"
|
||||||
|
@ -66,7 +66,7 @@ class DynamicModelChoiceMixin:
|
|||||||
choice (DEPRECATED: pass `context={'disabled': '$fieldname'}` instead)
|
choice (DEPRECATED: pass `context={'disabled': '$fieldname'}` instead)
|
||||||
context: A mapping of <option> template variables to their API data keys (optional; see below)
|
context: A mapping of <option> template variables to their API data keys (optional; see below)
|
||||||
selector: Include an advanced object selection widget to assist the user in identifying the desired object
|
selector: Include an advanced object selection widget to assist the user in identifying the desired object
|
||||||
quick_add: Include a button to quickly create a new related object for assignment
|
quick_add: Include a widget to quickly create a new related object for assignment
|
||||||
|
|
||||||
Context keys:
|
Context keys:
|
||||||
value: The name of the attribute which contains the option's value (default: 'id')
|
value: The name of the attribute which contains the option's value (default: 'id')
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
{% include 'django/forms/widgets/select.html' %}
|
{% include 'django/forms/widgets/select.html' %}
|
||||||
{% if widget.attrs.selector and not widget.attrs.disabled %}
|
{% if widget.attrs.selector and not widget.attrs.disabled %}
|
||||||
|
{# Opens the object selector modal #}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
title="{% trans "Open selector" %}"
|
title="{% trans "Open selector" %}"
|
||||||
@ -15,6 +16,7 @@
|
|||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if widget.attrs.quick_add and not widget.attrs.disabled %}
|
{% if widget.attrs.quick_add and not widget.attrs.disabled %}
|
||||||
|
{# Opens the quick add modal #}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
title="{% trans "Quick add" %}"
|
title="{% trans "Quick add" %}"
|
||||||
|
Loading…
Reference in New Issue
Block a user