FAISP/src/main/resources/static/js/publicBoard/publicBoard.js

180 lines
5.0 KiB
JavaScript
Raw Normal View History

2022-09-19 09:20:49 +00:00
$(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,
2022-09-20 05:09:20 +00:00
dataType:"html",
2022-09-19 09:20:49 +00:00
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
2022-09-20 05:09:20 +00:00
success : function(html) {
$("#commentDiv").append(html)
$("#comment").summernote('code', '')
const parentComment = $("#parentComment");
if(parentComment.val()){
parentComment.val('');
$("#commentFormHome").append($("#commentForm"))
}
2022-09-19 09:20:49 +00:00
alert("저장되었습니다.");
contentFade("out");
},
error : function(xhr, status) {
alert("저장에 실패하였습니다.")
contentFade("out");
}
})
}
}
})
2022-09-27 08:57:27 +00:00
$(function(){
$("#dateSelectorDiv").datepicker({
format: "yyyy-mm-dd",
language: "ko",
autoclose: true
2022-09-27 08:57:27 +00:00
});
})
2022-09-19 09:20:49 +00:00
$(document).on('click', '.childCommentBtn', function (){
const childCommentDiv = $(this).parents(".commentRow").find(".childCommentDiv")
childCommentDiv.show();
$("#parentComment").val($(this).parents(".commentRow").find(".commentKey").val());
childCommentDiv.empty().append($("#commentForm"))
})
$(document).on('click', '.deleteCommentBtn', function (){
2022-09-20 05:09:20 +00:00
const commentRow = $(this).parents(".commentRow");
const publicKey = Number(commentRow.find(".publicKey").val());
const commentKey = Number(commentRow.find(".commentKey").val());
2022-09-19 09:20:49 +00:00
$.ajax({
type : 'POST',
2022-09-20 05:09:20 +00:00
data : JSON.stringify({publicKey: publicKey, commentKey: commentKey}),
2022-09-19 09:20:49 +00:00
url : "/publicBoard/deleteComment",
2022-09-20 05:09:20 +00:00
contentType: 'application/json',
2022-09-19 09:20:49 +00:00
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(result) {
2022-09-20 05:09:20 +00:00
commentRow.remove();
2022-09-19 09:20:49 +00:00
alert("삭제되었습니다.");
contentFade("out");
},
error : function(xhr, status) {
alert("삭제를 실패하였습니다.")
contentFade("out");
}
})
})
2022-09-20 06:05:16 +00:00
2022-09-19 09:20:49 +00:00
function getEditModal(publicKey, publicType){
$.ajax({
url: '/publicBoard/editModal',
data: {publicKey: publicKey, publicType: publicType},
type: 'GET',
dataType:"html",
success: function(html){
$("#editContent").empty().append(html)
$("#content").summernote({
2022-09-19 09:20:49 +00:00
lang:'ko-KR',
height: 350,
disableDragAndDrop: true,
toolbar: [
['style', ['style']],
['font', ['bold', 'underline', 'clear']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']]
]
});
2022-09-19 09:20:49 +00:00
setUploadDiv();
$("#editModal").modal('show');
},
error:function(){
}
});
}
function getViewModal(publicKey, publicType){
$.ajax({
url: '/publicBoard/viewModal',
data: {publicKey: publicKey, publicType: publicType},
type: 'GET',
dataType:"html",
success: function(html){
$("#viewContent").empty().append(html)
$("#comment").summernote({
lang:'ko-KR',
height: 100,
disableDragAndDrop: true,
toolbar: [
['style', ['style']],
['font', ['bold', 'underline', 'clear']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']]
]
});
$("#viewModal").modal('show');
},
error:function(){
}
});
}
2022-09-20 06:05:16 +00:00
function savePublicBoard(formId, publicType){
2022-09-19 09:20:49 +00:00
if(contentCheck(formId)){
if(confirm("저장하시겠습니까?")){
contentFade("in");
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"));
})
$.ajax({
type : 'POST',
data : formData,
url : "/publicBoard/saveContent",
processData: false,
contentType: false,
success : function(result) {
alert("저장되었습니다.");
contentFade("out");
$("#editModal").modal('hide');
2022-09-20 06:05:16 +00:00
getViewModal(result, publicType);
2022-09-19 09:20:49 +00:00
},
error : function(xhr, status) {
alert("저장에 실패하였습니다.")
contentFade("out");
}
})
}
}
}
function contentCheck(formId){
let flag = true;
if(!$("#title").val()){
alert("제목을 입력해주세요.")
flag = false;
}
2022-10-14 01:17:05 +00:00
if($("#publicType").val()==="PLB003"){
if(!$("#tabStatus").val()){
alert("분류를 선택해주세요.")
flag = false;
}
}
2022-09-20 05:09:20 +00:00
flag = fileCheck(flag, files);
2022-09-19 09:20:49 +00:00
return flag;
}