[#2245] Liste des DAE finalisées
[auf_rh_dae.git] / project / templates / autocompleteselect.html
CommitLineData
3121c13c
OL
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">
10jQuery(document).ready(function($){{% block script %}
11 $("#{{html_id}}_text").autocomplete('{{lookup_url}}', {
65fcba3a 12 max: 100,
3121c13c
OL
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) {
680db452 30 kill = "<span class='iconic supprimer' id='kill_{{ html_id }}'>supprimer</span> ";
3121c13c
OL
31 if(repr){
32 $( "#{{html_id}}_on_deck" ).empty();
680db452 33 $( "#{{html_id}}_on_deck" ).append( "<div><span>" + repr + "</span>" + kill + "</div>");
3121c13c 34 } else {
680db452 35 $( "#{{html_id}}_on_deck > div" ).append(kill);
3121c13c
OL
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>