mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Refactor connection toggle to use API URLs
This commit is contained in:
2
netbox/project-static/dist/netbox.js
vendored
2
netbox/project-static/dist/netbox.js
vendored
File diff suppressed because one or more lines are too long
2
netbox/project-static/dist/netbox.js.map
vendored
2
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
@ -8,12 +8,12 @@ import { isTruthy, apiPatch, hasError, getElements } from '../util';
|
||||
* @param element Connection Toggle Button Element
|
||||
*/
|
||||
function toggleConnection(element: HTMLButtonElement): void {
|
||||
const id = element.getAttribute('data');
|
||||
const url = element.getAttribute('data-url');
|
||||
const connected = element.classList.contains('connected');
|
||||
const status = connected ? 'planned' : 'connected';
|
||||
|
||||
if (isTruthy(id)) {
|
||||
apiPatch(`/api/dcim/cables/${id}/`, { status }).then(res => {
|
||||
if (isTruthy(url)) {
|
||||
apiPatch(url, { status }).then(res => {
|
||||
if (hasError(res)) {
|
||||
// If the API responds with an error, show it to the user.
|
||||
createToast('danger', 'Error', res.error).show();
|
||||
|
@ -1,10 +1,10 @@
|
||||
{% if perms.dcim.change_cable %}
|
||||
{% if cable.status == 'connected' %}
|
||||
<button type="button" class="btn btn-warning btn-sm cable-toggle connected" title="Mark Planned" data="{{ cable.pk }}">
|
||||
<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 %}">
|
||||
<i class="mdi mdi-lan-disconnect" aria-hidden="true"></i>
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="button" class="btn btn-info btn-sm cable-toggle" title="Mark Installed" data="{{ cable.pk }}">
|
||||
<button type="button" class="btn btn-info btn-sm cable-toggle" title="Mark Installed" data-url="{% url 'dcim-api:cable-detail' pk=cable.pk %}">
|
||||
<i class="mdi mdi-lan-connect" aria-hidden="true"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user