kcgFileManager/src/main/resources/static/js/board/contentList.js

116 lines
3.2 KiB
JavaScript

$(function(){
setSearchCondition();
$("#dateSelectorDiv").datepicker({
format: "yyyy-mm-dd",
language: "ko"
});
})
$(document).on('click', '.contentTr', function (){
$(".contentCheckBox").prop('checked', false);
const target = $(this).find(".contentCheckBox")[0];
target.checked = true;
const selectedTab = $(".nav-tabs").find(".active")[0].id;
if(selectedTab === "contentTab"){
getBoardContent(target.value);
}else if(selectedTab === "logTab"){
getBoardLog(target.value);
}
})
$(document).on('change', '#fileCheckAll', function (){
$(".fileCheckBox").prop("checked", this.checked);
})
$(document).on('click', '#contentTab', function (){
getBoardContent(getContentSeq())
})
$(document).on('click', '#logTab', function (){
getBoardLog(getContentSeq())
})
$(document).on('click', '.fileDownLink', function (){
let url = "/board/fileDownload?"
url += "contentSeq="+Number($("#detailViewContentSeq").val());
url += "&fileSeq="+$(this).attr("data-fileseq");
window.open(encodeURI(url));
})
$(document).on('click', '#zipDownBtn', function (){
const checkFiles = $(".fileCheckBox:checked");
if(checkFiles.length>0){
let url = "/board/fileDownloadToZip?"
url += "contentSeq="+Number($("#detailViewContentSeq").val());
checkFiles.each(function (idx, el){
url += "&fileSeq="+Number($(el).attr("data-fileseq"))
});
window.open(encodeURI(url));
}else{
alert("선택된 파일이 없습니다.")
}
})
$(document).on('click', '#deleteBtn', function (){
if(confirm("이 게시물을 삭제하시겠습니까?\n되돌릴 수 없습니다.")){
$.ajax({
type : 'DELETE',
url : "/board/deleteContent",
data : {contentSeq: Number($(this).attr("data-contentseq"))},
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(data) {
alert("저장되었습니다.");
location.reload();
},
error : function(xhr, status) {
}
})
}
})
$(document).on('click', '#modifyBtn', function (){
location.href = "/board/contentWrite?contentSeq="+Number($(this).attr("data-contentseq"));
})
function getContentSeq(){
return $(".contentCheckBox:checked").val();
}
function getBoardContent(contentSeq){
if(contentSeq !== undefined){
const viewContentSeq = $("#detailViewContentSeq").val();
if(contentSeq !== viewContentSeq){
$.ajax({
url: '/board/selectBoardContent',
data: {contentSeq: contentSeq},
type: 'GET',
dataType:"html",
success: function(html){
$("#contentDiv").empty().append(html)
if($("#contentStatus").val() !== "D"){
const viewCntTd = $(".contentCheckBox:checked").parents("tr").find(".viewCntTd");
viewCntTd.text(Number(viewCntTd.text())+1);
}
},
error:function(){
}
});
}
}
}
function getBoardLog(contentSeq){
if(contentSeq !== undefined){
$.ajax({
url: '/board/selectBoardLog',
data: {contentSeq: contentSeq},
type: 'GET',
dataType:"html",
success: function(html){
$("#logDiv").empty().append(html)
},
error:function(){
}
});
}
}