<%--
  Class Name : LetterPhotoCustomRegist.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_insert() {
	
	var frm = document.writeForm;
	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/insertletterPhotosCustomAjax.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(){
	
	location.href="/letter/photo/letterPhotosCustomList.do";
	
}

/* 배너 삭제 function */
function fn_fmsfile_delete() {
	var msg;
	msg = "해당 첨부파일을 삭제하시겠습니까?";
	
	if (confirm(msg)) {
		frm = document.writeForm;
		frm.del.value = frm.fmsId.value ;
		frm.action = "<c:url value='/uss/ion/fms/fmsFileListDelete.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="fmsId" value="${fmsFileList[0].fmsId}" />
	<input type="hidden" name="fmsImageFile" value="${fmsFileList[0].fmsImageFile}" />
	<input type="hidden" name="letterType" value="C" />
	
	<!-- 드래그앤 드롭 파라미터 -->
	<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>
						<th><span class="reqArea">카테고리</span></th>
						<td id="55">
							<input type="checkbox" name="bestCategory" id="bestCategory" value="Y" />
							<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:out value='${cateCodeList_one.cateNm}'/></option>
								</c:if>
	                        </c:forEach>
	                        </select>
	                        <select name="cateCodeDepth_02" id="cateCodeDepth_02" class="asset_sec_sort displayN" style="display:none;" ></select>
	                        <select name="cateCodeDepth_03" id="cateCodeDepth_03" class="asset_sec_sort displayN" style="display:none;" ></select>
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">제목</span></th>
						<td colspan="3">
							<input type="text" name="letterSj" value="" title="letterSj" maxlength="100" />
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">해쉬 태그</span></th>
						<td colspan="3">
							<input type="text" name="hashTag" value="" title="hashTag" maxlength="100" />
						</td>
					</tr>
					<tr>
						<th><span class="reqArea">우선순위</span></th>
						<td colspan="3">
							<input type="text" name="priNum" value="" title="priNum" maxlength="100" />
						</td>
					</tr>
					<tr>
						<th>alt 내용</th>
						<td colspan="3">
							<input type="text" name="letterAlt" value="" 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:forEach var="fileList" items="${fileList}" varStatus="status">
		                        			<tr class="item_${fileList.fmsImageFile}_${fileList.fileSn} uploaded_obj">
												<input type="hidden" name="fileSize" class="item_file_size" value="${fileList.fileSize}">
												<td class="file_name">
													<img src="/direct/img/upload_hwp_img.png" alt="" />
													<span class="file_name_text">${fileList.orignlFileNm}</span>
												</td>
												<td>
													<span class="file_size_text" value="<c:out value="${fileList.fileSize}"/>"></span>
												</td>
												<td>
													<c:out value="${fileList.regdt}"/>
												</td>
												<td>
													<input type="button" class="delBtn" onclick="delAtchFile('${fileList.fmsImageFile}', '${fileList.fileSn}'); return false;">
												</td>
											</tr>
		                        		</c:forEach>
									</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>
					<c:if test="${!empty fmsFileList[0].fmsId }">
					<tr>
						<th class="td_title1"><span class="star_t"></span>첨부이미지 링크</th>
						<td colspan="3">
							<c:forEach var="result" items="${fmsFileList}" varStatus="status">
								<c:if test="${result.fileExtsn eq 'jpg' || 
									result.fileExtsn eq 'jpeg' || 
									result.fileExtsn eq 'png' || 
									result.fileExtsn eq 'bmp' || 
									result.fileExtsn eq 'gif' || 
									result.fileExtsn eq 'img' }">
									<span class="item_${result.fmsImageFile}_${result.fileSn}">
									<a href='${result.fmsLink}' target="_blank">${result.fmsLink}</a>
										  (${result.orignlFileNm})
									</br>
									</span>
								</c:if>
							</c:forEach>
						</td>
					</tr>
					<tr>
						<th class="td_title1"><span class="star_t"></span>첨부다운로드 링크</th>
						<td colspan="3">
							<c:forEach var="result" items="${fmsFileList}" varStatus="status">
								<span class="item_${result.fmsImageFile}_${result.fileSn}">
								<a href='${result.fmsDownLink}'>${result.fmsDownLink}</a>
								<c:if test="${listExist}">(</c:if>
								${result.orignlFileNm}
								<c:if test="${listExist}">)</c:if>
								</br>
								</span>
							</c:forEach>
						</td>
					</tr>
					<tr>
						<th class="td_title1"><span class="star_t"></span>최종수정일</th>
						<td colspan="3">
							${fmsFileList[0].moddt }
						</td>
					</tr>
					
					<tr>
						<th class="td_title1"><span class="star_t"></span>작성자</th>
						<td colspan="3">
							${fmsFileList[0].registerId }
						</td>
					</tr>
					</c:if>
				</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_insert(); 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>
