{include file="public/header" /}
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>



<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>权限设置</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>


    <form id="add_form" method="post">
        <div  class="ncap-form-default">
            <dl>
                <dt>{$Think.lang.gadmin_name}</dt>
                <dd>
                    <input id="gname" name="gname" value="" class="input-txt" type="text">
                    <span class="err"></span>
                </dd>
            </dl>
            <table class="ds-default-table">
                <thead>
                    <tr class="space">
                        <th> <input id="limitAll" id="limitAll" value="1" type="checkbox">&nbsp;&nbsp;{$Think.lang.admin_set_limt}</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach((array)$limit as $k => $v) { ?>
                    <tr>
                        <td>
                            <label style="width:100px"><?php echo (!empty($v['nav'])) ? $v['nav'] : '&nbsp;'; ?></label>
                            <input id="limit<?php echo $k;?>" type="checkbox" onclick="selectLimit('limit<?php echo $k;?>')">
                            <label for="limit<?php echo $k;?>"><b><?php echo $v['name'];?></b>&nbsp;&nbsp;</label>
                            <?php foreach($v['child'] as $xk => $xv) { ?>
                            <label><input nctype='limit' class="limit<?php echo $k;?>" type="checkbox" name="permission[]" value="<?php echo $xv['op'];?>">
                                <?php echo $xv['name'];?>&nbsp;</label>
                            <?php } ?>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <dl>
                <dt></dt>
                <dd><a href="JavaScript:void(0);" class="btn" id="submitBtn">确认提交</a></dd>
            </dl>
        </div>


    </form>




</div>

<script>
                                function selectLimit(name) {
                                    if ($('#'+name).prop('checked')) {
                                        $('.'+name).prop('checked', true);
                                    } else {
                                        $('.'+name).prop('checked', false);
                                    }
                                }
                                $(function() {
                                    //按钮先执行验证再提交表单
                                    $("#submitBtn").click(function() {
                                        if ($("#add_form").valid()) {
                                            $("#add_form").submit();
                                        }
                                    });
                                    $('#limitAll').on('click', function() {
                                        if ($(this).prop('checked')) {
                                            $(this).parents('table').find('input:checkbox').prop('checked', true);
                                        } else {
                                            $(this).parents('table').find('input:checkbox').prop('checked', false);
                                        }
                                    });

                                    $("#add_form").validate({
                                        errorPlacement: function(error, element) {
                                            error.appendTo(element.nextAll('span.err'));
                                        },
                                        rules: {
                                            gname: {
                                                required: true,
                                                remote: {
                                                    url: ADMIN_URL+'/Admin/ajax.html?branch=check_gadmin_name',
                                                    type: 'get',
                                                    data: {
                                                        gname: function() {
                                                            return $('#gname').val();
                                                        }
                                                    }
                                                }
                                            }
                                        },
                                        messages: {
                                            gname: {
                                                required: '{$Think.lang.nc_none_input}',
                                                remote: '{$Think.lang.admin_add_admin_not_exists}'
                                            }
                                        }
                                    });
                                });
</script>