{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><input class="btn" type="submit" value="{$Think.lang.ds_submit}"/></dd>
        </dl>


    </form>



</div>


<script>
                                function selectLimit(name) {
                                    if ($('#'+name).prop('checked')) {
                                        $('.'+name).prop('checked', true);
                                    } else {
                                        $('.'+name).prop('checked', false);
                                    }
                                }
                                $(function() {
                                    $('#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>