8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Ajoute des paramètres dans le bft tag

Les paramètres concernant bft sont maintenant spécifiés via un
dictionnaire pour alleger un peu le code.
Ajout des paramètres customisant l'engine et la possibilité de reload
quand un autre elt a changé
This commit is contained in:
Maël Kervella 2017-10-07 16:58:09 +00:00
parent feb00046a5
commit 474860f974
3 changed files with 26 additions and 22 deletions

View file

@ -48,19 +48,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %}
{% if interfaceform %}
<h3>Interface</h3>
{% if i_choices %}
{% if i_match_func %}
{% bootstrap_form_typeahead interfaceform 'ipv4' choices=i_choices match_func=i_match_func %}
{% else %}
{% bootstrap_form_typeahead interfaceform 'ipv4' choices=i_choices %}
{% endif %}
{% else %}
{% if i_match_func %}
{% bootstrap_form_typeahead interfaceform 'ipv4' match_func=i_match_func %}
{% else %}
{% if i_bft_param %}
{% bootstrap_form_typeahead interfaceform 'ipv4' bft_param=i_bft_param %}
{% else %}
{% bootstrap_form_typeahead interfaceform 'ipv4' %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% if domainform %}
<h3>Domaine</h3>

View file

@ -84,12 +84,14 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
{% bootstrap_form_typeahead form 'ipv4' choices='[...]' %}
"""
t_fields = typeahead_fields.split(',')
exclude = kwargs.get('exclude', None)
params = kwargs.get('bft_param', {})
exclude = params.get('exclude', None)
exclude = exclude.split(',') if exclude else []
t_choices = kwargs.get('choices', {})
t_match_func = kwargs.get('match_func', {})
t_choices = params.get('choices', {})
t_engine = params.get('engine', {})
t_match_func = params.get('match_func', {})
t_update_on = params.get('update_on', {})
hidden = [h.name for h in django_form.hidden_fields()]
form = ''
@ -116,7 +118,9 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
f_name,
f_value,
t_choices,
t_match_func
t_engine,
t_match_func,
t_update_on
)
)
else:
@ -145,19 +149,25 @@ def hidden_tag( f_bound, f_name ):
}
)
def typeahead_js( f_name, f_value, t_choices, t_match_func ) :
def typeahead_js( f_name, f_value,
t_choices, t_engine, t_match_func, t_update_on ) :
choices = mark_safe(t_choices[f_name]) if f_name in t_choices.keys() \
else default_choices( f_value )
engine = mark_safe(t_engine[f_name]) if f_name in t_engine.keys() \
else default_engine ( f_name )
match_func = mark_safe(t_match_func[f_name]) \
if f_name in t_match_func.keys() \
else default_match_func( f_name )
update_on = t_update_on[f_name] if f_name in t_update_on.keys() else []
js_content = \
'var choices_'+f_name+' = ' + choices + ';\n' + \
'var setup_'+f_name+' = function() {\n' + \
'var engine_'+f_name+' = ' + default_engine() + ';\n' + \
'var engine_'+f_name+' = ' + engine + ';\n' + \
'$("#'+input_id(f_name) + '").typeahead("destroy");\n' + \
'$("#'+input_id(f_name) + '").typeahead(\n' + \
default_datasets( f_name, match_func ) + '\n' + \
@ -171,6 +181,8 @@ def typeahead_js( f_name, f_value, t_choices, t_match_func ) :
'"typeahead:change", ' + \
typeahead_change( f_name ) + '\n' + \
');\n'
for u_id in update_on :
js_content += '$("#'+u_id+'").change( setup_'+f_name+' );\n'
js_content += '$("#'+input_id(f_name)+'").ready( setup_'+f_name+' );\n'
return render_tag( 'script', content=mark_safe( js_content ) )

View file

@ -159,7 +159,7 @@ def new_machine(request, userid):
return redirect("/users/profil/" + str(user.id))
i_choices = { 'ipv4': generate_ipv4_choices( interface.fields['ipv4'] ) }
i_match_func = { 'ipv4': generate_ipv4_match_func() }
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_choices': i_choices, 'i_match_func': i_match_func}, 'machines/machine.html', request)
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_bft_param': {'choices': i_choices, 'match_func': i_match_func}}, 'machines/machine.html', request)
@login_required
def edit_interface(request, interfaceid):
@ -198,7 +198,7 @@ def edit_interface(request, interfaceid):
return redirect("/users/profil/" + str(interface.machine.user.id))
i_choices = { 'ipv4': generate_ipv4_choices( interface_form.fields['ipv4'] ) }
i_match_func = { 'ipv4': generate_ipv4_match_func() }
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_choices': i_choices, 'i_match_func': i_match_func}, 'machines/machine.html', request)
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_bft_param': {'choices': i_choices, 'match_func': i_match_func}}, 'machines/machine.html', request)
@login_required
def del_machine(request, machineid):
@ -256,7 +256,7 @@ def new_interface(request, machineid):
return redirect("/users/profil/" + str(machine.user.id))
i_choices = { 'ipv4': generate_ipv4_choices( interface_form.fields['ipv4'] ) }
i_match_func = { 'ipv4': generate_ipv4_match_func() }
return form({'interfaceform': interface_form, 'domainform': domain_form, 'i_choices': i_choices, 'i_match_func': i_match_func}, 'machines/machine.html', request)
return form({'interfaceform': interface_form, 'domainform': domain_form, 'i_bft_param': { 'choices': i_choices, 'match_func': i_match_func }}, 'machines/machine.html', request)
@login_required
def del_interface(request, interfaceid):