<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    //$form->get('admin_group_id')->setEmptyOption('请选择管理员组');

    $form->get('adminName')->setAttributes([
        'placeholder' => $this->translate('管理员账号')
    ]);
    if(isset($user) && $user->getAdminId()) {
        $form->get('adminName')->setAttributes([
            'disabled' => 'disabled'
        ]);
    }

    $form->get('adminEmail')->setAttributes([
        'placeholder' => $this->translate('电子邮箱')
    ]);
    $form->get('adminPassword')->setAttributes([
        'placeholder' => $this->translate('管理员密码')
    ]);
    $form->get('adminComPassword')->setAttributes([
        'placeholder' => $this->translate('确认密码')
    ]);
    ?>
    <?= $this->form()->openTag($form); ?>
    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('admin');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?=$this->translate('返回管理员列表')?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?=$this->translate('保存管理员信息')?></button>
            <?=(isset($user) ? $this->HelpUrl('adminEdit') : $this->HelpUrl('adminAdd'))?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?=((isset($user) && $user->getAdminId()) ? $this->translate('编辑管理员') : $this->translate('添加管理员'))?></h3>
                    </div>

                        <div class="box-body">
                            <?= $this->formElementErrors($form->get('dberp_csrf'), ['class'=>'error-message']); ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?=$this->translate('管理员组')?><span class="must_add_value">*</span></label>
                                <div class="col-sm-3">
                                    <?= $this->formElement($form->get('adminGroupId')); ?>
                                    <?= $this->formElementErrors($form->get('adminGroupId'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?=$this->translate('管理员账号')?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?= $this->formElement($form->get('adminName')); ?>
                                    <?= $this->formElementErrors($form->get('adminName'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?=$this->translate('电子邮箱')?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?= $this->formElement($form->get('adminEmail')); ?>
                                    <?= $this->formElementErrors($form->get('adminEmail'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <?php if(!isset($user)) { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?=$this->translate('管理员密码')?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?= $this->formElement($form->get('adminPassword')); ?>
                                    <?= $this->formElementErrors($form->get('adminPassword'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?=$this->translate('确认密码')?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?= $this->formElement($form->get('adminComPassword')); ?>
                                    <?= $this->formElementErrors($form->get('adminComPassword'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <?php } ?>
                            <?php if(!isset($this->user) || (isset($this->user) and $this->user->getAdminId() != 1)) { ?>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?=$this->translate('状态')?></label>
                                    <div class="col-sm-6">
                                        <div class="checkbox">
                                            <label>
                                                <?= $this->formElement($form->get('adminState')); ?> <?=$this->translate('启用')?>
                                                <?= $this->formElementErrors($form->get('adminState'), ['class'=>'error-message']); ?>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>

                        <div>
                            <div class="box-footer">
                                <?= $this->formElement($form->get('dberp_csrf')); ?>
                                <button type="submit" class="btn btn-primary col-md-offset-2"><i class="fa fa-check"></i> <?=$this->translate('保存管理员信息')?></button>
                            </div>
                        </div>

                </div>
            </div>
        </div>

    </section>
    <?= $this->form()->closeTag(); ?>
</div>
<script>
    $(document).ready(function() {
        $("#<?=$form->getName()?>").validate({
            rules: {
                adminGroupId: {
                    required: true,
                    min:1
                },
                adminEmail: {
                    required: true,
                    email: true
                }
                <?php if(!isset($user)) { ?>
                ,
                adminName: {
                    required: true
                },
                adminPassword: {
                    required: true
                },
                adminComPassword: {
                    required: true,
                    equalTo: "#adminPassword"
                }
                <?php } ?>
            },
            messages: {
                adminGroupId: {
                    required: "<?=$this->translate('请选择管理员组')?>",
                    min: "<?=$this->translate('请选择管理员组')?>"
                },
                adminEmail: {
                    required: "<?=$this->translate('请输入管理员邮箱')?>",
                    email: "<?=$this->translate('请输入正确的邮箱地址')?>"
                }
                <?php if(!isset($user)) { ?>
                ,
                adminName: {
                    required: "<?=$this->translate('请输入管理员账号')?>"
                },
                adminPassword: {
                    required: "<?=$this->translate('请输入管理员密码')?>"
                },
                adminComPassword: {
                    required: "<?=$this->translate('请输入确认密码')?>",
                    equalTo: "<?=$this->translate('两次输入的密码不一致')?>"
                }
                <?php } ?>
            }
        });
    });
</script>