
// 업무리스트 분류 선택
$(document).ready(function () {

    /* 회의록 등록 팝업*/
    $('.mtg-reg').on("click",function(){
        let min_id = $(this).data('idx');
        let options = popSize(800,960);
        let uri = '/html/meeting/mtg_reg.html';
        if(min_id) uri = uri + '?min_id=' + min_id;
        window.open(uri, 'MTG', options + ', toolbar=no, menubar=no, scrollbars=Yes, resizable=no');
    })

    /* 회의록 VIEW 팝업*/
    $('.mtg-view').on("click",function(){
        let min_id = $(this).data('idx');
        let options = popSize(800,960);
        let uri = '/html/meeting/mtg_view.html?min_id=' + min_id;
        window.open(uri, 'MTG', options + ', toolbar=no, menubar=no, scrollbars=Yes, resizable=no');
    })

    /* 이전 회의록 VIEW 팝업*/
    $('.prev-view').on("click",function(){
        let min_id = $(this).data('idx');
        let options = popSize(800,960);
        let uri = '/html/meeting/mtg_view.html?mod=prev&min_id=' + min_id;
        window.open(uri, 'MTG_PREV', options + ', toolbar=no, menubar=no, scrollbars=Yes, resizable=no');
    })

    /* 회의록 수정*/
    $('.mtg-modify').on("click",function(){
        let min_id = $(this).data('idx');
        let uri = '/html/meeting/mtg_reg.html?min_id=' + min_id;
        location.href = uri;
    })


    /* 회의록 등록*/
    $('#mtg-register').on("click",function(){

        var formData = new FormData($('#dailyTaskInput')[0]);
        let min_id = $('#min_id').val();

        for (var i = 0; i < filesArr.length; i++) {
            // 삭제되지 않은 파일만 폼데이터에 담기
            if (!filesArr[i].is_delete) {
                formData.append("attach_file[]", filesArr[i]);
            }
        }

        if(!$('#min_dt').val()){
            alert("날짜를 입력해 주세요");
            return
        }
        if(!$('#title').val()){
            alert("제목을 입력해 주세요.");
            return
        }

        // 로딩바
        $('#status').fadeIn();
        $('#preloader').delay(200).fadeIn();

        $.ajax({
            cache : false,
            url : "/html/process.html", // 요기에
            type: 'POST',
            async: true,
            data: formData,
            contentType: false,
            processData: false,
            headers: {'cache-control': 'no-cache', 'pragma': 'no-cache'},
            success: function(data) {
                if(data=='Success' || data == 'Auth'){
                    top.opener.location.reload();
                    if(min_id) {
                        location.href = 'mtg_view.html?min_id=' + $('#min_id').val();
                    }else{
                        self.close();
                    }
                } else {
                    alert(data);
                    $('#status').fadeOut();
                    $('#preloader').delay(200).fadeOut();
                }
            }, // success

            error : function(xhr, status) {
                alert(xhr + " : " + status);
            }
        }); // $.ajax */
    })


});


