{% extends "admin/change_form.html" %}
{% load i18n admin_modify staticfiles %}
{% block content %}{{ block.super }}
<div>
<form action="{% url 'ldap_search' %}" method="post" id="ldap_search_form">
<label for="req_cn_input">Search for LDAP CN:</label>
<input type="text" id="req_cn_input" size="40" name="req_cn">
<input value="Search LDAP" class="default" name="_search_ldap" id="search_ldap_submit" type="submit">
</form>
<p class="help">Search for an LDAP OU CN, then click the CN result to add it to
the Org Unit box above.</p>
</div>
<div id="ldap_search_results"><ul id="ldap_results_list"></ul></div>
{% block ldap_scripts %}
<script type="text/javascript">
    $(document).ready(function()  {
        $("#search_ldap_submit").click(function() {
            var ldap_search_data = $("#ldap_search_form").serialize();
            $.post('{% url 'ldap_search' %}', ldap_search_data,
                function(data){
                    arr = $.map(eval(data), function(n, i){
                        return '<li><a class="cn_link" href="#">' + n + '</a></li>'
                        });
                    $("#ldap_results_list").html(arr.join(""));
                    $("a.cn_link").click(function() {
                        $("#id_org_unit").text($(this).html());
                    });
                });
            return false;
        });
    });
</script>
{% endblock %} 
{% endblock %}
