mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-25 09:21:10 +00:00
added dynamic form fields and fixed support for users without javascript support
This commit is contained in:
parent
ffcfccb20f
commit
7e218b06ed
@ -71,17 +71,19 @@ class TrimmedCharField(forms.CharField):
|
||||
class ConfigureForm(forms.Form):
|
||||
"""Form to configure the dynamic DNS client"""
|
||||
enabled = forms.BooleanField(label=_('Enable Dynamic DNS'),
|
||||
required=False)
|
||||
required=False,widget=forms.CheckboxInput
|
||||
(attrs={'onclick': 'mod_form();'}))
|
||||
|
||||
dynamicdns_service = forms.ChoiceField(label=_('Service type'),
|
||||
help_text=_('Please choose a update protocol according to your provider.\
|
||||
We recommend the GnudIP protocol. If your provider does not \
|
||||
support the GnudIP protocol or your provider is not listed \
|
||||
you may use the update URL of your provider.'),
|
||||
choices=(('1', 'GnudIP'),
|
||||
choices=(('1', 'GnuDIP'),
|
||||
('2', 'noip.com'),
|
||||
('3', 'selfhost.bz'),
|
||||
('4', 'other Update URL')))
|
||||
('4', 'other Update URL')),
|
||||
widget=forms.Select(attrs={"onChange":'mod_form()'}))
|
||||
|
||||
dynamicdns_server = TrimmedCharField(
|
||||
label=_('GnudIP Server Address'),
|
||||
@ -232,7 +234,27 @@ def get_status():
|
||||
if len(details) > 5:
|
||||
status['dynamicdns_ipurl'] = details[5]
|
||||
else:
|
||||
status['dynamicdns_secret'] = ''
|
||||
status['dynamicdns_ipurl'] = ''
|
||||
|
||||
if len(details) > 6:
|
||||
status['dynamicdns_update_url'] = details[6]
|
||||
else:
|
||||
status['dynamicdns_update_url'] = ''
|
||||
|
||||
if len(details) > 7:
|
||||
status['disable_SSL_cert_check'] = details[7]
|
||||
else:
|
||||
status['disable_SSL_cert_check'] = ''
|
||||
|
||||
if len(details) > 8:
|
||||
status['use_http_basic_auth'] = details[8]
|
||||
else:
|
||||
status['use_http_basic_auth'] = ''
|
||||
|
||||
if status['dynamicdns_server'] is not '':
|
||||
status['dynamicdns_service'] = '1'
|
||||
else:
|
||||
status['dynamicdns_service'] = '4'
|
||||
|
||||
return status
|
||||
|
||||
@ -258,6 +280,12 @@ def _apply_changes(request, old_status, new_status):
|
||||
new_status['dynamicdns_secret'] or \
|
||||
old_status['dynamicdns_ipurl'] != \
|
||||
new_status['dynamicdns_ipurl'] or \
|
||||
old_status['dynamicdns_update_url'] != \
|
||||
new_status['dynamicdns_update_url'] or \
|
||||
old_status['disable_SSL_cert_check'] != \
|
||||
new_status['disable_SSL_cert_check'] or \
|
||||
old_status['use_http_basic_auth'] != \
|
||||
new_status['use_http_basic_auth'] or \
|
||||
old_status['enabled'] != \
|
||||
new_status['enabled']:
|
||||
|
||||
@ -265,7 +293,10 @@ def _apply_changes(request, old_status, new_status):
|
||||
'-d', new_status['dynamicdns_domain'],
|
||||
'-u', new_status['dynamicdns_user'],
|
||||
'-p', new_status['dynamicdns_secret'],
|
||||
'-I', new_status['dynamicdns_ipurl']])
|
||||
'-I', new_status['dynamicdns_ipurl'],
|
||||
'-U', new_status['dynamicdns_update_url'],
|
||||
'-c', new_status['disable_SSL_cert_check'],
|
||||
'-b', new_status['use_http_basic_auth']])
|
||||
|
||||
if old_status['enabled']:
|
||||
_run(['stop'])
|
||||
|
||||
@ -27,15 +27,21 @@
|
||||
|
||||
{% include 'bootstrapform/field.html' with field=form.enabled %}
|
||||
|
||||
<div id='dynamicdns-post-enabled-form'
|
||||
style='display: {{ form.enabled.value|yesno:'block,none' }};'>
|
||||
<div id='dynamicdns-post-enabled-form'>
|
||||
|
||||
<h3>Dynamic DNS type</h3>
|
||||
<div id='dynamicdns-no-js'>
|
||||
You have disabled Javascript. Dynamic form mode is disabled. Please fill
|
||||
only "GnudIP Server Address" or "Update URL" field.</br><hr>
|
||||
</div>
|
||||
<div id='div-dynamicdns-dropdown' style="display:none">
|
||||
{% include 'bootstrapform/field.html' with field=form.dynamicdns_service %}
|
||||
<div id='dynamicdns-gnudip'>
|
||||
</div>
|
||||
<div id='div-dynamicdns-gnudip'>
|
||||
{% include 'bootstrapform/field.html' with field=form.dynamicdns_server %}
|
||||
</div>
|
||||
|
||||
<div id='dynamicdns-updateurl'>
|
||||
<div id='div-dynamicdns-updateurl'>
|
||||
{% include 'bootstrapform/field.html' with field=form.dynamicdns_update_url %}
|
||||
{% include 'bootstrapform/field.html' with field=form.disable_SSL_cert_check %}
|
||||
{% include 'bootstrapform/field.html' with field=form.use_http_basic_auth %}
|
||||
@ -59,85 +65,52 @@
|
||||
|
||||
{% block page_js %}
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
window.onload = function() {hide()}
|
||||
|
||||
(function($) {
|
||||
window.onload = function() {mod_form()}
|
||||
|
||||
$('#id_dynamicdns-enabled').change(function() {
|
||||
if ($('#id_dynamicdns-enabled').prop('checked')) {
|
||||
$('#dynamicdns-post-enabled-form').show('slow');
|
||||
} else {
|
||||
$('#dynamicdns-post-enabled-form').hide('slow');
|
||||
}
|
||||
});
|
||||
|
||||
$('#id_dynamicdns-dynamicdns_service').change(function() {
|
||||
//$(this).find('option:selected').text() == GnudIP
|
||||
if ($(this).val() == 1){
|
||||
$('#dynamicdns-updateurl').hide();
|
||||
$('#dynamicdns-gnudip').show('slow');
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("");
|
||||
}
|
||||
if ($(this).val() == 2){
|
||||
$('#dynamicdns-updateurl').show('slow');
|
||||
$('#dynamicdns-gnudip').hide();
|
||||
$('#id_dynamicdns-dynamicdns_server').val("");
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("https://noip.com/update.php?user=$user&pass=$pass&domain=$domain&IP=foo$ip");
|
||||
}
|
||||
if ($(this).val() == 3){
|
||||
$('#dynamicdns-updateurl').show('slow');
|
||||
$('#dynamicdns-gnudip').hide();
|
||||
$('#id_dynamicdns-dynamicdns_server').val("");
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("https://selfhost.bz/update.php?user=$user&pass=$pass&domain=$domain&IP=foo$ip");
|
||||
}
|
||||
if ($(this).val() == 4){
|
||||
$('#dynamicdns-updateurl').show('slow');
|
||||
$('#dynamicdns-gnudip').hide();
|
||||
$('#id_dynamicdns-dynamicdns_server').val("");
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("https://example.com/update.php?user=$user&pass=$pass&domain=$domain&IP=foo$ip");
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
||||
|
||||
function show_pass()
|
||||
{
|
||||
if(document.getElementById('id_dynamicdns-showpw').checked){
|
||||
document.getElementById("id_dynamicdns-dynamicdns_secret").type='text';}
|
||||
document.getElementById('id_dynamicdns-dynamicdns_secret').type='text';}
|
||||
else
|
||||
document.getElementById("id_dynamicdns-dynamicdns_secret").type='password';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_secret').type='password';
|
||||
}
|
||||
|
||||
function hide()
|
||||
function mod_form()
|
||||
{
|
||||
if ($('#id_dynamicdns-enabled').prop('checked')) {
|
||||
//$(this).find('option:selected').text() == GnudIP
|
||||
if ($(this).val() == 1){
|
||||
$('#dynamicdns-updateurl').hide();
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("");
|
||||
}
|
||||
if ($(this).val() == 2){
|
||||
$('#dynamicdns-gnudip').hide();
|
||||
$('#id_dynamicdns-dynamicdns_server').val("");
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("https://noip.com/update.php?user=$user&pass=$pass&domain=$domain&IP=foo$ip");
|
||||
}
|
||||
if ($(this).val() == 3){
|
||||
$('#dynamicdns-gnudip').hide();
|
||||
$('#id_dynamicdns-dynamicdns_server').val("");
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("https://selfhost.bz/update.php?user=$user&pass=$pass&domain=$domain&IP=foo$ip");
|
||||
}
|
||||
if ($(this).val() == 4){
|
||||
$('#dynamicdns-gnudip').hide();
|
||||
$('#id_dynamicdns-dynamicdns_server').val("");
|
||||
$('#id_dynamicdns-dynamicdns_update_url').val("https://example.com/update.php?user=$user&pass=$pass&domain=$domain&IP=foo$ip");
|
||||
}
|
||||
} else {
|
||||
$('#dynamicdns-post-enabled-form').hide('slow');
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('dynamicdns-no-js').style.display = 'none';
|
||||
document.getElementById('div-dynamicdns-dropdown').style.display = 'block';
|
||||
|
||||
if ( document.getElementById('id_dynamicdns-enabled').checked ) {
|
||||
document.getElementById('dynamicdns-post-enabled-form').style.display = 'block';
|
||||
var dropdown = document.getElementById('id_dynamicdns-dynamicdns_service');
|
||||
var service_type = dropdown.options[dropdown.selectedIndex].value;
|
||||
if (service_type == 1){
|
||||
document.getElementById('div-dynamicdns-updateurl').style.display = 'none';
|
||||
document.getElementById('div-dynamicdns-gnudip').style.display = 'block';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='';
|
||||
}
|
||||
if (service_type == 2){
|
||||
document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
|
||||
document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='noip';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
|
||||
}
|
||||
if (service_type == 3){
|
||||
document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
|
||||
document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='selfhost';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
|
||||
}
|
||||
if (service_type == 4){
|
||||
document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
|
||||
document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='';
|
||||
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
|
||||
}
|
||||
}else{
|
||||
document.getElementById('dynamicdns-post-enabled-form').style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user