<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript" src="IDC/js/SetPower.js"></script>
<script type="text/javascript">
$(function()
{
	//관리자 권한 얻어오기.
	$(document).ready(function()
	{
		$(".power").each(function()
		{
			$(this).parents("tr").find("select").val($(this).attr("power"));
		});
	});
	
	//삭제하기
	$(".delBtn").click(function()
	{
		var id ="&mem_id="+$(this).attr("value");
		window.location="IdcMemberDelete.main?"+id;
	});
	
	
	//수정하기
	$(".modiBtn").click(function()
	{
		var a=0;
		a= $(this).attr("value");
		var id = $(this).parents("tr").children().html();
		var url="IdcMemberPowerModify.main?curPage=1";
		var power=[];
		var tdid=$(this).parents("tr").find("#power").val();
		url+="&power="+tdid+"&id="+id;
		var pCheck=".pCheck"+a;
		var powerCheck = $(pCheck);
		
		for(var i=0;i<powerCheck.length;i++)
		{
//			alert($(powerCheck[i]).prop("checked"));
		}
		
		for(var i=0;i<powerCheck.length;i++)
		{
			if($(powerCheck[i]).prop("checked"))
			{
				power[i]="&power2="+"o";
			}
			else
			{
				power[i]="&power2="+"x";
			}
			url+=power[i];
		}
		window.location=url;
	});
});
</script>
<!-- 여기가 본 페이지이다 -->
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				<h4>
					<i class="fa fa-desktop fa-fw"></i> 멤버 리스트
				</h4>
			</div>
			<div class="panel-body">
				<div class="row">
					<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
						<form action="IdcMemberListForm.main" method="POST">
							<div class="input-group">
								<input class="form-control" type="text" name="search" value=${searchContext }> <span class="input-group-btn">
									<button class="btn btn-info btn-outline" type="button">검색</button>
								</span>
							</div>
						</form>	
					</div>
					<div class="col-lg-offset-8 col-md-offset-8 col-sm-offset-8 col-xs-offset-8 col-lg-1 col-md-1 col-sm-1 col-xs-1">
						<div class="input-group">
							<span class="input-group-btn">
								<a href="IdcJoinForm.main" class="btn btn-info btn-outline">회원가입</a>
							</span>
						</div>
					</div>
				</div>
				<!-- row -->
				<div class="table-responsive">
					<table class="table table-bordered table-hover table-striped">
						<thead>
							<tr>
								<td>아이디</td>
								<td>이름</td>
								<td>사원번호</td>
								<td>직급</td>
								<td>연락처</td>
								<td>위치</td>
								<td>권한</td>
								<td>권한2</td>
								<td>가입일</td>
								<td>기타</td>
								<td>수정</td>
								<td>삭제</td>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${memberList }" var="temp" varStatus="i2">
								<tr>
									<td>${temp.id }</td>
									<td>${temp.name }</td>
									<td>${temp.num }</td>
									<td>${temp.rank }</td>
									<td>${temp.phone }</td>
									<td>${temp.location }</td>
									<td class="power" power="${temp.power }">
										<select id="power" name="power" value="${temp.power }">
											<option value="0">일반</option>
											<option value="1">관리자</option>
										</select>
									</td>
									<td class="pContent">
										<c:forEach begin="0" end="9" varStatus="i">
											${i.count }. 
											<c:if test="${temp.getPower[i.count-1]=='o' }">
												<input type="checkbox" class="pCheck pCheck${i2.count }" name="power" value="${i.count }"
																data-toggle="popover-top"
																data-trigger="hover"
																data-content="권한설정 ${i.count} 입니다. " 
																data-original-title="${i.count }권한" checked="checked">
											</c:if>
											<c:if test="${temp.getPower[i.count-1]=='x' }">
												<input type="checkbox" class="pCheck pCheck${i2.count }" name="power" value="${i.count }"
																data-toggle="popover-top"
																data-trigger="hover"
																data-content="권한설정 ${i.count} 입니다. " 
																data-original-title="${i.count }권한">
											</c:if>
										</c:forEach>
									</td>
									<td>${temp.join_date }</td>
									<td>${temp.note }</td>
									<td><button type="button" class="btn btn-info modiBtn" value="${i2.count }" >수정</button>
									<td><button type="button" class="btn btn-danger delBtn"value="${temp.id }">삭제</button></td>
								</tr>
							</c:forEach>
						</tbody>
						<tfoot>
						</tfoot>
					</table>
				</div>
				<!-- table-responsive -->
				<div>
					<ul class="pagination" style="margin: 0px;">
						<li><a class="btn btn-outline btn-default"
							href="IdcMemberListForm.main?curPage=1"> 
							<i class="fa fa-angle-double-left "></i>
						</a></li>
						<c:forEach var="i" begin="${firstPage }" end="${pageCnt }">
							<li><a class="btn btn-outline btn-defualt"
								href="IdcMemberListForm.main?curPage=${i }">${i}</a></li>
						</c:forEach>
						<li><a class="btn btn-outline btn-default"
							href="IdcMemberListForm.main?curPage=${pageCnt }"> 
							<i class="fa fa-angle-double-right "></i>
						</a>
						</li>
					</ul>
					<!-- ul -->
				</div>
				<!-- UL DIV -->
			</div>
			<!-- panel-body -->
		</div>
		<!-- panel panel-default -->
	</div>
	<!-- col-lg-12 -->
</div>
<!-- row -->
<!-- /#page-wrapper -->
