Skip to content

Commit aab9656

Browse files
Merge pull request #17523 from atownson/issue_16009
Closes #16009 - Added styling to form templates to enable floating button groups
2 parents 111a1ad + ba4b5fe commit aab9656

File tree

10 files changed

+89
-23
lines changed

10 files changed

+89
-23
lines changed

netbox/project-static/dist/netbox.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/netbox.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/netbox.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getElements } from '../util';
2+
3+
/**
4+
* Conditionally add and remove a class that will float the button group
5+
* based on whether or not items in the list are checked
6+
*/
7+
function toggleFloat(): void {
8+
const checkedCheckboxes = document.querySelector<HTMLInputElement>(
9+
'input[type="checkbox"][name="pk"]:checked',
10+
);
11+
const buttonGroup = document.querySelector<HTMLDivElement>(
12+
'div.form.form-horizontal div.btn-list',
13+
);
14+
if (!buttonGroup) {
15+
return;
16+
}
17+
const isFloating = buttonGroup.classList.contains('btn-float-group-left');
18+
if (checkedCheckboxes !== null && !isFloating) {
19+
buttonGroup.classList.add('btn-float-group-left');
20+
} else if (checkedCheckboxes === null && isFloating) {
21+
buttonGroup.classList.remove('btn-float-group-left');
22+
}
23+
}
24+
25+
/**
26+
* Initialize floating bulk buttons.
27+
*/
28+
export function initFloatBulk(): void {
29+
for (const element of getElements<HTMLInputElement>('input[type="checkbox"][name="pk"]')) {
30+
element.addEventListener('change', () => {
31+
toggleFloat();
32+
});
33+
}
34+
// Handle the select-all checkbox
35+
for (const element of getElements<HTMLInputElement>(
36+
'table tr th > input[type="checkbox"].toggle',
37+
)) {
38+
element.addEventListener('change', () => {
39+
toggleFloat();
40+
});
41+
}
42+
}

netbox/project-static/src/buttons/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { initDepthToggle } from './depthToggle';
33
import { initMoveButtons } from './moveOptions';
44
import { initReslug } from './reslug';
55
import { initSelectAll } from './selectAll';
6+
import { initFloatBulk } from './floatBulk';
67
import { initSelectMultiple } from './selectMultiple';
78
import { initMarkdownPreviews } from './markdownPreview';
89
import { initSecretToggle } from './secretToggle';
@@ -14,6 +15,7 @@ export function initButtons(): void {
1415
initReslug,
1516
initSelectAll,
1617
initSelectMultiple,
18+
initFloatBulk,
1719
initMoveButtons,
1820
initMarkdownPreviews,
1921
initSecretToggle,

netbox/project-static/styles/custom/_misc.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ span.color-label {
3434
letter-spacing: .15rem;
3535
}
3636

37+
// A floating div for form buttons
38+
.btn-float-group {
39+
position: sticky;
40+
bottom: 10px;
41+
z-index: 2;
42+
}
43+
44+
.btn-float-group-left {
45+
@extend .btn-float-group;
46+
float: left;
47+
}
48+
49+
.btn-float-group-right {
50+
@extend .btn-float-group;
51+
float: right;
52+
}
53+
54+
// Override a transparent background
55+
.btn-float {
56+
--tblr-btn-bg: var(--#{$prefix}bg-surface-tertiary) !important;
57+
}
58+
3759
.logo {
3860
height: 80px;
3961
}

netbox/templates/generic/bulk_edit.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ <h2 class="col-9 offset-3">{% trans "Comments" %}</h2>
102102

103103
{% endif %}
104104

105-
<div class="text-end">
106-
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
105+
<div class="btn-float-group-right">
106+
<a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
107107
<button type="submit" name="_apply" class="btn btn-primary">{% trans "Apply" %}</button>
108108
</div>
109109

netbox/templates/generic/object_edit.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
{% endblock form %}
6868
</div>
6969

70-
<div class="text-end my-3">
70+
<div class="btn-float-group-right">
7171
{% block buttons %}
72-
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
72+
<a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
7373
{% if object.pk %}
7474
<button type="submit" name="_update" class="btn btn-primary">
7575
{% trans "Save" %}
@@ -79,7 +79,7 @@
7979
<button type="submit" name="_create" class="btn btn-primary">
8080
{% trans "Create" %}
8181
</button>
82-
<button type="submit" name="_addanother" class="btn btn-outline-primary">
82+
<button type="submit" name="_addanother" class="btn btn-outline-primary btn-float">
8383
{% trans "Create & Add Another" %}
8484
</button>
8585
</div>

netbox/templates/generic/object_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
{# /Objects table #}
122122

123123
{# Form buttons #}
124-
<div class="btn-list d-print-none mt-2">
124+
<div class="btn-list d-print-none">
125125
{% block bulk_buttons %}
126126
<div class="bulk-action-buttons">
127127
{% if 'bulk_edit' in actions %}

netbox/templates/inc/filter_list.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
</div>
3838
{% endif %}
3939
</div>
40-
<div class="card-footer text-end d-print-none border-0">
41-
<button type="button" class="btn btn-outline-danger m-1" data-reset-select>
42-
<i class="mdi mdi-backspace"></i> {% trans "Reset" %}
43-
</button>
44-
<button type="submit" class="btn btn-primary m-1">
45-
<i class="mdi mdi-magnify"></i> {% trans "Search" %}
46-
</button>
47-
</div>
40+
</div>
41+
<div class="btn-float-group-right me-1">
42+
<button type="button" class="btn btn-outline-danger btn-float" data-reset-select>
43+
<i class="mdi mdi-backspace"></i> {% trans "Reset" %}
44+
</button>
45+
<button type="submit" class="btn btn-primary">
46+
<i class="mdi mdi-magnify"></i> {% trans "Search" %}
47+
</button>
4848
</div>
4949
</form>

0 commit comments

Comments
 (0)