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


{% block content %}
    {% include 'nav_cat_bar.html' %}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-10">
                <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="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" id="userForm" class="form-horizontal" action="">
                            {% if error %}
                                <div class="alert alert-warning text-center">{{ error }}</div>
                            {% endif %}
                            {% if msg %}
                                <div class="alert alert-success text-center">{{ msg }}</div>
                            {% endif %}
                            <div class="form-group">
                                <div class="col-sm-8">
                                    <input id="user_id" name="user_id" type="text"  value="{{ user.id }}" style="display: none">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">姓名<span class="red-fonts">*</span></label>
                                <div class="col-sm-8">
                                    <input id="name" name="name" placeholder="Name" type="text" class="form-control" value="{{ user.name }}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label for="password" class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-8">
                                    <input id="password" name="password" placeholder="Password" type="password" class="form-control">
                                    <span class="help-block m-b-none">
                                        登陆web的密码, 不修改请留空
                                    </span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label for="ssh_key_pwd" class="col-sm-2 control-label">SSH密钥</label>
                                <div class="col-sm-8" style="border: none">
                                    <a value="{% url 'key_gen' %}?uuid={{ user.uuid }}" id="regen_ssh_key" class="form-control"> 重新生成</a>
                                    <span class="help-block m-b-none">
                                        重新生成密钥，需要重新下载并导入
                                    </span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <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="Email" class="form-control" value="{{ user.email }}" >
                                </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="submit">取消</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_pass: [/^\w+$/, '数字和字符']
    },

    fields: {
        "name": {
            rule: "required",
            tip: "姓名",
            ok: "",
            msg: {required: "必须填写"}
        },
        "email": {
            rule: "required",
            tip: "Email",
            ok: "",
            msg: {required: "必须填写"}
        }
    },
    valid: function(form) {
        form.submit();
    }
});

$("document").ready(function() {
    $("#regen_ssh_key").click(function () {
        alert('申请已提交，请等待，请勿重复提交');
        $.get(
                $(this).attr('value'),
                {},
                function(data){
                    alert(data)
                }
        )
    })
 })

</script>
{% endblock %}