mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +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' + \
|
||||||
|
reset_input( f_name, f_value ) + '\n' + \
|
||||||
|
'};\n' + \
|
||||||
|
'$("#'+input_id(f_name) + '").bind(\n' + \
|
||||||
'"typeahead:select", ' + \
|
'"typeahead:select", ' + \
|
||||||
typeahead_updater( f_name ) + '\n' + \
|
typeahead_updater( f_name ) + '\n' + \
|
||||||
').bind(\n' + \
|
').bind(\n' + \
|
||||||
'"typeahead:change", ' + \
|
'"typeahead:change", ' + \
|
||||||
typeahead_change( f_name ) + '\n' + \
|
typeahead_change( f_name ) + '\n' + \
|
||||||
')\n' + \
|
');\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) { ' \
|
||||||
|
|
Loading…
Reference in a new issue