Skip to content

Commit cf8fdac

Browse files
committed
Refactor connection toggle to use API URLs
1 parent 2c1745c commit cf8fdac

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

netbox/project-static/dist/netbox.js

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.map

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/src/buttons/connectionToggle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { isTruthy, apiPatch, hasError, getElements } from '../util';
88
* @param element Connection Toggle Button Element
99
*/
1010
function toggleConnection(element: HTMLButtonElement): void {
11-
const id = element.getAttribute('data');
11+
const url = element.getAttribute('data-url');
1212
const connected = element.classList.contains('connected');
1313
const status = connected ? 'planned' : 'connected';
1414

15-
if (isTruthy(id)) {
16-
apiPatch(`/api/dcim/cables/${id}/`, { status }).then(res => {
15+
if (isTruthy(url)) {
16+
apiPatch(url, { status }).then(res => {
1717
if (hasError(res)) {
1818
// If the API responds with an error, show it to the user.
1919
createToast('danger', 'Error', res.error).show();

netbox/templates/dcim/inc/cable_toggle_buttons.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{% if perms.dcim.change_cable %}
22
{% if cable.status == 'connected' %}
3-
<button type="button" class="btn btn-warning btn-sm cable-toggle connected" title="Mark Planned" data="{{ cable.pk }}">
3+
<button type="button" class="btn btn-warning btn-sm cable-toggle connected" title="Mark Planned" data-url="{% url 'dcim-api:cable-detail' pk=cable.pk %}">
44
<i class="mdi mdi-lan-disconnect" aria-hidden="true"></i>
55
</button>
66
{% else %}
7-
<button type="button" class="btn btn-info btn-sm cable-toggle" title="Mark Installed" data="{{ cable.pk }}">
7+
<button type="button" class="btn btn-info btn-sm cable-toggle" title="Mark Installed" data-url="{% url 'dcim-api:cable-detail' pk=cable.pk %}">
88
<i class="mdi mdi-lan-connect" aria-hidden="true"></i>
99
</button>
1010
{% endif %}

0 commit comments

Comments
 (0)