

/* ##############################################################
	설  명 : [Modal]공지사항 상세/수정 팝업
	작성일 : 2023. 01. 19.
	작성자 : NTsoft
	수정일 	        수정자 	 수정내용
	-------         -------- ---------------------------
	2023. 01. 19.	NTsoft 	 최초 생성
*/
let mobileNoticeSelectModal = {
    callback : null,
    reqParam : null,
    dataList : null,
    /* 모달 초기화 작업 */
    init : function () {
        $('#mobileNoticeSelectModal').remove();
        $('body').append( this.HtmlTemplate);
        //그리드 이벤트
        this.setEvent();
    },
    /* 그리드 이벤트 설정 */
    setEvent:function() {
        $('#mobileNoticeSelectModal .btnCancle').on("click", function(){
            mobileNoticeSelectModal.close();
        });
    },
    /* 데이터 선택 */
    setSelect:function(selectNumber) {
        let checkedData = dataList[selectNumber];
        if(dataList==null||checkedData==undefined){
            return ;
        }

        if( mobileNoticeSelectModal.callback )  {
            mobileNoticeSelectModal.callback(checkedData);
        }
        mobileNoticeSelectModal.close();
    },
    // 상세 조회
    search:function(state) {
        let muNoticeId = mobileNoticeSelectModal.reqParam.muNoticeId;

        if(true != fn_emptyCheck(muNoticeId)){
            modalEvent.warning("조회", "공지사항 정보가 없습니다.");
            return;
        }

        let formData = new FormData();
        formData.append("muNoticeId", muNoticeId);

        $.ajax({
            url: encodeURI('/mobilenotice/selectNotice.do'),
            data: formData,
            dataType: "json",
            processData: false,
            contentType: false,
            type: 'POST',
            async: true,
            success: function(data){
                if('0'==data.msgCode){
                    $("#mobileNoticeSelectModal #modalTitle").text(data.rows[0].title);
                    $("#mobileNoticeSelectModal #modalContent").empty().html(data.rows[0].content.replace(/\n/g,"<br/>"));
                    $("#mobileNoticeSelectModal #writeDate").text(data.rows[0].writeDate);
                    $("#mobileNoticeSelectModal #writeTime").text(data.rows[0].writeTime);
                }
                else{
                    modalEvent.danger("조회 오류", data.msgDesc);
                }
            },
            error : function(xhr, status, error) {
                modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
            },
            beforeSend:function(){

            },
            complete:function(){

            }
        });
    },
    /*
     * 팝업
     * callback : 콜백함수, reqParam: 팝업파라미터
     */
    popup:function(callback, reqParam) {
        // 초기화 후 열기
        mobileNoticeSelectModal.init();

        //콜백함수 지정.
        mobileNoticeSelectModal.callback = callback;
        mobileNoticeSelectModal.reqParam = reqParam;
        mobileNoticeSelectModal.dataList = null;

        setTimeout(function(){
            $('#mobileNoticeSelectModal').modal('show')
        }, 200);

        mobileNoticeSelectModal.search();
    },
    /*
     * 팝업 닫기
     */
    close:function() {
        $('#mobileNoticeSelectModal').modal('hide');

		setTimeout(function(){
			$('#mobileNoticeSelectModal').remove();
		},500);
    },
    HtmlTemplate : `
	<div id="mobileNoticeSelectModal" class="modal notice_modal fade" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<p class="label" id="modalTitle"></p>
					<p>
                        <span id="writeDate"></span>
                        <span id="writeTime"></span>
                    </p>
				</div>
	
				<div class="modal-body">
                    <p id="modalContent"></p>
				</div>

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