
/* ##############################################################
	설  명 : [Modal]근태관리 - 연차 취소사유 팝업
	작성일 : 2023. 01. 19.
	작성자 : NTsoft
	수정일 	        수정자 	 수정내용
	-------         -------- ---------------------------
	2023. 01. 19.	NTsoft 	 최초 생성
*/
let attendVacationManagementCancelEtcModal = {
	callback : null,
	reqParam : null,
	dataList : null,
	/* 모달 초기화 작업 */
	init : function () {
		$('#attendVacationManagementCancelEtcModal').remove();
		$('body').append( this.HtmlTemplate);
		//그리드 이벤트
		this.setEvent();
	},
	/* 그리드 이벤트 설정 */
	setEvent:function() {
		$('#attendVacationManagementCancelEtcModal .btnCancle').on("click", function(){
			attendVacationManagementCancelEtcModal.close();
		});
		
		$('#attendVacationManagementCancelEtcModal .btnSave').on("click", function(){
			attendVacationManagementCancelEtcModal.save("I");
		});
	},
	/* 데이터 선택 */
	setSelect:function(selectNumber) {
		let checkedData = dataList[selectNumber];
		if(dataList==null||checkedData==undefined){
			return ;
		}
		
		if( attendVacationManagementCancelEtcModal.callback )  {
			attendVacationManagementCancelEtcModal.callback(checkedData);
		}
		attendVacationManagementCancelEtcModal.close();
	},
	//저장
	save:function(state) {
		let muAttendanceId = attendVacationManagementCancelEtcModal.reqParam.muAttendanceId;
		let cancelEtc      = $("#attendVacationManagementCancelEtcModal #modalCancelEtc").val();
		
		
		if(true != fn_emptyCheck(muAttendanceId)){
			modalEvent.warning("취소", "근태관리 정보가 없습니다.");	
			return;
		}
		
		if(true != fn_emptyCheck(cancelEtc)){
			modalEvent.warning("취소", "취소사유 정보가 없습니다.");	
			return;
		}
		
		modalEvent.info("취소", "연차취소하시겠습니까?", function(){
			let formData = new FormData();
			formData.append("menuClass", menuClass);
			formData.append("muAttendanceId", muAttendanceId);
			formData.append("cancelEtc", cancelEtc);
	
			$.ajax({
				url: encodeURI('/webattendance/updateAttendanceVacationCancel.do'),
				data: formData,
				dataType: "json",
				processData: false,
				contentType: false,
				type: 'POST',
				async: true,
				success: function(data){
					if('0'==data.msgCode){
						modalEvent.success("취소 성공", data.msgDesc, function(){
							if( attendVacationManagementCancelEtcModal.callback ) {
								attendVacationManagementCancelEtcModal.callback();
							}
							attendVacationManagementCancelEtcModal.close();
						});
					}
					else{
						modalEvent.danger("취소 오류", data.msgDesc);
					}
				},
				error : function(xhr, status, error) {
					modalEvent.danger("취소 오류", "취소 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
				},
				beforeSend:function(){
					
				},
				complete:function(){
					
				}
			});
		});
	},
	/*
	 * 팝업
	 * callback : 콜백함수, reqParam: 팝업파라미터
	 */
	popup:function(callback, reqParam) {
		// 초기화 후 열기
		attendVacationManagementCancelEtcModal.init();
		
		//콜백함수 지정.
		attendVacationManagementCancelEtcModal.callback = callback;
		attendVacationManagementCancelEtcModal.reqParam = reqParam;
		attendVacationManagementCancelEtcModal.dataList = null;
		
		setTimeout(function(){
			$('#attendVacationManagementCancelEtcModal').modal('show')
		}, 200);
	},
	/*
	 * 팝업 닫기
	 */
	close:function() {
		$('#attendVacationManagementCancelEtcModal').modal('hide');

		setTimeout(function(){
			$('#attendVacationManagementCancelEtcModal').remove();
		},500);
	},
	HtmlTemplate : `
	<div id="attendVacationManagementCancelEtcModal" class="modal cencell_modal fade" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header cencell_reason_header">
					<p class="title">취소 사유</p>
				</div>
				
				
				<div class="modal-body">
					<div class="cencell_reason open">
						<div class="textarea_box">
							<textarea id="modalCancelEtc" placeholder="사유를 입력하세요."></textarea>
						</div>
						<div class="btn_box">
							<button type="button" class="cancel_btn btnCancle">취소</button>
							<button type="button" class="seve_bth btnSave">저장</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
    `
};