<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : ExcelUploadPopupForm.html
 * @desc    : 엑셀 업로드 팝업 Page
 *============================================================================
 * Pastelmall
 * Copyright(C) 2019 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.10.22   eskim       최초 작성
 *******************************************************************************
 -->	
	<div class="modalPopup" data-width="600">
		<div class="panelStyle">
			<!-- TITLE -->
			<div class="panelTitle">
				<strong>엑셀업로드</strong>
				<button type="button" class="close" onclick="uifnPopupClose('popupExcelUpload')"><i class="fa fa-times"></i></button>
			</div>
			<!-- //TITLE -->
			<!-- CONTENT -->
			<div class="panelContent">
			<form id="excelPopupForm" name="excelPopupForm"  action="">
			<input type="hidden" name="procJob" id="procJob" th:value="${params.procJob}"/>
			<input type="hidden" name="callBackFun" id="callBackFun" th:value="${params.callBackFun}"/>
				<table class="frmStyle">
				<colgroup>
					<col style="width:20%;"/>
					<col/>
					<col style="width:20%;"/>
				</colgroup>
				<tbody>
					<tr>
						<th>파일</th>
						<td><div class="uFile w300">
								<input id="excelFile" name="excelFile" type="file" class="uFileInput"/>
								<label for="excelFile" class="uFileLabel">파일선택</label>
								<input type="hidden" name="OrgFileNm"/>
								<input type="hidden" name="NewFileNm"/>
							</div>
						</td>
					</tr>
				</tbody>
				</table>
				<!-- 버튼 배치 영역 -->
				<ul class="panelBar">
					<li class="right">
						<button type="button" class="btn btn-success btn-lg" id="btnExcelUploadSave">저장</button>
					</li>	
				</ul>
				<!-- //버튼 배치 영역 -->
			</form>
			</div>
		</div>
		<!-- //CONTENT -->
	</div>
<script th:inline="javascript">
/*<![CDATA[*/
	
	//첨부파일 등록
	$('#excelPopupForm input[name=excelFile]').on('change', function() {
		var file = this.files[0];
	
		if (typeof(file) == 'undefined'){
			return;
		}
		
		gagajf.ajaxFileUpload('/common/file/upload?subDir=/excel'
				, file
				, function(result) {
					$('#excelPopupForm input[name=OrgFileNm]').val(result.newFileName);
					$('#excelPopupForm input[name=NewFileNm]').val(result.newFileName);
				}
				, 'excel'
		);
	});
	
	//저장
	$('#btnExcelUploadSave').on('click', function (){
		
		if(gagajf.isNull($("#excelPopupForm input[name=OrgFileNm]").val())){
			mcxDialog.alert("파일을 첨부해 주세요.");
			$("#excelPopupForm input[name=excelFile]").focus();
			return false;
		}
		
		var callback = $('#excelPopupForm input[name=callBackFun]').val();
		if( typeof callback != 'undefined' && callback){
			var data = {procJob : $('#excelPopupForm input[name=procJob]').val()
						, callBackFun : $('#excelPopupForm input[name=callBackFun]').val()
						, excelFileNm : $('#excelPopupForm input[name=NewFileNm]').val()
						};
			var jsonData = JSON.stringify(data);
			if (typeof callback == 'function') {
				callback(jsonData);
			}else{
				if( callback ) {
					if( callback.indexOf("(") == -1 ) eval( callback +"(" + jsonData+")");
					else eval( callback(jsonData) );
				}
			}
			uifnPopupClose('popupExcelUpload');
		}
	});	
	
/*]]>*/
</script>
</html>