{% extends 'base.html' %}
{% load bootstrap %}

{% block content %}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>填写用户信息</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" id="userForm" class="form-horizontal" action="">
                            {% csrf_token %}
                            <h2>账户</h2>
                            {{ form.username|bootstrap_horizontal }}
                            {{ form.name|bootstrap_horizontal }}
                            {{ form.email|bootstrap_horizontal }}
                            {{ form.groups|bootstrap_horizontal }}

                            <div class="hr-line-dashed"></div>
                            <h2>密码</h2>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-8 bottom-left" >
                                    生成重置密码连接，通过邮件发送给用户
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <h2>角色安全</h2>
                            <div class="form-group">
                                <label for="email" class="col-sm-2 control-label">Email<span class="red-fonts">*</span></label>
                                <div class="col-sm-8">
                                    <input id="email" name="email" type="email" placeholder="username@jumpserver.org" class="form-control" {% if error %}value="{{ email }}" {% endif %}>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group"><label class="col-sm-2 control-label">其它</label>
                                <div class="col-sm-2">
                                    <div class="checkbox i-checks">
                                        <label><input type="checkbox" value="0" name="extra" >禁用 </label>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <div class="checkbox i-checks">
                                        <label><input type="checkbox" value="1" name="extra" checked>发送邮件 </label>
                                    </div>
                                </div>
                            </div>
                            <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">取消</button>
                                    <button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block self_footer_js %}

<script>
$('#userForm').validator({
    timely: 2,
    theme: "yellow_right_effect",
    rules: {
        check_username: [/^[\w.]{3,20}$/, '大小写字母数字和下划线小数点'],
        type_m: function(element){
                    return  $("#M").is(":checked");
            }
    },
    fields: {
        "username": {
            rule: "required;check_username",
            tip: "输入用户名",
            ok: "",
            msg: {required: "必须填写!"}
        },
        "password": {
            rule: "required;length[6~50]",
            tip: "输入密码",
            ok: "",
            msg: {required: "必须填写!"}
        },
        "name": {
            rule: "required",
            tip: "姓名",
            ok: "",
            msg: {required: "必须填写"}
        },
        "email": {
            rule: "required",
            tip: "Email",
            ok: "",
            msg: {required: "必须填写"}
        }
    },
    valid: function(form) {
        form.submit();
    }
});


</script>
{% endblock %}