From 4f75f4476998c8aa1f1936ad36673e89d387810e Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 22 Aug 2015 20:22:08 +0530 Subject: [PATCH] networks: Fix showing password during PPPoE edit - Javascript was missing for the template altogether. Added one similar to create case. - Minor refactoring to existing javascript. - Consistent styling for display label and field id. --- plinth/modules/networks/forms.py | 4 ++-- .../templates/connections_create.html | 21 ++++++++----------- .../networks/templates/connections_edit.html | 11 ++++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plinth/modules/networks/forms.py b/plinth/modules/networks/forms.py index 7ff371c0c..290d1d89d 100644 --- a/plinth/modules/networks/forms.py +++ b/plinth/modules/networks/forms.py @@ -89,8 +89,8 @@ available over this interfaces. Select Internal only for trusted networks.'), username = forms.CharField(label=_('Username')) password = forms.CharField(label=_('Password'), widget=forms.PasswordInput()) - showpw = forms.BooleanField(label=_('show password'), - required=False) + show_password = forms.BooleanField(label=_('Show password'), + required=False) def __init__(self, *args, **kwargs): """Initialize the form, populate interface choices.""" diff --git a/plinth/modules/networks/templates/connections_create.html b/plinth/modules/networks/templates/connections_create.html index c28737d7a..b3a753389 100644 --- a/plinth/modules/networks/templates/connections_create.html +++ b/plinth/modules/networks/templates/connections_create.html @@ -58,18 +58,15 @@ } }); - $('#id_showpw').change(function() { - //changing type attribute from password to text is prevented by - //most browsers make a new form field works for me - if ($('#id_showpw').prop('checked')) { - $('#id_password').replaceWith( - $('#id_password').clone().attr( - 'type', 'text')); - } else { - $('#id_password').replaceWith( - $('#id_password').clone().attr( - 'type', 'password')); - } + $('#id_show_password').change(function() { + // Changing type attribute from password to text is prevented by + // most browsers. Making a new form field works. + new_type = 'password'; + if ($('#id_show_password').prop('checked')) + new_type = 'text'; + + $('#id_password').replaceWith( + $('#id_password').clone().attr('type', new_type)); }); })(jQuery); diff --git a/plinth/modules/networks/templates/connections_edit.html b/plinth/modules/networks/templates/connections_edit.html index 65e2f8a1e..3e64eec35 100644 --- a/plinth/modules/networks/templates/connections_edit.html +++ b/plinth/modules/networks/templates/connections_edit.html @@ -58,6 +58,17 @@ } }); + $('#id_show_password').change(function() { + // Changing type attribute from password to text is prevented by + // most browsers. Making a new form field works. + new_type = 'password'; + if ($('#id_show_password').prop('checked')) + new_type = 'text'; + + $('#id_password').replaceWith( + $('#id_password').clone().attr('type', new_type)); + }); + })(jQuery);