{% extends '_base_create_update.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap3 %}
{% block form %}
    {% if form.non_field_errors %}
         <div class="alert alert-danger">
            {{ form.non_field_errors }}
         </div>
    {% endif %}
    <form method="post" class="form-horizontal" action="" enctype="multipart/form-data">
        {% csrf_token %}
        <h3>{% trans 'Account' %}</h3>
        {% bootstrap_field form.name layout="horizontal" %}
        {% bootstrap_field form.username layout="horizontal" %}
        {% bootstrap_field form.email layout="horizontal" %}
        {% bootstrap_field form.groups layout="horizontal" %}

        <div class="hr-line-dashed"></div>

        <h3>{% trans 'Auth' %}</h3>
        {% block password %}{% endblock %}
        {% bootstrap_field form.mfa_level layout="horizontal" %}
        {% bootstrap_field form.source layout="horizontal" %}

        <div class="hr-line-dashed"></div>
        <h3>{% trans 'Security and Role' %}</h3>
        {% bootstrap_field form.role layout="horizontal" %}
        <div class="form-group {% if form.date_expired.errors %} has-error {% endif %}" id="date_5">
            <label for="{{ form.date_expired.id_for_label }}" class="col-sm-2 control-label">{{ form.date_expired.label }}</label>
            <div class="col-sm-9">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    {% if form.errors %}
                    <input id="{{ form.date_expired.id_for_label }}" name="{{ form.date_expired.html_name }}" type="text" class="form-control"  value="{{ form.date_expired.value }}">
                    {% else %}
                    <input id="{{ form.date_expired.id_for_label }}" name="{{ form.date_expired.html_name }}" type="text" class="form-control"  value="{{ form.date_expired.value|date:'Y-m-d H:i' }}">
                    {% endif %}
                </div>
                <span class="help-block ">{{ form.date_expired.errors }}</span>
            </div>
         </div>
        <div class="hr-line-dashed"></div>
        <h3>{% trans 'Profile' %}</h3>
        {% bootstrap_field form.phone layout="horizontal" %}
        {% bootstrap_field form.wechat layout="horizontal" %}
        {% bootstrap_field form.comment layout="horizontal" %}
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-2">
                <button class="btn btn-white" type="reset">{% trans 'Reset' %}</button>
                <button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
            </div>
        </div>
    </form>

{% endblock %}
{% block custom_foot_js %}
    <script src="{% static 'js/plugins/datepicker/bootstrap-datepicker.js' %}"></script>
    <script src="{% static 'js/plugins/datepicker/bootstrap-datepicker.zh-CN.min.js' %}"></script>
    <script type="text/javascript" src='{% static "js/plugins/daterangepicker/moment.min.js" %}'></script>
    <script type="text/javascript" src='{% static "js/plugins/daterangepicker/daterangepicker.min.js" %}'></script>
    <link rel="stylesheet" type="text/css" href={% static "css/plugins/daterangepicker/daterangepicker.css" %} />

    <script>
        var role_id = '#' + '{{ form.role.id_for_label }}';
        var groups_id = '#' + '{{ form.groups.id_for_label }}';
        function fieldDisplay(){
            var role = $(role_id).val();
            if (role === 'Auditor'){
                $(groups_id).closest('.form-group').addClass('hidden');
            }
            else {
                $(groups_id).closest('.form-group').removeClass('hidden');
            }}

        $(document).ready(function () {
            $('.select2').select2();
            initDateRangePicker('#id_date_expired');
            var mfa_radio = $('#id_mfa_level');
            mfa_radio.addClass("form-inline");
            mfa_radio.children().css("margin-right","15px");
            fieldDisplay()
        }).on('change', role_id, function(){
            fieldDisplay();
        })
    </script>
{% endblock %}
