refact ergo + page perso (vide)
[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);">
5 <img src="{{ admin_media_prefix }}img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another">
6 </a>
7 {% endif %}
8 {% block help %}{% endblock %}
9 <div id="{{html_id}}_on_deck" class="results_on_deck">
10 <div>{{current_result|safe}}</div>
11 </div>
12 <input type="hidden" name="{{name}}" id="{{html_id}}" value="{{current_id}}" />
13 <script type="text/javascript">
14 jQuery(document).ready(function($){{% block script %}
15 $("#{{html_id}}_text").autocomplete('{{lookup_url}}', {
16 max: 100,
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) {
34 kill = "<span class='iconic supprimer' id='kill_{{ html_id }}'>supprimer</span> ";
35 if(repr){
36 $( "#{{html_id}}_on_deck" ).empty();
37 $( "#{{html_id}}_on_deck" ).append( "<div><span>" + repr + "</span>" + kill + "</div>");
38 } else {
39 $( "#{{html_id}}_on_deck > div" ).append(kill);
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>