{% 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="panel blank-panel">
                        <div class="panel-heading">
                            <div class="panel-options">
                                <ul class="nav nav-tabs">
                                    <li id="tab1" class=""><a href="/jperm/sys_user_list/" >查看系统用户</a></li>
                                    <li id="tab2" class="active"><a href="/jperm/sys_user_add/">添加系统用户</a></li>
                                </ul>
                            </div>
                        </div>

                        <div class="panel-body">
                            <div class="tab-content">
                                <div id="tab-default" class="tab-pane active">
                                    <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">
                                            <label for="username" class="col-sm-2 control-label">用户名<span class="red-fonts">*</span></label>
                                            <div class="col-sm-8">
                                                <input id="username" name="username" placeholder="Username" type="text" class="form-control" {% if error %}value="{{ username }}" {% endif %}>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="password" class="col-sm-2 control-label">密码<span class="red-fonts">*</span></label>
                                            <div class="col-sm-8">
                                                <input id="password" name="password" placeholder="Password" type="password" class="form-control" {% if error %}value="{{ password }}" {% endif %} >
                                                <span class="help-block m-b-none">通常在其它硬件上使用，服务器会使用自动生成的key</span>
                                            </div>

                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="" class="col-sm-2 control-label">推送资产组<span class="red-fonts">*</span></label>
                                            <div class="col-sm-4">
                                                <div>
                                                    <select id="asset_groups" name="asset_groups" class="form-control" size="12" multiple>
                                                        {% for asset_group in asset_group_all %}
                                                        <option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
                                                        {% endfor %}
                                                    </select>
                                                    <span class="help-block m-b-none">将在以上资产组服务器新建系统用户</span>
                                                </div>
                                            </div>

                                            <div class="col-sm-1">
                                                <div class="btn-group" style="margin-top: 42px;">
                                                    <button type="button" class="btn btn-white" onclick="move('asset_groups', 'asset_groups_select')"><i class="fa fa-chevron-right"></i></button>
                                                    <button type="button" class="btn btn-white" onclick="move('asset_groups_select', 'asset_groups')"><i class="fa fa-chevron-left"></i> </button>
                                                </div>
                                            </div>

                                            <div class="col-sm-3">
                                                <div>
                                                    <select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="12"  multiple>

                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="comment" class="col-sm-2 control-label">备注<span class="red-fonts">*</span></label>
                                            <div class="col-sm-8">
                                                <input id="comment" name="comment" placeholder="Comment" type="text" class="form-control" {% if error %}value="{{ comment }}" {% endif %} >
                                            </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>
            </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: "必须填写!"}
        }
    },
    valid: function(form) {
        form.submit();
    }
});


</script>
{% endblock %}