mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 15:12:25 +00:00
Tout le script JS est dans une fonction
pour povoir être relaod plusieurs fois
This commit is contained in:
parent
af6df474ba
commit
d27f776588
1 changed files with 18 additions and 16 deletions
|
@ -155,20 +155,23 @@ def typeahead_js( f_name, f_value, t_choices, t_match_func ) :
|
||||||
else default_match_func()
|
else default_match_func()
|
||||||
|
|
||||||
js_content = \
|
js_content = \
|
||||||
'$("#'+input_id(f_name)+'").ready( function() {\n' + \
|
'var choices = ' + choices + ';\n' + \
|
||||||
reset_input( f_name, f_value ) + '\n' + \
|
'var setup = function() {\n' + \
|
||||||
'var choices = ' + choices + '\n' + \
|
'var engine = ' + deafult_engine() + ';\n' + \
|
||||||
'var engine = ' + default_engine() + '\n' + \
|
'$("#'+input_id(f_name) + '").typeahead("destroy");\n' + \
|
||||||
'$("#'+input_id(f_name) + '").typeahead(\n' + \
|
'$("#'+input_id(f_name) + '").typeahead(\n' + \
|
||||||
default_datasets( f_name, match_func ) + \
|
default_datasets( f_name, match_func ) + '\n' + \
|
||||||
').bind(\n' + \
|
');\n' + \
|
||||||
'"typeahead:select", ' + \
|
reset_input( f_name, f_value ) + '\n' + \
|
||||||
typeahead_updater( f_name ) + '\n' + \
|
'};\n' + \
|
||||||
').bind(\n' + \
|
'$("#'+input_id(f_name) + '").bind(\n' + \
|
||||||
'"typeahead:change", ' + \
|
'"typeahead:select", ' + \
|
||||||
typeahead_change( f_name ) + '\n' + \
|
typeahead_updater( f_name ) + '\n' + \
|
||||||
')\n' + \
|
').bind(\n' + \
|
||||||
'});\n'
|
'"typeahead:change", ' + \
|
||||||
|
typeahead_change( f_name ) + '\n' + \
|
||||||
|
');\n'
|
||||||
|
js_content += '$("#'+input_id(f_name)+'").ready( setup );\n'
|
||||||
|
|
||||||
return render_tag( 'script', content=mark_safe( js_content ) )
|
return render_tag( 'script', content=mark_safe( js_content ) )
|
||||||
|
|
||||||
|
@ -182,7 +185,7 @@ def default_choices( f_value ) :
|
||||||
', value: "' + str(choice[1]) + '"}' \
|
', value: "' + str(choice[1]) + '"}' \
|
||||||
for choice in f_value.choices \
|
for choice in f_value.choices \
|
||||||
]) + \
|
]) + \
|
||||||
'];'
|
']'
|
||||||
|
|
||||||
def default_engine () :
|
def default_engine () :
|
||||||
return 'new Bloodhound({ ' \
|
return 'new Bloodhound({ ' \
|
||||||
|
@ -217,7 +220,6 @@ def default_match_func () :
|
||||||
'engine.search(q, sync);' \
|
'engine.search(q, sync);' \
|
||||||
'}' \
|
'}' \
|
||||||
'}'
|
'}'
|
||||||
# matches.filter(function (elt) {return elt.type == $("#id_type").val();});sync(matches);})
|
|
||||||
|
|
||||||
def typeahead_updater( f_name ):
|
def typeahead_updater( f_name ):
|
||||||
return 'function(evt, item) { ' \
|
return 'function(evt, item) { ' \
|
||||||
|
@ -230,6 +232,6 @@ def typeahead_change( f_name ):
|
||||||
return 'function(evt) { ' \
|
return 'function(evt) { ' \
|
||||||
'if (evt.currentTarget.value === "") {' \
|
'if (evt.currentTarget.value === "") {' \
|
||||||
'$("#'+hidden_id(f_name)+'").val(""); ' \
|
'$("#'+hidden_id(f_name)+'").val(""); ' \
|
||||||
'$("#'+hidden_id(f_name)+'").change();' \
|
'$("#'+hidden_id(f_name)+'").change();' \
|
||||||
'}' \
|
'}' \
|
||||||
'}'
|
'}'
|
||||||
|
|
Loading…
Reference in a new issue