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

		$.ajax({
			url: encodeURI('/webnotice/selectNotice.do'),
			data: formData,
			dataType: "json",
			processData: false,
			contentType: false,
			type: 'POST',
			async: true,
			success: function(data){
				if('0'==data.msgCode){
					$("#noticeSelectModal #modalTitle").text(data.rows[0].title);
					$("#noticeSelectModal #modalContent").empty().html(data.rows[0].content.replace(/\n/g,"<br/>"));
					$("#noticeSelectModal #modalOpenDate").text(data.rows[0].openDate);
					$("#noticeSelectModal #modalOpenTime").text(data.rows[0].openTime);
				}
				else{
					modalEvent.danger("조회 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){
				
			},
			complete:function(){
				
			}
		});
	},
	/*
	 * 팝업
	 * callback : 콜백함수, reqParam: 팝업파라미터
	 */
	popup:function(callback, reqParam) {
		// 초기화 후 열기
		noticeSelectModal.init();
		
		//콜백함수 지정.
		noticeSelectModal.callback = callback;
		noticeSelectModal.reqParam = reqParam;
		noticeSelectModal.dataList = null;
		
		setTimeout(function(){
			$('#noticeSelectModal').modal('show')
		}, 200);
		
		noticeSelectModal.search();
	},
	/*
	 * 팝업 닫기
	 */
	close:function() {
		$('#noticeSelectModal').modal('hide');

		setTimeout(function(){
			$('#noticeSelectModal').remove();
		},500);
	},
	HtmlTemplate : `
	<div id="noticeSelectModal" class="modal notice_detail_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">
						<div class="input_box">
							<label>제목</label>
							<div class="input_div" id="modalTitle"></div>
						</div>

						<div class="textarea_box">
							<label>내용</label>
							<div class="textarea_div" id="modalContent" style="overflow-y:auto;"></div>
						</div>

						<div class="registration_box">
							<label>게시일</label>

							<div class="date_div" id="modalOpenDate"></div>
							<div class="time_div" id="modalOpenTime"></div>
						</div>
					</div>
				</div>

				<div class="modal-footer">
					<div class="btn_box">
						<button type="button" class="check_bth btnCancle">확인</button>
					</div>
				</div>
			</div>
		</div>
	</div>
    `
};