<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-horizontal" id="groupFrom" action="<?= site_url('admin/group/edit') ?>" method="post">
            <div class="btn-group pull-right">
                <button class="btn btn-primary" type="submit">
                    <i class="fa fa-save"></i>
                </button>
            </div>
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#home" role="tab" data-toggle="tab">增加分组</a></li>
            </ul>

            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="home">
                    <div class="form-group">
                        <label for="inputName" class="col-sm-2 control-label">分组名称</label>
                        <div class="col-sm-10">
                            <input type="text" data-required="true" class="form-control" name="name" placeholder="NAME" value="<?=isset($group)?$group['name']:''?>">
                            <?php if (isset($group)):?>
                            <input type="hidden" name="id" value="<?=$group['id']?>" />
                            <?php endif;?>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="<?= THEMEPATH ?>/js/validator.js"></script>

<script type="text/javascript">
    $(function() {
        $('#groupFrom').formValidator({
            sending:{
                type: 'ajax',
                success: function (data) {
                    var e = $.parseJSON(data);
                    if (e.error) {
                        show_error({'message': e.error});
                    } else {
                        ajax_dialog.close();
                        show_error(e.success);
                        $('#groupTable').DataTable().ajax.url("<?= site_url('/admin/group/table/') ?>").load();
                    }
                },
                error: function () {
                    show_error('提交表单失败！');
                }
            }
        });
    });
</script>