<!--{include file="<!--{$oapath}-->public/ins_page.tpl"}-->

<block name="content">
	<style>
		.wrap.tree_menu{
			height:500px;
			overflow-y: scroll;
		}
	</style>
	<div class="page-header">
	<h1>权限组管理</h1>
</div>
	<form id="form_search" name="form_search" method="post" action="">
		<div class="operate panel panel-default">
			<div class="panel-body">
				<div class="pull-left">
					<select name="eq_pid" id="eq_pid" class="form-control col-10" onchange="submit_search();">
						<option value="#">全部</option>
						<!--{foreach $groupList as $volist}-->
                                                      <option value="<!--{$volist.id}-->"><!--{$volist.name}--></option>
                                                <!--{/foreach}-->	
					</select>
				</div>
				<div class="pull-right">
					<a onclick="save()" class="btn btn-sm btn-primary">保存</a>
				</div>
			</div>
		</div>
	</form>
	<div class="row">
		<div class="col-sm-4 role_list">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th>ID</th>
						<th>名称</th>
					</tr>
				</thead>
				<tbody>
						<!--{foreach $list as  $key=>$parent}-->
						<tr id="<!--{$parent.id}-->"  id="data">
							<td><!--{$parent.name}--></td>
							<td>
                                                            <!--{if $parent.is_del=='0'}--> 
                                                                        启用
                                                           <!--{else}-->
                                                                        禁用
                                                            <!--{/if}-->
                                                        </td>
						</tr>
				 <!--{/foreach}-->  
				</tbody>
			</table>
		
		</div>
		<div class="col-sm-8 wrap">
			<form id="form_data" method="post" action="">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<input type="hidden" name="role_id" id="role_id">
				<input type="hidden" name="org_node_list" id="org_node_list">
				<input type="hidden" name="node_list" id="node_list">
				<div class="wrap tree_menu">
					<table class="table table-bordered">
						<tr>
							<th style="width:55%;text-align:center"><label class="inline pull-left">
								<input class="ace" type="checkbox" name="id-toggle-all" id="id-toggle-all" />
								<span class="lbl"></span></label>菜单</th>
							<th style="width:15%;text-align:center">读取</th>
							<th style="width:15%;text-align:center">修改</th>
							<th style="width:15%;text-align:center">管理</th>
						</tr>
					
                                                    <!--{foreach $node_list as  $key=>$data}-->
							<tr>
								<td class="tbody"><label>
									<input class="ace" type="checkbox"  name="node_id"  value="<!--{$data.id}-->" />
									<span class="lbl level<!--{$data.level}-->">&nbsp;<!--{$data.name}--></span></label></td>
                                                                      <!--   <!--{if $data.url!=''}--> 
                     
									<td class="text-center"><label class="inline">
										<input class="ace" type="checkbox" name="read[]" value="<!--{$data.id}-->" />
										<span class="lbl"></span></label></td>
									<td class="text-center"><label class="inline">
										<input class="ace" type="checkbox" name="write[]" value="<!--{$data.id}-->"/>
										<span class="lbl"></span></label></td>
									<td class="text-center"><label class="inline">
										<input class="ace" type="checkbox" name="admin[]" value="<!--{$data.id}-->"/>
										<span class="lbl"></span></label></td>
									  <!--{else}-->
									<td class="text-center">&nbsp;</td>
									<td class="text-center">&nbsp;</td>
									<td class="text-center">&nbsp;</td>
								  <!--{/if}-->-->
                                                                  <td class="text-center">&nbsp;</td>
									<td class="text-center">&nbsp;</td>
									<td class="text-center">&nbsp;</td>
							</tr>
					
                                                                                 <!--{/foreach}-->  
					</table>
				</div>
			</form>
		</div>
	</div>
</block>

					
				</div>
			</div>
		</div>
		<!--<iframe src="{:U('push/client')}" class="push" id="push"></iframe>-->
		<!-- Mainly scripts -->
		<script src="<!--{$oapath}-->Ins/js/jquery-2.1.1.js"></script>
		<script src="<!--{$oapath}-->Ins/js/bootstrap.min.js"></script>
		<script src="<!--{$oapath}-->Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
		<script src="<!--{$oapath}-->Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<!-- Custom and plugin javascript -->
		<script src="<!--{$oapath}-->Ins/js/inspinia.js"></script>
		<script src="<!--{$oapath}-->Ins/js/common.js"></script>
		<script src="<!--{$oapath}-->Ins/js/plugins/pace/pace.min.js"></script>
                
		<script src="<!--{$oapath}-->Ins/js/plugins/toastr/toastr.min.js"></script>
                <script src="<!--{$oapath}-->Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
                <script src="<!--{$oapath}-->Ins/js/plugins/bootbox/bootbox.min.js"></script>
		<include file="Layout:ins_plugin_js"/>
<block name="js">
	<script type="text/javascript">
		function save() {
			if ($("#role_id").val() == '') {
				ui_error("请选择权限组");
				return false;
			};
			$("#node_list").val('');
			$(".wrap .tree_menu input[name='node_id']:checked").each(function() {
				$("#node_list").val($("#node_list").val() + $(this).val() + ",");
			});
			sendForm("form_data", "oa.php?c=Role&a=set_node","oa.php?c=Role&a=node");
		};

		function showdata(result) {
			$(".wrap .tree_menu input").each(function() {
				$(this).prop("checked", false);
				//$(this).parents("td").removeClass("active");
			});
			for (var s in result.data) {
				$(".wrap .tree_menu input[name='node_id'][value=" + result.data[s].node_id + "]").prop("checked", "true");
				//$(".wrap .tree_menu input[name='node_id'][value=" + result.data[s].node_id + "]").parents("td").addClass("active");

				if (result.data[s].admin == 1) {
					$(".wrap .tree_menu input[name='admin[]'][value=" + result.data[s].node_id + "]").prop("checked", "true");
					//$(".wrap .tree_menu input[name='admin[]'][value=" + result.data[s].node_id + "]").parents("td").addClass("active");
				}
				if (result.data[s].write == 1) {
					$(".wrap .tree_menu input[name='write[]'][value=" + result.data[s].node_id + "]").prop("checked", "true");
					//$(".wrap .tree_menu input[name='write[]'][value=" + result.data[s].node_id + "]").parents("td").addClass("active");
				}
				if (result.data[s].read == 1) {
					$(".wrap .tree_menu input[name='read[]'][value=" + result.data[s].node_id + "]").prop("checked", "true");
					//$(".wrap .tree_menu input[name='read[]'][value=" + result.data[s].node_id + "]").parents("td").addClass("active");
				}
			};
			$("#org_node_list").val('');
			$(".wrap .tree_menu input[name='node_id']:checked").each(function() {;
				$("#org_node_list").val($("#org_node_list").val() + $(this).val() + ",");
			});
			$("#opmode").val("edit");
		};

		$(document).ready(function() {
			set_return_url();
			set_val('eq_pid', '<!--{$eq_pid}-->');
			$(".role_list tbody tr").click(function() {
				$(".role_list  tr").removeClass("active");
				$(this).attr("class", "active");
				$("#role_id").val($(this).attr("id"));
				sendAjax("oa.php?c=Role&a=get_node_list", "role_id=" + $(this).attr("id"), function(data) {
					showdata(data);
				});
				return false;
			});
		});
	</script>
</block>
	</body>
</html>
