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