let eduList=[]; let selectedIdx=0; $(document).on('click', '.policeTr', function (event){ const target = event.target; if(!(target.className === "checkBoxTd" ||$(target).parents("td").length>0)){ const userSeq = (Number($(this).find(".userSeq").val())); showModal(userSeq); } }); function showModal(userSeq){ $.ajax({ url: '/police/eduEditModal', data: {userSeq: userSeq}, type: 'GET', dataType:"html", success: function(html){ $("#eduEditModalContent").empty().append(html); $(".dateSelector").datepicker({ format: "yyyy-mm-dd", language: "ko", autoclose: true }); $("#eduEditModal").modal('show'); }, error:function(e){ ajaxErrorAction(e); } }); } $(document).on('click', '#previousTab', function (){ const userStatus = $(this).data('userstatus'); location.href = "/police/educationMgt?userStatus="+userStatus; }) $(document).on('click', '#presentTab', function (){ const userStatus = $(this).data('userstatus'); location.href = "/police/educationMgt?userStatus="+userStatus; }) $(document).on('click', '#notPoliceTab', function (){ const userStatus = $(this).data('userstatus'); location.href = "/police/educationMgt?userStatus="+userStatus; }) $(document).on('click', '#eduAddBtn', function (){ const userSeq = (Number($(this).data('userseq'))); $('#insertEdu').append( '
'+ '
'+ ''+ '
'+ ''+ '
'+ ''+ '
'+ ''+ '
'+ ''+ '
'+ ''+ '
'+ ''+ '
'+ ''+ '
'+ '
'+ '
'+ '
'+ ''+ '
'+ '
'+ '
' ) $(".eduSdate").datepicker({ format: "yyyy-mm-dd", language: "ko", autoclose: true }); $(".eduEdate").datepicker({ format: "yyyy-mm-dd", language: "ko", autoclose: true }); eduList.push({userSeq:userSeq, eduName:"",eduSdate:"",eduEdate:"",eduRa:""}); }) $(document).on('click', '.rowDeleteBtn', function (){ selectedIdx = $(this).parents("#eduDiv").index()-1; eduList.splice(selectedIdx,1); $(this).parents('#eduDiv').remove(); }) $(document).on('change', '.eduInput', function (){ selectedIdx = $(this).parents("#eduDiv").index()-1; const target = eduList[selectedIdx]; switch (this.name){ case "eduName": target.eduName = this.value break; case "eduSdate": target.eduSdate = this.value break; case "eduEdate": target.eduEdate = this.value break; case "eduRa": target.eduRa = this.value break; } }) $(document).on('click', '#saveBtn', function (){ if(eduList.length < 1){ alert("새로 입력된 교육정보가 없습니다."); return false; } if(confirm("저장하시겠습니까?")){ contentFade("in"); $.ajax({ type : 'POST', data : JSON.stringify(eduList), url : "/police/saveEdu", contentType: 'application/json', beforeSend: function (xhr){ xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); }, success : function(data) { contentFade("out"); alert("교육등록이 완료되었습니다."); showModal(data); eduList.length = 0; }, error : function(xhr, status) { contentFade("out"); alert("교육등록을 실패하였습니다"); } }) } }) $(document).on('click', '#deleteBtn', function (){ const eduSeq = (Number($(this).data('eduseq'))); const userSeq = (Number($(this).data('userseq'))); if(confirm("삭제하시겠습니까?")){ $.ajax({ type : 'POST', url : "/police/deleteEdu", data : JSON.stringify({eduSeq:eduSeq, userSeq:userSeq}), contentType: 'application/json', beforeSend: function (xhr){ xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); }, success : function(data) { alert("삭제 처리되었습니다."); showModal(data); }, error : function(xhr, status) { alert("삭제 처리에 실패하였습니다"); } }) } })