<?php
/**
 * @var \yii\web\View $this
 * @var array $roleList
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>BIT System 后台管理平台</title>
    <?= $this->render('/common/css_js_main') ?>
</head>
<body id="main">
<div class="main-nav"> <span class="fn-left">添加管理员</span> <span class="fn-right"><a href="javascript:history.go(-1);"><i class="icon-chevron-left"></i>返回</a></span>
    <div class="fn-clear"></div>
</div>
<div class="main-content">
    <div class="form-or-table">
        <form class="form-horizontal" id="validateForm" action="/cp/admin/save" method="post">
            <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>" value="<?= Yii::$app->request->getCsrfToken() ?>" />
            <fieldset>
                <div class="blank15"></div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>用户名</label>
                    <div class="controls">
                        <input type="text" id="username" name="username" class="span5" title="用户名只允许包含中文、英文、数字和下划线" autocomplete="off"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>密码</label>
                    <div class="controls">
                        <input type="password" id="password" name="password" class="span3" autocomplete="off"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>重复密码</label>
                    <div class="controls">
                        <input type="password" id="rePassword" name="rePassword" class="span3" autocomplete="off"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>电子邮箱</label>
                    <div class="controls">
                        <input type="text" id="email" name="email" class="span5"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="inlineCheckboxes">设置</label>
                    <div class="controls">
                        <label class="checkbox inline">
                            <input type="checkbox" name="is_account_enabled" value="1" id="is_account_enabled" checked="checked" /> 启用
                        </label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">部门</label>
                    <div class="controls">
                        <input type="text" id="department" name="department" class="span5" />
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">姓名</label>
                    <div class="controls">
                        <input type="text" id="name" name="name" class="span5" />
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="inlineCheckboxes"><span class="must-input">*</span>管理角色</label>
                    <div class="controls">
                        <?php foreach ($roleList as $k => $v) : ?>
                            <label class="role_id inline">
                                <input type="radio" id="role_<?= $v['id'] ?>" name="role_id" value="<?= $v['id'] ?>" /> <?= $v['name'] ?>
                            </label>
                        <?php endforeach; ?>
                        <span for="role_id" generated="true" class="error" style="display: none;">请选择管理角色!</span>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="textarea">描述</label>
                    <div class="controls">
                        <textarea id="textarea" name="description" rows="6" ></textarea>
                    </div>
                </div>
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary"><i class="icon-upload"></i> 提交</button>
                    <button type="reset" class="btn" onclick="javascript:history.go(-1);"><i class="icon-repeat"></i> 返回</button>
                </div>
            </fieldset>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
$(function() {
    var $validateForm = $("#validateForm");

    // 表单验证
    $validateForm.validate({
        rules: {
            username: {
                required: true,
                username: true,
                minlength: 2,
                maxlength: 20,
                remote: "/cp/admin/check-username"
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 20
            },
            rePassword: {
                required: true,
                equalTo: "#password"
            },
            email: {
                required: true,
                email: true
            },
            role_id: "required"
        },
        messages: {
            username: {
                required: "请填写用户名!",
                username: "用户名只允许包含中文、英文、数字和下划线!",
                minlength: "用户名必须大于等于2!",
                maxlength: "用户名必须小于等于20!",
                remote: "用户名已存在!"
            },
            password: {
                required: "请填写密码!",
                minlength: "密码必须大于等于6!",
                maxlength: "密码必须小于等于20!"
            },
            rePassword: {
                required: "请填写重复密码!",
                equalTo: "两次密码输入不一致!"
            },
            email: {
                required: "请填写E-mail!",
                email: "E-mail格式不正确!"
            },
            role_id: "请选择管理角色!"
        }
    });
});
</script>
</html>