d91ba4f6ea66715eca4c5f900f5f891794ddef56
[auf_rh_dae.git] / project / templates / autocompleteselect.html
1 {% load i18n %}
2 <input type="text" name="{{name}}_text" id="{{html_id}}_text" value="" {{ extra_attrs }} />
3 {% if add_link %}
4 <a href="{{ add_link }}" class="add-another" id="add_{{ html_id }}" onclick="return showAddAnotherPopup(this);"> <img src="{{ admin_media_prefix }}img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"></a>
5 {% endif %}
6 {% block help %}{% endblock %}
7 <div id="{{html_id}}_on_deck" class="results_on_deck"><div>{{current_result|safe}}</div></div>
8 <input type="hidden" name="{{name}}" id="{{html_id}}" value="{{current_id}}" />
9 <script type="text/javascript">
10 jQuery(document).ready(function($){{% block script %}
11 $("#{{html_id}}_text").autocomplete('{{lookup_url}}', {
12 max: 100,
13 width: 320,
14 formatItem: function(row) { return row[2]; },
15 formatResult: function(row) { return row[1]; },
16 dataType: "text"
17 });
18 function receiveResult(event, data) {
19 prev = $("#{{html_id}}").val();
20 if(prev) {
21 kill_{{ func_slug }}(prev);
22 }
23 $("#{{html_id}}").val(data[0]);
24 $("#{{html_id}}_text").val("");
25 addKiller_{{ func_slug }}(data[1],data[0]);
26 $("#{{html_id}}_on_deck").trigger("added");
27 }
28 $("#{{html_id}}_text").result(receiveResult);
29 function addKiller_{{func_slug}}(repr,id) {
30 kill = "<span class='iconic supprimer' id='kill_{{ html_id }}'>supprimer</span> ";
31 if(repr){
32 $( "#{{html_id}}_on_deck" ).empty();
33 $( "#{{html_id}}_on_deck" ).append( "<div><span>" + repr + "</span>" + kill + "</div>");
34 } else {
35 $( "#{{html_id}}_on_deck > div" ).append(kill);
36 }
37 $("#kill_{{ html_id }}").click(function() { return function(){
38 kill_{{func_slug}}();
39 $("#{{html_id}}_on_deck").trigger("killed");
40 }}() );
41 }
42 function kill_{{func_slug}}() {
43 $("#{{html_id}}").val( '' );
44 $( "#{{html_id}}_on_deck" ).children().fadeOut(1.0).remove();
45 }
46 if($("#{{ html_id }}").val()) { // add X for initial value if any
47 addKiller_{{ func_slug }}(null,$("#{{ html_id }}").val());
48 }
49 $("#{{ html_id }}").bind('didAddPopup',function(event,id,repr) {
50 data = Array();
51 data[0] = id;
52 data[1] = repr;
53 receiveResult(null,data);
54 });
55 {% block extra_script %}{% endblock %}
56 {% endblock %}});
57 </script>