174 lines
4.9 KiB
JavaScript
174 lines
4.9 KiB
JavaScript
|
|
$(function(){
|
|
$("#dateSelectorDiv").datepicker({
|
|
format: "yyyy-mm-dd",
|
|
language: "ko",
|
|
autoclose: true
|
|
});
|
|
})
|
|
|
|
$(document).on('click', '#commentSaveBtn', function (){
|
|
if(!$("#comment").val()) {
|
|
alert("댓글을 입력해주세요.")
|
|
}else{
|
|
if (confirm("등록하시겠습니까?")) {
|
|
contentFade("in")
|
|
const formData = new FormData($("#commentForm")[0]);
|
|
$.ajax({
|
|
type : 'POST',
|
|
data : formData,
|
|
url : "/publicBoard/saveComment",
|
|
processData: false,
|
|
contentType: false,
|
|
dataType:"html",
|
|
beforeSend: function (xhr){
|
|
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
|
|
},
|
|
success : function(html) {
|
|
const parentComment = $("#parentComment");
|
|
if(!parentComment.val()){
|
|
$("#commentDiv").append(html)
|
|
}else{
|
|
$("#childComment"+parentComment.val()).append(html);
|
|
}
|
|
commentFormReset();
|
|
alert("저장되었습니다.");
|
|
contentFade("out");
|
|
},
|
|
error : function(xhr, status) {
|
|
alert("저장에 실패하였습니다.")
|
|
contentFade("out");
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
$(document).on('click', '.childCommentBtn', function (){
|
|
const childCommentFormDiv = $(this).parents(".commentRow").find(".childCommentFormDiv")
|
|
childCommentFormDiv.show();
|
|
$("#parentComment").val($(this).parents(".commentRow").find(".commentKey").val());
|
|
$("#childFormRemoveBtn").show();
|
|
childCommentFormDiv.empty().append($("#commentForm"))
|
|
})
|
|
$(document).on('click', '#childFormRemoveBtn', function (){
|
|
commentFormReset();
|
|
})
|
|
$(document).on('click', '.deleteCommentBtn', function (){
|
|
const commentRow = $(this).parents(".commentRow");
|
|
const publicKey = Number(commentRow.find(".publicKey").val());
|
|
const commentKey = Number(commentRow.find(".commentKey").val());
|
|
$.ajax({
|
|
type : 'POST',
|
|
data : JSON.stringify({publicKey: publicKey, commentKey: commentKey}),
|
|
url : "/publicBoard/deleteComment",
|
|
contentType: 'application/json',
|
|
beforeSend: function (xhr){
|
|
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
|
|
},
|
|
success : function(result) {
|
|
commentRow.remove();
|
|
$("#childComment"+commentKey).remove();
|
|
alert("삭제되었습니다.");
|
|
contentFade("out");
|
|
},
|
|
error : function(xhr, status) {
|
|
alert("삭제를 실패하였습니다.")
|
|
contentFade("out");
|
|
}
|
|
})
|
|
})
|
|
|
|
function getEditModal(publicKey, publicType){
|
|
$.ajax({
|
|
url: '/publicBoard/editModal',
|
|
data: {publicKey: publicKey, publicType: publicType},
|
|
type: 'GET',
|
|
dataType:"html",
|
|
success: function(html){
|
|
$("#editContent").empty().append(html)
|
|
setUploadDiv();
|
|
setEditor('editor', '570');
|
|
$("#editModal").modal('show');
|
|
},
|
|
error:function(e){
|
|
ajaxErrorAction(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
function getViewModal(publicKey, publicType){
|
|
$.ajax({
|
|
url: '/publicBoard/viewModal',
|
|
data: {publicKey: publicKey, publicType: publicType},
|
|
type: 'GET',
|
|
dataType:"html",
|
|
success: function(html){
|
|
$("#viewContent").empty().append(html)
|
|
$("#viewModal").modal('show');
|
|
},
|
|
error:function(e){
|
|
ajaxErrorAction(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
function savePublicBoard(formId, publicType){
|
|
if(contentCheck(formId)){
|
|
if(confirm("저장하시겠습니까?")){
|
|
contentFade("in");
|
|
$("#content").val("");
|
|
const formData = new FormData($("#"+formId)[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 : "/publicBoard/saveContent",
|
|
processData: false,
|
|
contentType: false,
|
|
success : function(result) {
|
|
alert("저장되었습니다.");
|
|
contentFade("out");
|
|
$("#editModal").modal('hide');
|
|
getViewModal(result, publicType);
|
|
},
|
|
error : function(xhr, status) {
|
|
alert("저장에 실패하였습니다.")
|
|
contentFade("out");
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
function contentCheck(formId){
|
|
let flag = true;
|
|
if(!$("#title").val()){
|
|
alert("제목을 입력해주세요.")
|
|
flag = false;
|
|
}
|
|
if($("#publicType").val()==="PLB003"){
|
|
if(!$("#tabStatus").val()){
|
|
alert("분류를 선택해주세요.")
|
|
flag = false;
|
|
}
|
|
}
|
|
flag = fileCheck(flag, files);
|
|
return flag;
|
|
}
|
|
|
|
function commentFormReset(){
|
|
const commentForm = $("#commentForm");
|
|
commentForm[0].reset();
|
|
$("#childFormRemoveBtn").hide();
|
|
$("#parentComment").val('');
|
|
$("#commentFormHome").append(commentForm)
|
|
}
|