
/* ##############################################################
	설  명 : [Modal]휴무관리 상세/취소 팝업
	작성일 : 2023. 01. 19.
	작성자 : NTsoft
	수정일 	        수정자 	 수정내용
	-------         -------- ---------------------------
	2023. 01. 19.	NTsoft 	 최초 생성
*/
let holidayManagementCancelModal = {
	callback : null,
	reqParam : null,
	dataList : null,
	/* 모달 초기화 작업 */
	init : function () {
		$('#holidayManagementCancelModal').remove();
		$('body').append( this.HtmlTemplate);
		//그리드 이벤트
		this.setEvent();
	},
	/* 그리드 이벤트 설정 */
	setEvent:function() {
		$('#holidayManagementCancelModal .btnCancle').on("click", function(){
			holidayManagementCancelModal.close();
		});
		
		$('#holidayManagementCancelModal .btnSave').on("click", function(){
			holidayManagementCancelModal.save("I");
		});
	},
	/* 데이터 선택 */
	setSelect:function(selectNumber) {
		let checkedData = dataList[selectNumber];
		if(dataList==null||checkedData==undefined){
			return ;
		}
		
		if( holidayManagementCancelModal.callback )  {
			holidayManagementCancelModal.callback(checkedData);
		}
		holidayManagementCancelModal.close();
	},
	// 상세 조회
	search:function(state) {
		let muAttendanceId = holidayManagementCancelModal.reqParam.muAttendanceId;
		
		if(true != fn_emptyCheck(muAttendanceId)){
			modalEvent.warning("등록", "휴무관리 정보가 없습니다.");	
			return;
		}
		
		let formData = new FormData();
		formData.append("menuClass", menuClass);
		formData.append("muAttendanceId", muAttendanceId);

		$.ajax({
			url: encodeURI('/webholidaymanagement/selectHolidayManagement.do'),
			data: formData,
			dataType: "json",
			processData: false,
			contentType: false,
			type: 'POST',
			async: true,
			success: function(data){
				if('0'==data.msgCode){
					$("#holidayManagementCancelModal #modalMemberNameId").text(data.rows[0].memberName+'('+data.rows[0].loginId+')');
					$("#holidayManagementCancelModal #modalGroupName").text(data.rows[0].groupName);
					$("#holidayManagementCancelModal #modalDutyName").text(data.rows[0].dutyName);
					$("#holidayManagementCancelModal #modalStatus").text(data.rows[0].statusKorName);
					$("#holidayManagementCancelModal #modalHolidayDate").text(data.rows[0].startDate+' ~ '+data.rows[0].endDate+', '+data.rows[0].days+'일');
					$("#holidayManagementCancelModal #modalCancelEtc").val(data.rows[0].cancelEtc);
					$("#holidayManagementCancelModal #modalCancelDate").text(data.rows[0].cancelDate);
					$("#holidayManagementCancelModal #modalCancelName").text(data.rows[0].cancelMemberName);
				}
				else{
					modalEvent.danger("조회 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){
				
			},
			complete:function(){
				
			}
		});
	},
	//저장
	save:function(state) {
		let muAttendanceId = holidayManagementCancelModal.reqParam.muAttendanceId;
		let cancelEtc      = $("#holidayManagementCancelModal #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( holidayManagementCancelModal.callback )  {
								holidayManagementCancelModal.callback();
							}
							holidayManagementCancelModal.close();
						});
					}
					else{
						modalEvent.danger("수정 오류", data.msgDesc);
					}
				},
				error : function(xhr, status, error) {
					modalEvent.danger("수정 오류", "등록 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
				},
				beforeSend:function(){
					
				},
				complete:function(){
					
				}
			});
		});
	},
	/*
	 * 팝업
	 * callback : 콜백함수, reqParam: 팝업파라미터
	 */
	popup:function(callback, reqParam) {
		// 초기화 후 열기
		holidayManagementCancelModal.init();
		
		//콜백함수 지정.
		holidayManagementCancelModal.callback = callback;
		console.log(this.callback);
		holidayManagementCancelModal.reqParam = reqParam;
		holidayManagementCancelModal.dataList = null;
		
		setTimeout(function(){
			$('#holidayManagementCancelModal').modal('show')
		}, 200);
		
		holidayManagementCancelModal.search();
	},
	/*
	 * 팝업 닫기
	 */
	close:function() {
		$('#holidayManagementCancelModal').modal('hide');

		setTimeout(function(){
			$('#holidayManagementCancelModal').remove();
		},500);
	},
	HtmlTemplate : `
	<div id="holidayManagementCancelModal" class="modal cencell_info_modal fade" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<p class="title">휴무 상세</p>
				</div>
	
				<div class="modal-body">
					<div class="form_box">
						<ul class="info_list">
							<li>
								<label>이름(ID)</label>
								<p id="modalMemberNameId"></p>
							</li>
							<li>
								<label>조직</label>
								<p id="modalGroupName"></p>
							</li>
							<li>
								<label>직무</label>
								<p id="modalDutyName"></p>
							</li>
							<li>
								<label>상태</label>
								<p id="modalStatus"></p>
							</li>
							<li>
								<label>휴무기간</label>
								<p id="modalHolidayDate"></p>
							</li>
							<li>
								<div class="input_box">
									<label>취소사유</label>
	
									<div class="textarea_box">
										<textarea id="modalCancelEtc" placeholder="취소사유를 입력해주세요."></textarea>
									</div>
								</div>
							</li>
							<li>
								<label>취소일/담당자</label>
								<p>
									<span id="modalCancelDate"></span>
									<span id="modalCancelName"></span>
								</p>
							</li>
						</ul>
					</div>
				</div>

				<div class="modal-footer">
					<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>
    `
};