Skip to content

Commit

Permalink
Merge pull request #17523 from atownson/issue_16009
Browse files Browse the repository at this point in the history
Closes #16009 - Added styling to form templates to enable floating button groups
  • Loading branch information
jeremystretch authored Oct 15, 2024
2 parents 111a1ad + ba4b5fe commit aab9656
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 23 deletions.
2 changes: 1 addition & 1 deletion netbox/project-static/dist/netbox.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions netbox/project-static/dist/netbox.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions netbox/project-static/dist/netbox.js.map

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions netbox/project-static/src/buttons/floatBulk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { getElements } from '../util';

/**
* Conditionally add and remove a class that will float the button group
* based on whether or not items in the list are checked
*/
function toggleFloat(): void {
const checkedCheckboxes = document.querySelector<HTMLInputElement>(
'input[type="checkbox"][name="pk"]:checked',
);
const buttonGroup = document.querySelector<HTMLDivElement>(
'div.form.form-horizontal div.btn-list',
);
if (!buttonGroup) {
return;
}
const isFloating = buttonGroup.classList.contains('btn-float-group-left');
if (checkedCheckboxes !== null && !isFloating) {
buttonGroup.classList.add('btn-float-group-left');
} else if (checkedCheckboxes === null && isFloating) {
buttonGroup.classList.remove('btn-float-group-left');
}
}

/**
* Initialize floating bulk buttons.
*/
export function initFloatBulk(): void {
for (const element of getElements<HTMLInputElement>('input[type="checkbox"][name="pk"]')) {
element.addEventListener('change', () => {
toggleFloat();
});
}
// Handle the select-all checkbox
for (const element of getElements<HTMLInputElement>(
'table tr th > input[type="checkbox"].toggle',
)) {
element.addEventListener('change', () => {
toggleFloat();
});
}
}
2 changes: 2 additions & 0 deletions netbox/project-static/src/buttons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { initDepthToggle } from './depthToggle';
import { initMoveButtons } from './moveOptions';
import { initReslug } from './reslug';
import { initSelectAll } from './selectAll';
import { initFloatBulk } from './floatBulk';
import { initSelectMultiple } from './selectMultiple';
import { initMarkdownPreviews } from './markdownPreview';
import { initSecretToggle } from './secretToggle';
Expand All @@ -14,6 +15,7 @@ export function initButtons(): void {
initReslug,
initSelectAll,
initSelectMultiple,
initFloatBulk,
initMoveButtons,
initMarkdownPreviews,
initSecretToggle,
Expand Down
22 changes: 22 additions & 0 deletions netbox/project-static/styles/custom/_misc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ span.color-label {
letter-spacing: .15rem;
}

// A floating div for form buttons
.btn-float-group {
position: sticky;
bottom: 10px;
z-index: 2;
}

.btn-float-group-left {
@extend .btn-float-group;
float: left;
}

.btn-float-group-right {
@extend .btn-float-group;
float: right;
}

// Override a transparent background
.btn-float {
--tblr-btn-bg: var(--#{$prefix}bg-surface-tertiary) !important;
}

.logo {
height: 80px;
}
Expand Down
4 changes: 2 additions & 2 deletions netbox/templates/generic/bulk_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ <h2 class="col-9 offset-3">{% trans "Comments" %}</h2>

{% endif %}

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

Expand Down
6 changes: 3 additions & 3 deletions netbox/templates/generic/object_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
{% endblock form %}
</div>

<div class="text-end my-3">
<div class="btn-float-group-right">
{% block buttons %}
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
<a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
{% if object.pk %}
<button type="submit" name="_update" class="btn btn-primary">
{% trans "Save" %}
Expand All @@ -79,7 +79,7 @@
<button type="submit" name="_create" class="btn btn-primary">
{% trans "Create" %}
</button>
<button type="submit" name="_addanother" class="btn btn-outline-primary">
<button type="submit" name="_addanother" class="btn btn-outline-primary btn-float">
{% trans "Create & Add Another" %}
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/generic/object_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
{# /Objects table #}

{# Form buttons #}
<div class="btn-list d-print-none mt-2">
<div class="btn-list d-print-none">
{% block bulk_buttons %}
<div class="bulk-action-buttons">
{% if 'bulk_edit' in actions %}
Expand Down
16 changes: 8 additions & 8 deletions netbox/templates/inc/filter_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
</div>
{% endif %}
</div>
<div class="card-footer text-end d-print-none border-0">
<button type="button" class="btn btn-outline-danger m-1" data-reset-select>
<i class="mdi mdi-backspace"></i> {% trans "Reset" %}
</button>
<button type="submit" class="btn btn-primary m-1">
<i class="mdi mdi-magnify"></i> {% trans "Search" %}
</button>
</div>
</div>
<div class="btn-float-group-right me-1">
<button type="button" class="btn btn-outline-danger btn-float" data-reset-select>
<i class="mdi mdi-backspace"></i> {% trans "Reset" %}
</button>
<button type="submit" class="btn btn-primary">
<i class="mdi mdi-magnify"></i> {% trans "Search" %}
</button>
</div>
</form>

0 comments on commit aab9656

Please sign in to comment.