<%--
  Class Name : LetterPhotoDetail.jsp
  Description : 그림문자 수정 페이지
  Modification Information

      수정일         수정자                   수정내용
    -------    --------    ---------------------------
     2009.09.16    장동한          최초 생성

    author   : 공통서비스 개발팀 장동한
    since    : 2009.09.16

    Copyright (C) 2009 by MOPAS  All right reserved.
--%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="ImgUrl" value="${pageContext.request.contextPath}/images/egovframework/com/cmm/" />
<c:set var="CssUrl" value="${pageContext.request.contextPath}/css/egovframework/com/" />
<c:set var="JsUrl"  value="${pageContext.request.contextPath}/js/egovframework/com/uss/ion/pwm/"/>
<!DOCTYPE html>
<html lang="ko">
<head>
<title>그림문자 등록 관리</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="<c:url value='/js/EgovMultiFile.js'/>"></script>
<script src="/direct/js/jquery.nice-select.min.js"></script>
<link rel="stylesheet" href="/direct/css/nice-select.css">
<script type="text/javaScript" language="javascript">

$( document ).ready(function(){
	
	$('select').not(".displayN").niceSelect();
	
	$("#cateCodeDepth_01").on("change", function(){  
		setCateCode_01();
	});
	$("#cateCodeDepth_02").on("change", function(){  
		setCateCode_02();
	});
	
});

// 카테고리 옵션 선택 함수
function setCateCode_01(){
	if(""==$("#cateCodeDepth_01").val()){ //빈값 선택
		$("#cateCodeDepth_02").niceSelect('destroy').hide();
		$("#cateCodeDepth_03").niceSelect('destroy').hide();
	}else{
		$('#cateCodeDepth_02').html($('#span_cate_'+$("#cateCodeDepth_01").val()).html().trim());
		$('#cateCodeDepth_02').niceSelect('update');
		$("#cateCodeDepth_02").niceSelect(); //display show 기능
		$("#cateCodeDepth_03").niceSelect('destroy').hide();
	}
}

function setCateCode_02(){
	if(""==$("#cateCodeDepth_02").val()){ //빈값 선택
		$("#cateCodeDepth_03").niceSelect('destroy').hide();
	}else{
		$('#cateCodeDepth_03').html($('#span_cate_'+$("#cateCodeDepth_02").val()).html().trim());
		$('#cateCodeDepth_03').niceSelect('update');
		$("#cateCodeDepth_03").niceSelect(); //display show 기능
	}
}

/* pagination 페이지 링크 function */
function goList(){
   	document.searchForm.submit();
}

/* 등록시 값 확인 */
function fn_checkForm(flag) {
	frm = document.writeForm;
	
	if(frm.cateCodeDepth_01.value==""){
		
		alert("카테고리를 선택해 주세요.");
		return false;
		
	}
	
	if(frm.letterSj.value=="") {
		alert("제목을 입력해 주십시오");
		frm.letterSj.focus();
		return false;
	}
	
	if(flag==1){
		if($('.file_name').find('span').length==0){
			alert("첨부파일을 추가해 주십시오");
			return false;
		}
	}
	return true;	
}

/* 글 등록 function */
function fn_photo_update() {
	
	var frm = document.writeForm;
	
	if(frm.chgPriority.value != frm.oriPriority.value){
		frm.priNum.value = frm.chgPriority.value;
	}
	
	if(fn_checkForm(1)){
		
		var data = new FormData(document.writeForm);
		_fileForm2.forEach(function(obj, idx) {
			if (obj) data.append("file"+idx, obj.fileObj);
		});

		$.ajax({
	        type: "POST",
	        enctype: 'multipart/form-data',
	        url: '/letter/photo/updateLetterPhotosAjax.do',
	        data: data,
	        dataType:'json',
	        async: false,
	        processData: false,
	        contentType: false,
	        cache: false,
	        //timeout: 600000,
	        success: function (returnData, status) {
				if(status == 'success'){ // status 확인 필요한가. 석세스 안뜨면 에러 가지 않나
					if("fail"==returnData.result){
						alert(returnData.message);
						return;
					}
					alert("저장 되었습니다.");
					fn_photoList();
				} else if(status== 'fail'){
					alert("저장에 실패하였습니다. !!");
				}
			},
	        error: function (e) { alert("저장에 실패하였습니다."); console.log("ERROR : ", e); }
	    });
		
	}	
}

function fn_photoList(){
	var frm = document.writeForm;
	frm.action = "<c:url value='/letter/photo/letterPhotosList.do'/>";
	frm.submit();
	
}

/* 문서 파일  팝업 */
var fileupladOpener = null;
function fileUploadPopup(){
	var docWidth = screen.availWidth;
	var docHeight = screen.availHeight;
	
	var scX = window.screenX||window.screenLeft||0;
	var scY = window.screenY||window.screenTop||0;
	
	var popupX = scX + (docWidth - 185) / 2;
	var popupY = scY + (docHeight - 195) / 2;
	
	fileupladOpener = window.open('', 'fileUploadPopup', "width=185, height=195, left="+popupX+", top="+popupY, "location = no","status= no","toolbars= no");
	document.writeForm.method = "post";
	//document.writeForm.action = "/uss/itsm/ip/IpFilePopup.do"; 
	document.writeForm.action = "/uss/ion/fms/fmsfileUploadPopup.do";
	document.writeForm.target = "fileUploadPopup" ;
	document.writeForm.submit();
}

</script>

</head>
<body>
<form name="writeForm" enctype="multipart/form-data" method="post">
	<input type="hidden" name="selectedId" />	
	<input type="hidden" name="del" />
	<input type="hidden" name="letterId" value="${resultPhotoList.letterId}" />
	<input type="hidden" name="attachFileId" value="${resultFileList.attachFileId}" />
	<input type="hidden" name="orignlFileNm" value="${resultFileList.orignlFileNm}" />
	<input type="hidden" id="oriPriority" name="oriPriority" value="${resultPhotoList.priority}"/>
	<input type="hidden" id="priNum" name="priNum" value=""/>
	<input type="hidden" name="letterType" value="P" />
	
	<input type="hidden" name="searchSortCnd"		value="<c:out value="${userSearchVO.searchSortCnd}" />"/>
	<input type="hidden" name="searchSortOrd"		value="<c:out value="${userSearchVO.searchSortOrd}" />"/>
	<input type="hidden" name="searchCondition"		value="<c:out value='${userSearchVO.searchCondition}'/>"/>
	<input type="hidden" name="searchKeyword"		value="<c:out value='${userSearchVO.searchKeyword}'/>"/>
	<input type="hidden" name="searchBestCategory"	value="<c:out value='${userSearchVO.searchBestCategory}'/>"/>
	<input type="hidden" name="pageUnit"			value="<c:out value='${userSearchVO.pageUnit}'/>"/>
	<input type="hidden" name="PageIndex"			value="<c:out value='${userSearchVO.pageIndex}' default='1' /> "/>
	
	<input type="hidden" name="searchTwoDptCategoryCode"	value="<c:out value='${userSearchVO.searchTwoDptCategoryCode}'/>"/>
	<input type="hidden" name="searchThrDptCategoryCode"	value="<c:out value='${userSearchVO.searchThrDptCategoryCode}'/>"/>	
	
	<!-- 드래그앤 드롭 파라미터 -->
	<input type="hidden" name="limitcount" value="1" /><!-- 최대 첨부파일 갯수 -->
	
	<div class="contWrap">
		<div class="pageTitle">
			<div class="pageIcon"><img src="/pb/img/pageTitIcon4.png" alt=""></div>
			<h2 class="titType1 c_222222 fwBold">그림 문자 파일관리</h2>
			<p class="tType6 c_999999">그림문자 내용 및 이미지를 등록/수정 할 수 있습니다.</p>
		</div>
		<div class="pageCont">
			<table class="tbType2">
				<colgroup>
					<col style="width: 20%">
					<col style="width: 80%">
				</colgroup>
				<tbody>
					<tr>
						<!-- 뎁스별 카테고리 코드번호 -->
						<c:set var="strCateCode01" value="" />
                        <c:set var="strCateCode02" value="" />
                        <c:set var="strCateCode03" value="" />  
                        <!-- 뎁스별 부모 카테고리 코드번호 -->
                        <c:set var="strUpCateCode01" value="" />
                        <c:set var="strUpCateCode02" value="" />
                        <c:set var="strUpCateCode03" value="" />                    
                        <c:forEach var="cateCodeRegList" items="${cateCodeRegList}" varStatus="status">
                        	<c:choose>
                        		<c:when test="${cateCodeRegList.cateDepth == '1'}">
                        			<c:set var="strCateCode01" value="${cateCodeRegList.cateNo}" />
                        			<c:set var="strUpCateCode01" value="${cateCodeRegList.upperCateNo}" />
                        		</c:when>
                        		<c:when test="${cateCodeRegList.cateDepth == '2'}">
                        			<c:set var="strCateCode02" value="${cateCodeRegList.cateNo}" />
                        			<c:set var="strUpCateCode02" value="${cateCodeRegList.upperCateNo}" />
                        		</c:when>
                        		<c:otherwise>
                        			<c:set var="strCateCode03" value="${cateCodeRegList.cateNo}" />
                        			<c:set var="strUpCateCode03" value="${cateCodeRegList.upperCateNo}" />
                        		</c:otherwise>
                        	</c:choose>
                        </c:forEach>
						<th><span class="reqArea">카테고리</span></th>
						<td id="55">
							<input type="checkbox" name="bestCategory" id="bestCategory" value="Y" <c:if test="${resultPhotoList.bestCategory eq 'Y'}">checked=checked</c:if> />
							<label for="bestCategory" style="padding-right:15px">BEST</label>
	                        <select name="cateCodeDepth_01" id="cateCodeDepth_01" class="asset_sec_sort">
	                        <option value="">선택</option>
	                        <c:forEach var="cateCodeList_one" items="${cateCodeList}" varStatus="status">
								<c:if test="${cateCodeList_one.cateDepth eq '1'}">
									<option value="<c:out value='${cateCodeList_one.cateNo}'/>" <c:if test="${strCateCode01 eq cateCodeList_one.cateNo }">selected</c:if> ><c:out value='${cateCodeList_one.cateNm}'/></option>
								</c:if>
	                        </c:forEach>
	                        </select>
	                        <select name="cateCodeDepth_02" id="cateCodeDepth_02" class="asset_sec_sort">
	                        	<option value="">선택</option>
		                        <c:forEach var="cateCodeList_two" items="${cateCodeList}" varStatus="status">
									<c:if test="${cateCodeList_two.cateDepth eq '2' && cateCodeList_two.upperCateNo eq strUpCateCode02}">
										<option value="<c:out value='${cateCodeList_two.cateNo}'/>" <c:if test="${strCateCode02 eq cateCodeList_two.cateNo }">selected</c:if> ><c:out value='${cateCodeList_two.cateNm}'/></option>
									</c:if>
		                        </c:forEach>
	                        </select>
	                        <select name="cateCodeDepth_03" id="cateCodeDepth_03" class="asset_sec_sort">
	                        	<option value="">선택</option>
		                        <c:forEach var="cateCodeList_three" items="${cateCodeList}" varStatus="status">
									<c:if test="${cateCodeList_three.cateDepth eq '3' && cateCodeList_three.upperCateNo eq strUpCateCode03}">
										<option value="<c:out value='${cateCodeList_three.cateNo}'/>" <c:if test="${strCateCode03 eq cateCodeList_three.cateNo }">selected</c:if> ><c:out value='${cateCodeList_three.cateNm}'/></option>
									</c:if>
		                        </c:forEach>
	                        </select>
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">제목</span></th>
						<td colspan="3">
							<input type="text" name="letterSj" value="${resultPhotoList.letterSj}" title="letterSj" maxlength="100" />
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">해쉬 태그</span></th>
						<td colspan="3">
							<input type="text" name="hashTag" value="${resultPhotoList.hashTag}" title="hashTag" maxlength="100" />
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">우선순위</span></th>
						<td colspan="3">
							<input type="text" id="chgPriority" name="chgPriority" value="${resultPhotoList.priority}" title="priority"/>
						</td>
					</tr>
					<tr>
						<th>첨부 이미지</th>
						<td colspan="3">
							<img src="/cmm/fms/getImage2.do?atchFileId=${resultFileList.attachFileId}&fileSn=${resultFileList.fileSn}" width="300px"/>
						</td>
					</tr>
					<tr>
						<th>alt 내용</th>
						<td colspan="3">
							<input type="text" id="letterAlt" name="letterAlt" value="${resultPhotoList.letterAlt}" title="letterAlt" maxlength="2000"/>
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">파일 첨부</span></th>
						<td class="upload_area">
							<div class="file_upload_box no_img_box fileWrap">
								<table>	
									<colgroup>
										<col style="width: 60%">
										<col style="width: 10%">
										<col style="width: 20%">
										<col style="width: 10%">
									</colgroup>
									<thead>
										<tr>
										<th>파일명</th>
										<th>크기</th>
										<th>등록일시</th>
										<th>삭제</th>
										</tr>
									</thead>
								</table>
							</div>
							<div class="fileWrap fileAfter file_list_div">
								<table>
									<colgroup>
										<col style="width: 60%">
										<col style="width: 10%">
										<col style="width: 20%">
										<col style="width: 10%">
									</colgroup>
									<thead>
										<tr>
											<th>파일명</th>
											<th>크기</th>
											<th>등록일시</th>
											<th>삭제</th>
										</tr>
									</thead>
									<tbody id="tbody_fiielist">
										<c:if test="${!empty resultFileList}">
		                        			<tr class="item_${resultFileList.attachFileId}_${resultFileList.fileSn} uploaded_obj">
												<input type="hidden" name="fileSize" class="item_file_size" value="${resultFileList.fileSize}">
												<td class="file_name">
													<img src="/direct/img/upload_hwp_img.png" alt="" />
													<span class="file_name_text">${resultFileList.orignlFileNm}</span>
												</td>
												<td>
													<span class="file_size_text" value="<c:out value="${resultFileList.fileSize}"/>"></span>
												</td>
												<td>
													<fmt:formatDate pattern = "yyyy-MM-dd HH:mm:ss" value = "${resultPhotoList.regdate}" />
												</td>
												<td>
													<input type="button" class="delBtn" onclick="delAtchFile('${resultFileList.attachFileId}', '${resultFileList.fileSn}'); return false;">
												</td>
											</tr>
										</c:if>
									</tbody>
								</table>
							</div>
							<div class="fileInfo file_list_div">
								<ul class="inline">
									<li>
										<p>최대 <span class="c_e40000 fwBold limitcount_li">1</span>개 ｜ <span class="c_e40000 fwBold upload_number">50MB</span>제한</p>
									</li>
									<li>
										<p><span class="c_456ded fwBold totalfileCount">1</span>개 ｜ <span class="c_456ded fwBold totalfileSize">72.01KB</span></p>
									</li>
								</ul>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="btnWrap">
				<input type="button" class="btnType1 bg_888888" value="목 록" onclick="fn_photoList(); return false;">
				<input type="button" class="btnType1" value="수 정" onclick="fn_photo_update(); return false;">
			</div>
	 	</div>
	</div>
</form>
<form name="searchForm" id="searchForm" method="get" action="<c:url value='/uss/ion/fms/fmsFileList.do'/>" ></form>

<!-- selectbox 미리만들기 -->
<!-- 2뎁스 만들기 -->
<c:forEach var="hiddenResult_one" items="${orgHiddenList}" varStatus="status">
	<c:if test="${hiddenResult_one.depth eq '1'}">
		<span id="span_one_${hiddenResult_one.id}" style="display:none;">
		<option value="">선택</option>
		<c:forEach var="hiddenResult_two" items="${orgHiddenList}" varStatus="status"><c:if test="${hiddenResult_one.id eq hiddenResult_two.parent}"><option value="<c:out value='${hiddenResult_two.id}'/>"><c:out value='${hiddenResult_two.text}'/></option></c:if></c:forEach>
		</span>
	</c:if>
</c:forEach> 


<!-- cate 2 뎁스 만들기 -->
<c:forEach var="cateCodeList_one" items="${cateCodeList}" varStatus="status">
	<c:if test="${cateCodeList_one.cateDepth eq '1'}">
		<span id="span_cate_${cateCodeList_one.cateNo}" style="display:none;">
		<option value="">선택</option>
		<c:forEach var="cateCodeList_two" items="${cateCodeList}" varStatus="status">
		<c:if test="${cateCodeList_one.cateNo eq cateCodeList_two.upperCateNo}">
			<option value="<c:out value='${cateCodeList_two.cateNo}'/>">
			<c:out value='${cateCodeList_two.cateNm}'/></option>
		</c:if>
		</c:forEach>
		</span>
	</c:if>
</c:forEach> 

<!-- cate 3 뎁스 만들기 -->
<c:forEach var="cateCodeList_two" items="${cateCodeList}" varStatus="status">
	<c:if test="${cateCodeList_two.cateDepth eq '2'}">
		<span id="span_cate_${cateCodeList_two.cateNo}" style="display:none;">
		<option value="">선택</option>
		<c:forEach var="cateCodeList_three" items="${cateCodeList}" varStatus="status">
		<c:if test="${cateCodeList_two.cateNo eq cateCodeList_three.upperCateNo}">
			<option value="<c:out value='${cateCodeList_three.cateNo}'/>">
			<c:out value='${cateCodeList_three.cateNm}'/></option>
		</c:if>
		</c:forEach>
		</span>
	</c:if>
</c:forEach>

</body>
</html>
