{include file="public/header" /}





<div class="page">
    <form id="add_form" method="post">
        <dl>
            <dt>{$Think.lang.gadmin_name}</dt>
            <dd>
                <input id="gname" name="gname" value="{$ginfo.gname}" class="input-txt" type="text">
                <span class="err"></span>
            </dd>
        </dl>
        <table class="ds-default-table nomargin">
            <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>
                {foreach name="limit" item="v" key="k" }
                <tr>
                    <td>
                        <label style="width:100px">{$v.nav|default=''}</label>
                        <input id="limit{$k}" type="checkbox" onclick="selectLimit('limit{$k}')">
                        <label for="limit{$k}"><b>{$v.name}</b>&nbsp;&nbsp;</label>
                        {foreach name="$v.child" item="xv" key="xk" }
                        <label>
                            <input dstype="limit{$k}" class="limit{$k}" type="checkbox" name="permission[]" value="{$xv.action}" <?php if(in_array(substr($xv['action'],0,($t=strpos($xv['action'],'|'))?$t:100),$ginfo['glimits'])){ echo "checked=\"checked\""; }?> >{$xv.name}&nbsp;
                        </label>
                       {/foreach}
                    </td>
                </tr>
                {/foreach}
            </tbody>
        </table>

        <dl>
            <dt></dt>
            <dd><a href="JavaScript:void(0);" class="btn" id="submitBtn">{$Think.lang.ds_confirm_submit}</a></dd>
        </dl>


    </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: ADMINSITEURL+'/Admin/ajax.html?branch=check_gadmin_name&gid={$ginfo.gid}',
                                                    type: 'get',
                                                    data: {
                                                        gname: function() {
                                                            return $('#gname').val();
                                                        }
                                                    }
                                                }
                                            }
                                        },
                                        messages: {
                                            gname: {
                                                required: '{$Think.lang.ds_none_input}',
                                                remote: '{$Think.lang.admin_add_admin_not_exists}'
                                            }
                                        }
                                    });
                                });
</script>