
/* ##############################################################
	설  명 : [Modal]휴무관리 취소사유 팝업
	작성일 : 2023. 01. 19.
	작성자 : NTsoft
	수정일 	        수정자 	 수정내용
	-------         -------- ---------------------------
	2023. 01. 19.	NTsoft 	 최초 생성
*/
let holidayManagementCancelEtcModal = {
	callback : null,
	reqParam : null,
	dataList : null,
	/* 모달 초기화 작업 */
	init : function () {
		$('#holidayManagementCancelEtcModal').remove();
		$('body').append( this.HtmlTemplate);
		//그리드 이벤트
		this.setEvent();
	},
	/* 그리드 이벤트 설정 */
	setEvent:function() {
		$('#holidayManagementCancelEtcModal .btnCancle').on("click", function(){
			holidayManagementCancelEtcModal.close();
		});
		
		$('#holidayManagementCancelEtcModal .btnSave').on("click", function(){
			holidayManagementCancelEtcModal.save("I");
		});
	},
	/* 데이터 선택 */
	setSelect:function(selectNumber) {
		let checkedData = dataList[selectNumber];
		if(dataList==null||checkedData==undefined){
			return ;
		}
		
		if( holidayManagementCancelEtcModal.callback )  {
			holidayManagementCancelEtcModal.callback(checkedData);
		}
		holidayManagementCancelEtcModal.close();
	},
	//저장
	save:function(state) {
		let muAttendanceId = holidayManagementCancelEtcModal.reqParam.muAttendanceId;
		let cancelEtc      = $("#holidayManagementCancelEtcModal #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('/webholidaymanagement/updateHolidayManagementCancel.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( holidayManagementCancelEtcModal.callback )  {
								holidayManagementCancelEtcModal.callback();
							}
							holidayManagementCancelEtcModal.close();
						});
					}
					else{
						modalEvent.danger("수정 오류", data.msgDesc);
					}
				},
				error : function(xhr, status, error) {
					modalEvent.danger("수정 오류", "등록 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
				},
				beforeSend:function(){
					
				},
				complete:function(){
					
				}
			});
		});
	},
	/*
	 * 팝업
	 * callback : 콜백함수, reqParam: 팝업파라미터
	 */
	popup:function(callback, reqParam) {
		// 초기화 후 열기
		holidayManagementCancelEtcModal.init();
		
		//콜백함수 지정.
		holidayManagementCancelEtcModal.callback = callback;
		holidayManagementCancelEtcModal.reqParam = reqParam;
		holidayManagementCancelEtcModal.dataList = null;
		
		setTimeout(function(){
			$('#holidayManagementCancelEtcModal').modal('show')
		}, 200);
	},
	/*
	 * 팝업 닫기
	 */
	close:function() {
		$('#holidayManagementCancelEtcModal').modal('hide');

		setTimeout(function(){
			$('#holidayManagementCancelEtcModal').remove();
		},500);
	},
	HtmlTemplate : `
	<div id="holidayManagementCancelEtcModal" 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>
    `
};