Skip to content

Commit 1332f2b

Browse files
committed
[req-change] Made retrieving group id robust
1 parent bd315ff commit 1332f2b

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

openwisp_controller/config/static/config/js/relevant_templates.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ django.jQuery(function ($) {
105105
url.searchParams.set("backend", backend);
106106
}
107107
if (isDeviceGroup() && !$(".add-form").length) {
108-
// Get the group id from the URL
109-
// TODO: This is fragile, consider using a more robust way to get the group id.
110-
var pathParts = window.location.pathname.split("/");
111-
url.searchParams.set("group_id", pathParts[pathParts.length - 3]);
108+
url.searchParams.set("group_id", window._deviceGroupId);
112109
} else if ($('input[name="config-0-id"]').length) {
113110
url.searchParams.set("config_id", $('input[name="config-0-id"]').val());
114111
}

openwisp_controller/config/templates/admin/device_group/change_form.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
$(document).ready( function () {
1414
window._relevantTemplateUrl = "{{ relevant_template_url | safe }}";
1515
window._deviceGroup = true;
16+
window._deviceGroupId = "{{ original.pk }}";
1617
window.bindDefaultTemplateLoading();
1718
})
1819
}) (django.jQuery);

0 commit comments

Comments
 (0)