fix package
[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 width: 320,
13 formatItem: function(row) { return row[2]; },
14 formatResult: function(row) { return row[1]; },
15 dataType: "text"
16 });
17 function receiveResult(event, data) {
18 prev = $("#{{html_id}}").val();
19 if(prev) {
20 kill_{{ func_slug }}(prev);
21 }
22 $("#{{html_id}}").val(data[0]);
23 $("#{{html_id}}_text").val("");
24 addKiller_{{ func_slug }}(data[1],data[0]);
25 $("#{{html_id}}_on_deck").trigger("added");
26 }
27 $("#{{html_id}}_text").result(receiveResult);
28 function addKiller_{{func_slug}}(repr,id) {
29 kill = "<span class='iconic supprimer' id='kill_{{ html_id }}'>supprimer</span> ";
30 if(repr){
31 $( "#{{html_id}}_on_deck" ).empty();
32 $( "#{{html_id}}_on_deck" ).append( "<div><span>" + repr + "</span>" + kill + "</div>");
33 } else {
34 $( "#{{html_id}}_on_deck > div" ).append(kill);
35 }
36 $("#kill_{{ html_id }}").click(function() { return function(){
37 kill_{{func_slug}}();
38 $("#{{html_id}}_on_deck").trigger("killed");
39 }}() );
40 }
41 function kill_{{func_slug}}() {
42 $("#{{html_id}}").val( '' );
43 $( "#{{html_id}}_on_deck" ).children().fadeOut(1.0).remove();
44 }
45 if($("#{{ html_id }}").val()) { // add X for initial value if any
46 addKiller_{{ func_slug }}(null,$("#{{ html_id }}").val());
47 }
48 $("#{{ html_id }}").bind('didAddPopup',function(event,id,repr) {
49 data = Array();
50 data[0] = id;
51 data[1] = repr;
52 receiveResult(null,data);
53 });
54 {% block extra_script %}{% endblock %}
55 {% endblock %}});
56 </script>