FAISP/src/main/resources/static/js/counterIntelligence/ciWork.js

169 lines
4.4 KiB
JavaScript

$(document).on('click', '#ciWorkTab', function (){
location.href="/counterIntelligence/ciWorkList";
})
$(document).on('click', '#performanceTab', function (){
location.href="/counterIntelligence/CiWorkStatistics";
})
$(document).on('change', '#statisticsYear', function (){
location.href="/counterIntelligence/CiWorkStatistics?year="+this.value;
})
$(document).on('click', '#addCiWorkBtn', function (){
getCiWorkEditModal(null);
})
$(document).on('click', '#saveTempBtn,#saveCiWorkBtn', function(){
saveCiWork($(this).attr("data-status"));
})
$(document).on('click', '.ciWorkTr', function (){
getCiWorkViewModal($(this).find(".ciwKey").val());
})
$(document).on('click', '#editCiWorkBtn', function (){
$("#ciWorkViewModal").modal('hide');
getCiWorkEditModal($(this).attr("data-ciwkey"));
})
$(document).on('click', '#deleteCiWorkBtn', function (){
deleteCiWork($(this).attr("data-ciwkey"));
})
function getCiWorkEditModal(ciwKey){
$.ajax({
url: '/counterIntelligence/ciWorkEditModal',
data: {ciwKey: ciwKey},
type: 'GET',
dataType:"html",
success: function(html){
$("#ciWorkEditModalContent").empty().append(html)
$(".dateSelector").datepicker({
format: "yyyy-mm-dd",
language: "ko",
autoclose: true
});
setUploadDiv();
setEditor('editor', '400');
$("#ciWorkEditModal").modal('show');
},
error:function(e){
ajaxErrorAction(e);
}
});
}
function getCiWorkViewModal(ciwKey){
$.ajax({
url: '/counterIntelligence/ciWorkViewModal',
data: {ciwKey: ciwKey},
type: 'GET',
dataType:"html",
success: function(html){
$("#ciWorkViewModalBody").empty().append(html)
$("#ciWorkViewModal").modal('show');
},
error:function(e){
ajaxErrorAction(e);
}
});
}
function saveCiWork(status){
if(confirm("저장하시겠습니까?")){
let flag = true;
if(status === "DST007"){
flag = contentCheck();
}
if(flag){
contentFade("in");
const ciWorkEditForm = $("#ciWorkEditForm");
ciWorkEditForm.find("#status").val(status);
const formData = new FormData(ciWorkEditForm[0]);
for(const file of files) {
if(!file.isDelete)
formData.append('uploadFiles', file, file.name);
}
$(".text-decoration-line-through").each(function (idx, el){
formData.append('fileSeq', $(el).attr("data-fileseq"));
})
formData.append('content', CrossEditor.GetBodyValue());
$.ajax({
type : 'POST',
data : formData,
url : "/counterIntelligence/saveCiWork",
processData: false,
contentType: false,
success : function(result) {
alert("저장되었습니다.");
contentFade("out");
$("#ciWorkEditModal").modal('hide');
//getCiWorkViewModal(result);
location.reload();
},
error : function(xhr, status) {
alert("저장에 실패하였습니다.")
contentFade("out");
}
})
}
}
}
function deleteCiWork(ciwKey){
if(confirm("삭제하시겠습니까?")){
contentFade("in");
const formData = new FormData();
formData.append('ciwKey', ciwKey);
$.ajax({
type : 'POST',
data : formData,
url : "/counterIntelligence/deleteCiWork",
processData: false,
contentType: false,
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(result) {
alert("삭제되었습니다.");
contentFade("out");
location.reload();
},
error : function(xhr, status) {
alert("삭제를 실패하였습니다.")
contentFade("out");
}
})
}
}
function contentCheck(){
if(!$("#workStartDate").val()){
alert("착수일을 입력해주세요.")
return false;
}
if(!$("#workPlanDate").val()){
alert("예정일을 입력해주세요.")
return false;
}
if(!$("#reRatingDate1").val()){
alert("1차재평가를 입력해주세요.")
return false;
}
if(!$("#reRatingDate2").val()){
alert("2차재평가를 입력해주세요.")
return false;
}
if(!$("#workRating").val()){
alert("등급을 선택해주세요.")
return false;
}
if(!$("#title").val()){
alert("공작명을 입력해주세요.")
return false;
}
if(!$("#summaryInfo").val()){
alert("사건개요를 입력해주세요.")
return false;
}
return true;
}