diff --git a/openwisp_controller/config/admin.py b/openwisp_controller/config/admin.py index e6b279d41..7004a848d 100644 --- a/openwisp_controller/config/admin.py +++ b/openwisp_controller/config/admin.py @@ -445,6 +445,7 @@ class DeviceAdmin(MultitenantAdminMixin, BaseConfigAdmin, UUIDAdmin): class Media(BaseConfigAdmin.Media): js = BaseConfigAdmin.Media.js + [ f'{prefix}js/tabs.js', + f'{prefix}js/device.js', f'{prefix}js/relevant_templates.js', ] diff --git a/openwisp_controller/config/base/device.py b/openwisp_controller/config/base/device.py index 5c82b25b5..21b4b22a0 100644 --- a/openwisp_controller/config/base/device.py +++ b/openwisp_controller/config/base/device.py @@ -88,7 +88,12 @@ class AbstractDevice(OrgMixin, BaseModel): blank=True, null=True, db_index=True, - help_text=_('ip address of the management interface, if available'), + help_text=_( + 'IP address used by OpenWISP to reach the device when performing ' + 'any type of push operation or active check. The value of this field is ' + 'generally sent by the device and hence does not need to be changed, ' + 'but can be changed or cleared manually if needed.' + ), ) hardware_id = models.CharField(**(app_settings.HARDWARE_ID_OPTIONS)) diff --git a/openwisp_controller/config/migrations/0013_last_ip_management_ip_and_status_applied.py b/openwisp_controller/config/migrations/0013_last_ip_management_ip_and_status_applied.py index 6fdc5496b..ab0132aff 100644 --- a/openwisp_controller/config/migrations/0013_last_ip_management_ip_and_status_applied.py +++ b/openwisp_controller/config/migrations/0013_last_ip_management_ip_and_status_applied.py @@ -64,7 +64,10 @@ class Migration(migrations.Migration): name='management_ip', field=models.GenericIPAddressField( blank=True, - help_text='ip address of the management interface, if available', + help_text='IP address used by OpenWISP to reach the device when ' + 'performing any type of push operation or active check. The value ' + 'of this field is generally sent by the device and hence does not ' + 'need to be changed, but can be changed or cleared manually if needed.', null=True, ), ), diff --git a/openwisp_controller/config/migrations/0027_add_indexes_on_ip_fields.py b/openwisp_controller/config/migrations/0027_add_indexes_on_ip_fields.py index d8a04ceb6..92fb68611 100644 --- a/openwisp_controller/config/migrations/0027_add_indexes_on_ip_fields.py +++ b/openwisp_controller/config/migrations/0027_add_indexes_on_ip_fields.py @@ -27,7 +27,11 @@ class Migration(migrations.Migration): field=models.GenericIPAddressField( blank=True, db_index=True, - help_text='ip address of the management interface, if available', + help_text='This is the IP address used by OpenWISP to reach the ' + 'device when performing any type of push operation or active ' + 'check. The value of this field is generally sent by the device ' + 'and hence does not need to be changed, but can be changed or ' + 'cleared manually if needed.', null=True, ), ), diff --git a/openwisp_controller/config/migrations/0037_alter_management_ip_help_text.py b/openwisp_controller/config/migrations/0037_alter_management_ip_help_text.py new file mode 100644 index 000000000..34261bc44 --- /dev/null +++ b/openwisp_controller/config/migrations/0037_alter_management_ip_help_text.py @@ -0,0 +1,27 @@ +# Generated by Django 3.1.13 on 2021-08-11 16:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('config', '0036_device_group'), + ] + + operations = [ + migrations.AlterField( + model_name='device', + name='management_ip', + field=models.GenericIPAddressField( + blank=True, + db_index=True, + help_text='IP address used by OpenWISP to reach the device when ' + 'performing any type of push operation or active check. The ' + 'value of this field is generally sent by the device and hence ' + 'does not need to be changed, but can be changed or cleared ' + 'manually if needed.', + null=True, + ), + ), + ] diff --git a/openwisp_controller/config/static/config/js/device.js b/openwisp_controller/config/static/config/js/device.js new file mode 100644 index 000000000..003ed3a84 --- /dev/null +++ b/openwisp_controller/config/static/config/js/device.js @@ -0,0 +1,37 @@ +"use strict"; +django.jQuery(function ($) { + if ($(".add-form").length || !$("#device_form").length) { + return; + } + + // replaces the management ip field with text with the option to edit it + var ip_input = $(".field-management_ip > div > input"); + var initial_ip = ip_input.prop("value"); + ip_input.after(function () { + ip_input.hide(); + return ( + '' + + (initial_ip === "" ? "-n/a-" : initial_ip) + + "" + ); + }); + $("#management_ip_text").after( + ' ' + ); + $("#edit_management_ip").click(function () { + var ip_text = $("#management_ip_text"); + var img_element = $("#edit_management_ip > img"); + if (img_element.attr("alt") === "Edit") { + ip_input.show(); + ip_text.hide(); + img_element.attr("src", "/static/admin/img/icon-deletelink.svg"); + img_element.attr("alt", "Cancel"); + } else { + ip_text.show(); + ip_input.hide(); + ip_input.val(initial_ip); + img_element.attr("src", "/static/admin/img/icon-changelink.svg"); + img_element.attr("alt", "Edit"); + } + }); +}); diff --git a/openwisp_controller/config/static/config/js/tabs.js b/openwisp_controller/config/static/config/js/tabs.js index a82f5f40c..4dd381429 100644 --- a/openwisp_controller/config/static/config/js/tabs.js +++ b/openwisp_controller/config/static/config/js/tabs.js @@ -76,33 +76,5 @@ django.jQuery(function ($) { } } - // replaces the management ip field with text with the option to edit it - $(".field-management_ip > div").append( - 'Edit' - ); - var ip_input = $(".field-management_ip > div > input"); - var initial_ip = ip_input.prop("value"); - ip_input.after(function () { - ip_input.hide(); - return ( - '