$(document).ready(function () {


    /* Member 등록/수정 팝업*/
    $('.member-reg').on("click",function(){
        let user_no = $(this).data('idx');
        popUserMember(user_no);
    })


    /* Member 수정*/
    $('#btn-register').on("click",function(){
        var formData = $("#dailyTaskInput").serialize();

        if(!$("#pln_title").val()){
            alert('업무내용을 입력해 주세요.');
            $("#pln_title").focus();
            return;
        }

        $.ajax({
            cache : false,
            url : "/html/process.html", // 요기에
            type : 'POST',
            data : formData,
            success : function(data) {
                if(data=='Success' || data == 'Auth'){
                    top.opener.location.reload();
                    self.close();
                }
                else alert(data);
            }, // success

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


    /* Member 삭제*/
    $('.btn-delete').on("click",function(){
        let user_no = $(this).data('idx')
        let refpage = '/html/member/member_Add.html';

        if(!user_no){
            alert('회원정보가 아닙니다.');
            return;
        }

        if(!confirm('해당 직원을 탈퇴 시키시겠습니까?')) return;

        $.ajax({
            cache : false,
            url : "/html/process.html",
            type : 'POST',
            data : {user_no:user_no,mod:'del',refpage:refpage },
            success : function(data) {
                if(data=='Success') location.reload();
                else alert(data);
            }, // success

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


    /* 관리자 등록 */
    $('.btn-admin').on("click",function(){
        let user_no = $(this).data('idx')
        let refpage = '/html/member/member_Add.html';

        if(!user_no){
            alert('회원정보가 아닙니다.');
            return;
        }

        if(!confirm('해당 직원을 관리자로 등록 하시겠습니까?')) return;

        $.ajax({
            cache : false,
            url : "/html/process.html",
            type : 'POST',
            data : {user_no:user_no,mod:'admin',refpage:refpage },
            success : function(data) {
                if(data=='Success') location.reload();
                else alert(data);
            }, // success

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