From 678f7132e2d21bf7b12d570eff01c8db3c96a2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 7 Oct 2017 16:47:13 +0000 Subject: [PATCH] =?UTF-8?q?Renomme=20des=20variables=20pour=20=C3=A9viter?= =?UTF-8?q?=20les=20conflits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templatetags/bootstrap_form_typeahead.py | 32 +++++++++---------- machines/views.py | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/machines/templatetags/bootstrap_form_typeahead.py b/machines/templatetags/bootstrap_form_typeahead.py index d1b3978e..fb95bb23 100644 --- a/machines/templatetags/bootstrap_form_typeahead.py +++ b/machines/templatetags/bootstrap_form_typeahead.py @@ -151,13 +151,13 @@ def typeahead_js( f_name, f_value, t_choices, t_match_func ) : else default_choices( f_value ) match_func = mark_safe(t_match_func[f_name]) \ - if f_name in t_match_func.keys() \ - else default_match_func() + if f_name in t_match_func.keys() \ + else default_match_func( f_name ) js_content = \ - 'var choices = ' + choices + ';\n' + \ - 'var setup = function() {\n' + \ - 'var engine = ' + deafult_engine() + ';\n' + \ + 'var choices_'+f_name+' = ' + choices + ';\n' + \ + 'var setup_'+f_name+' = function() {\n' + \ + 'var engine_'+f_name+' = ' + default_engine() + ';\n' + \ '$("#'+input_id(f_name) + '").typeahead("destroy");\n' + \ '$("#'+input_id(f_name) + '").typeahead(\n' + \ default_datasets( f_name, match_func ) + '\n' + \ @@ -171,7 +171,7 @@ def typeahead_js( f_name, f_value, t_choices, t_match_func ) : '"typeahead:change", ' + \ typeahead_change( f_name ) + '\n' + \ ');\n' - js_content += '$("#'+input_id(f_name)+'").ready( setup );\n' + js_content += '$("#'+input_id(f_name)+'").ready( setup_'+f_name+' );\n' return render_tag( 'script', content=mark_safe( js_content ) ) @@ -187,13 +187,13 @@ def default_choices( f_value ) : ]) + \ ']' -def default_engine () : - return 'new Bloodhound({ ' \ +def default_engine ( f_name ) : + return 'new Bloodhound({ ' \ 'datumTokenizer: Bloodhound.tokenizers.obj.whitespace("value"), ' \ 'queryTokenizer: Bloodhound.tokenizers.whitespace, ' \ - 'local: choices, ' \ - 'identify: function(obj) { return obj.key; } ' \ - '});' + 'local: choices_'+f_name+', ' \ + 'identify: function(obj) { return obj.key; } ' \ + '})' def default_datasets( f_name, match_func ) : return '{ ' \ @@ -207,17 +207,17 @@ def default_datasets( f_name, match_func ) : 'source: '+match_func + \ '}' -def default_match_func () : +def default_match_func ( f_name ) : return 'function(q, sync) {' \ 'if (q === "") {' \ 'var nb = 10;' \ 'var first = [] ;' \ - 'for ( var i=0 ; i