<%@page import="kcg.imis.cmmn.CommConstants"%>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c"         uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form"      uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>
<%@ taglib prefix="spring"    uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="ckeditor" uri="http://ckeditor.com" %>
<c:set var="registerFlag" value="${registerFlag}"/>
<form:form commandName="boardVO" id="detailForm" name="detailForm" enctype="multipart/form-data">
	<form:hidden path="bdIdx"/>
	<form:hidden path="bbsId" value="${boardVO.bbsId}"/>
	<c:if test="${registerFlag == 'reply'}">
		<input type="hidden" name="bdIdxGrp" value="${boardVO.bdIdxGrp}"/>
	</c:if>

   	<div id="table">
	   	<table class="tbl_add">
	   		<colgroup>
	   			<col width="180"/>
	   			<col width="320"/>
	   			<col width="180"/>
	   			<col width="320"/>
	   		</colgroup>
	   		<tr>
	  			<th><label for="rgsde">그룹</label></th>
	  			<td><c:out value="${userVO.place2Str}"/></td>
	  			<th><label for="writer"><spring:message code="board.view.writer" /></label></th>
	  			<td><c:out value="${userVO.name}"/> <c:out value="${userVO.dutyStr}"/></td>
	  		</tr>
	   		<tr>
	   			<th><label for="title"><spring:message code="board.view.title" /></label></th>
	   			<td colspan="3">
	   				<form:input path="bdSubject" maxlength="50" cssClass="txt"/>	   				
	   			</td>
	   		</tr>
	   		<tr>
	   			<th><label for="object">목적</label></th>
	   			<td colspan="3">
	   				<form:input path="bdObject" maxlength="50" cssClass="txt"/>	   				
	   			</td>
	   		</tr>
	   		<tr>
	   			<th><label for="national">수집대상국</label></th>
	   			<td colspan="3">
	   				<form:input path="bdNational" maxlength="50" cssClass="txt"/>	   				
	   			</td>
	   		</tr>
	   		<tr>
	   			<th><label for="contents"><spring:message code="board.view.attach" /></label></th>
	   			<td colspan="3">
	   			
   					<c:choose>
				       	<c:when test="${registerFlag != 'modify'}">
							<p><input type="file" name="<%=CommConstants.FILE_TYPE_DOC%>1" class="input_file" size="60" /></p>
   							<p><input type="file" name="<%=CommConstants.FILE_TYPE_DOC%>2" class="input_file" size="60" /></p>
   							<p><input type="file" name="<%=CommConstants.FILE_TYPE_DOC%>3" class="input_file" size="60" /></p>
				       </c:when>				       
				       <c:otherwise>
				       <form:hidden path="bdFiles" value="${boardVO.bdFiles}"/>
				       <form:hidden path="bdFileNames" value="${boardVO.bdFileNames}"/>
				       		<p>
				       			<c:forEach var="file" items="${boardVO.orgFileNames}"  varStatus="status2">
			       					<input type="checkbox" name="deleteDocFile" value="${boardVO.saveFileNames[status2.index]}"/>
			       					[<c:out value="${file}"/>] 파일은 삭제합니다.
				       			</c:forEach>
				       		</p>
				       		
							<c:if test="${boardVO.fileSize < 3}">
							<c:forEach var="count" begin="${boardVO.fileSize + 1}" end="3" varStatus="status">
								<p><input type="file" name="<%=CommConstants.FILE_TYPE_DOC%>${status.index}" class="input_file" size="60"/></p>
							</c:forEach>
							</c:if>
				       </c:otherwise>
			       	</c:choose>
	             </td>
	   		</tr>
	   		<tr>
	   			<th><label for="contents"><spring:message code="board.view.content" /></label></th>
	   			<td colspan="3">
	   				<form:textarea path="bdContent" rows="5" cols="58" htmlEscape="false"/>&nbsp;<form:errors path="bdContent" />
	   				<ckeditor:replace replace="bdContent" basePath="${pageContext.request.contextPath}/ckeditor/" />
	            </td>
	   		</tr>
	   		<tr>
	   			<th><label for="contents">열람권한</label></th>
	   			<td colspan="3">
	   					<c:if test="${registerFlag == 'modify'}">
	   				<form:radiobutton path="bdViewAuth" value="0" label="모두공개" checked="checked"/>
	   				<form:radiobutton path="bdViewAuth" value="1" label="일부그룹공개"/>
	   				<form:errors path="bdViewAuth" cssClass="errormsg" />
	   				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	   				<c:choose>
	   					<c:when test="${boardVO.bdViewAuth eq '0'}">
	   					<!-- 모두공개 -->
		   				<form:checkbox path="checkAuth" value="5" label="국제협력관실" disabled="true" />
		   				<form:checkbox path="checkAuth" value="22" label="국제정보분석팀" disabled="true"/>
		   				<form:errors path="checkAuth" cssClass="errormsg" />
	   					</c:when>
	   					<c:otherwise>
	   					<!-- 일부그룹 -->
		   					<c:choose>
			   					<c:when test="${fn:indexOf(boardVO.bdViewGrp, '5')  > -1}">
			   					<!-- 국제협관관실 체크 -->
			   				<form:checkbox path="checkAuth" value="5" label="국제협력관실" checked="true"/>
			   					</c:when>
			   					<c:otherwise>
			   					<!-- 국제협관관실 미체크 -->
			   				<form:checkbox path="checkAuth" value="5" label="국제협력관실" />
			   					</c:otherwise>
			   				</c:choose>
			   				<c:choose>
			   					<c:when test="${fn:indexOf(boardVO.bdViewGrp, '22') > -1}">
			   					<!-- 국제정보분석팀 체크 -->
			   				<form:checkbox path="checkAuth" value="22" label="국제정보분석팀" checked="true"/>
			   					</c:when>
			   					<c:otherwise>
			   					<!-- 국제정보분석팀 미체크 -->
			   				<form:checkbox path="checkAuth" value="22" label="국제정보분석팀" />
			   					</c:otherwise>
			   				</c:choose>
		   				<%-- <form:checkbox path="checkAuth" value="22" label="국제정보분석팀" /> --%>
		   				<form:errors path="checkAuth" cssClass="errormsg" />
	   					</c:otherwise>
	   				</c:choose>
	   				</c:if>
	   			<c:if test="${registerFlag == 'create'}">
	   				<form:radiobutton path="bdViewAuth" value="0" label="모두공개"  checked="true" />
	   				<form:radiobutton path="bdViewAuth" value="1" label="일부그룹공개"/>
	   				<form:errors path="bdViewAuth" cssClass="errormsg" />
	   				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	   				<form:checkbox path="checkAuth" value="5" label="국제협력관실" disabled="true" />
	   				<form:checkbox path="checkAuth" value="22" label="국제정보분석팀" disabled="true"/>
	   				<form:errors path="checkAuth" cssClass="errormsg" />
	   			</c:if>
	   			
	   			
	   			<!-- 20180516 답글 관련 부분 추가 -->
	   			<c:if test="${registerFlag == 'reply'}">
	   				<form:radiobutton path="bdViewAuth" value="0" label="모두공개"  checked="true" />
	   				<form:radiobutton path="bdViewAuth" value="1" label="일부그룹공개"/>
	   				<form:errors path="bdViewAuth" cssClass="errormsg" />
	   				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	   				<form:checkbox path="checkAuth" value="5" label="국제협력관실" disabled="true" />
	   				<form:checkbox path="checkAuth" value="22" label="국제정보분석팀" disabled="true"/>
	   				<form:errors path="checkAuth" cssClass="errormsg" />
	   			</c:if>
	   			
	   			</td>
	   		</tr>
	   	</table>
    </div>
   	<div class="boardviewinfo">
		<ul class="right btn-style">
   			<li>
           		<a href="javascript:fn_egov_selectList();"><spring:message code="button.goList" /></a>
            </li>
   			<li>
               	<a href="javascript:fn_egov_save();">
                   	<c:if test="${registerFlag == 'create'}"><spring:message code="button.goCreate" /></c:if>
                   	<c:if test="${registerFlag == 'modify'}"><spring:message code="button.goModify" /></c:if>
                   	<c:if test="${registerFlag == 'reply'}"><spring:message code="button.goReply" /></c:if>
               	</a>
          	</li>
   		</ul>
   	</div>
</form:form>
<script type="text/javascript" src="<c:url value='/validator.do'/>"></script>
<validator:javascript formName="boardVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javaScript" defer="defer">
    /* 글 목록 화면 function */
    function fn_egov_selectList() {
       	//document.detailForm.action = "<c:url value='/bbs/list.do'/>";
       	//document.detailForm.submit();
    	window.history.back();
       	
    }
    
    /* 글 등록 function */
    function fn_egov_save() {
    	frm = document.detailForm;
    	console.log(CKEDITOR);
    	frm.bdContent.value = encodeURIComponent(CKEDITOR.instances.bdContent.getData());
    	if(!validateBoardVO(frm)){
            return;
        }else{
        	frm.action = "<c:url value="${registerFlag == 'modify' ? '/bbs/update.do' : registerFlag == 'reply' ? '/bbs/reply.do' : '/bbs/add.do'}"/>";
           	frm.submit();
        }
    }
    
    $(document).ready(function(){
    	
    	//열람권한 체크 이벤트 처리
    	$("input[name=bdViewAuth]").on("change", function(){
    		if($(this).val() == '1'){
    			$("input[name=checkAuth]").prop("disabled", false);
    		}else{
    			$("input[name=checkAuth]").prop("checked", false);
    			$("input[name=checkAuth]").prop("disabled", true);
    		}
    	});
    	
    });
</script>