
$(document).on('click', '#addPlanBtn', function (){
    $.ajax({
        url: '/fpiMgt/planEditModal',
        data: {planKey: null},
        type: 'GET',
        dataType:"html",
        success: function(html){
            $("#planEditBody").empty().append(html)
            $("#planEditModal").modal('show');
            $("#planDt").datepicker({
                format: "yyyy-mm-dd",
                language: "ko"
            });
        },
        error:function(){

        }
    });
})

$(document).on('click', '#planAddBtn', function (){
    $("#planDiv").append("<input type='text' class='form-control' name='planInfos'>")
})

$(document).on('click', '#detailPlanAddBtn', function (){
    const detailPlanDiv = $("#detailPlanDiv");
    detailPlanDiv.append("<textarea type='text' name='detailPlanInfos'></textarea>");
    const lastAppendTextarea = detailPlanDiv.children()[detailPlanDiv.children().length-1];
    $(lastAppendTextarea).summernote({
        lang:'ko-KR',
        height: 120,
        disableDragAndDrop: true,
        toolbar: [
            ['style', ['style']],
            ['font', ['bold', 'underline', 'clear']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['table', ['table']]
        ]
    });
})

$(document).on('click', '#savePlanBtn', function (){
    savePlan('S')
})
$(document).on('click', '#saveTempBtn', function (){
    savePlan('T')
})

function savePlan(planState){
    if(confirm("저장하시겠습니까?")){
        $("#planState").val(planState);
        contentFade("in");
        const formData = new FormData($("#planEditForm")[0]);
        $.ajax({
            type : 'POST',
            data : formData,
            url : "/fpiMgt/savePlan",
            processData: false,
            contentType: false,
            success : function(result) {
                debugger
                contentFade("out");
            },
            error : function(xhr, status) {
                alert("저장에 실패하였습니다.")
                contentFade("out");
            }
        })
    }
}