{extend name="public:base" /}
{block name="header"}
<style type="text/css">
	label {
		font-weight: normal;
	}

	div.col-sm-2 {
		font-weight: bold;
		white-space: nowrap;
	}

	.col-sm-10 label {
		width: 120px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		margin-bottom: 0;
	}
</style>
{/block}
{block name="body"}

{include file="public/bread" menu="manager_index" title="管理员权限" /}

<div id="page-wrapper">
	<div class="page-header">管理员权限</div>
	<div id="page-content">
		<form action="{:url('manager.index/permision',array('id'=>$model['manager_id']))}" class="form-horizontal"
			method="post">
			<div class="text-muted">已禁用的权限需要先在角色管理中启用</div>
			<div class="card">
				<div class="card-header">全局权限</div>
				<div class="card-body">
					<label><input type="checkbox" name="global[]" value="edit"
							{$role->hasGlobalPerm('edit')?'':'disabled'} {if in_array('edit',$model['global'])
						}checked{/if} />&nbsp;编辑</label>
					<label><input type="checkbox" name="global[]" value="del"
							{$role->hasGlobalPerm('del')?'':'disabled'} {if
						in_array('del',$model['global'])}checked{/if} />&nbsp;删除</label>
				</div>
			</div>
			<div class="card mt-4 mb-4">
				<div class="card-header">详细权限&nbsp;&nbsp;<label><input type="checkbox"
							onclick="checkall(this)" />&nbsp;全选</label></div>

				<ul class="list-group list-group-flush">
					{foreach $perms as $key => $perm}
					<li class="list-group-item">
						<div class="row">
							<label class="col-2"><input type="checkbox"
									onclick="checkline(this)" />&nbsp;{$perm.title}</label>
							<div class="col-10">
								{foreach $perm.items as $k => $item}
								<label title="{$item}"><input type="checkbox" name="detail[]"
										{$role->hasPerm($key.'_'.$k)?'':'disabled'} value="{$key}_{$k}" {if
									in_array($key.'_'.$k,$model['detail'])}checked{/if} />&nbsp;{$item}</label>
								{/foreach}
							</div>
						</div>
					</li>
					{/foreach}
				</ul>
			</div>

			<div class="form-group">
				<div class="col-sm-10 col-sm-offset-2">
					<button class="btn btn-primary" type="submit">保存</button>
				</div>
			</div>


		</form>
	</div>
</div>
<script type="text/javascript">
	function checkall(src) {
		var checked = $(src).is(':checked');
		$('[name^=global]:not(:disabled)').prop('checked', checked);
		$('[name^=detail]:not(:disabled)').prop('checked', checked);
		$('[name^=checkline]:not(:disabled)').prop('checked', checked);
	}
	function checkline(src) {
		var checked = $(src).is(':checked');
		$(src).parents('li').find('[name^=detail]:not(:disabled)').prop('checked', checked);
	}
	$('input[name^=detail]').click(function () {
		var row = $(this).parents('li.list-group-item');
		var p = row.find('div.col-10');
		if (p.find(':checked').length == p.find('input').length) {
			row.find('label.col-2 input:not(:disabled)').prop('checked', true);
		} else {
			row.find('label.col-2 input').prop('checked', false);
		}
	});
	jQuery(function () {
		$('.detail-line').each(function () {
			var row = $(this);
			var p = row.find('div.col-10');
			if (p.find(':checked').length == p.find('input').length) {
				row.find('label.col-2 input:not(:disabled)').prop('checked', true);
			} else {
				row.find('label.col-2 input').prop('checked', false);
			}
		})
	});
</script>

{/block}