

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

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

        if(true != fn_emptyCheck(muPushId)){
            modalEvent.warning("조회", "알림 정보가 없습니다.");
            return;
        }

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

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

            },
            complete:function(){

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

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

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

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

        if(mobilePushSelectModal.callback){
            mobilePushSelectModal.callback();
        }

		setTimeout(function(){
			$('#mobilePushSelectModal').remove();
		},500);
    },
    HtmlTemplate : `
    <div class="modal noticeSelect_modal fade" id="mobilePushSelectModal" 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="sendDate">2021-07-07</span>,
                        <span id="sendTime">14:00</span>
                    </p>
                </div>
    
                <div class="modal-body">
                    <p id="modalContent">
                        OOO 님, 진료 접수가 완료 되었습니다.
                        데스크에서 안내가 있을 때 까지 잠시만 기다려주세요!
                    </p>
                </div>
    
                <div class="modal-footer">
                    <div class="btn_box">
                        <button class="ok_btn">확인</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    `
};