<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
</head>
<style>
	.tablelink{margin-right:10px;}
</style>
<body>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/role/adminRoleList.html}" method="post">
	<ul class="seachform">
		<li>
			<label>角色名称/用户呢称</label>
			<input name="name" type="text" class="scinput" th:value="${search.get('name')}"/>
			<input type="hidden" id="id" name="id" th:value="${search.get('id')}"/>
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
				<ul class="toolbar">
					<li class="click"><span><img style="width: 24px;height: 24px" th:src="@{/static/sys/images/select.png}" /></span>选择</li>
				</ul>
		</li>
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th style="width: 50px;"><input name="checkboxlist" type="checkbox"/></th>
		        <th>角色名称</th>
		        <th>角色说明</th>
		        <th>创建时间</th>
		        <th>更新时间</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				<td> <input name="selectlist" type="checkbox" th:data-id="${item.get('id')}" /> </td>
				<td th:text="${item.get('name')}"></td>
				<td th:text="${item.get('memo')}" ></td>
				<td th:text="${#calendars.format(item.get('create_time'),'yyyy-MM-dd HH:mm:ss')}" ></td>
				<td th:text="${#calendars.format(item.get('update_time'),'yyyy-MM-dd HH:mm:ss')}" ></td>
			</tr>
		</tbody>
	</table>
	<!-- 分页 -->
	<div class="pagin">
    	<div class="message">共<i class="blue">[[${page.rowCnt}]]</i>条记录，当前显示第&nbsp;<i class="blue">[[${page.pageNo }]]&nbsp;</i>页</div>
    	<div th:utext='${listNavigatHtml}' th:remove="tag" ></div>
   	</div>
</div>
</body>
<script type="text/javascript">

$(function(){
	 checkNode();
	 $('[name=checkboxlist]').click(function() {
         checkAll();
     });
})
function checkAll(){
	$.each($('[name=selectlist]'), function () {
		   if($(this).prop('checked')){
			  $(this).prop('checked', false);
		   }else{
			   $(this).prop('checked', true);
		   } 
   });
	
}

$('ul.toolbar li.click').click(function () {
	var selectIds=[];
	 $.each($('[name=selectlist]'), function () {
		 if ($(this).prop('checked')) {
		 var id = $(this).attr('data-id');
		 selectIds.push(id);
		 }
    });
	 if(selectIds.length==0){
		 selectIds.push('');
	 }
	 var url="[[${sysUrl}]]/sys/role/saveAdminRole";
	 var params ={
	            id : $("#id").val(),
	            roleIds : selectIds
	        };
	$.post(url,params,function(data){
		if(data.meta.success){
           window.close();
		}
	});
	
});


function checkNode(){
	var url ='[[${sysUrl}]]/sys/role/getAdminRole';
	var params = {'id' : $('#id').val()} ;
	$.post(url,params,function(data){
			if(data.length>0){
				for(var x=0; x<data.length; x++){
					 $.each($('[name=selectlist]'), function () {
						 var id =  $(this).attr('data-id');
						   if(id==data[x]){
							  $(this).prop('checked', true);
						   }
						 });
			         }
		     }
		});
}
</script>
</html>