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

171 lines
5.2 KiB
JavaScript
Raw Normal View History

2021-12-20 09:40:21 +00:00
$(function (){
$("#selectedCategoryDiv").sortable();
})
$(document).on('click', '#categoryName', function (){
$("#categorySelectModalBtn").click();
})
$(document).on('click', '.categoryTr', function (){
const checkBox = $(this).find(".categoryCheckBox");
const depth = Number(checkBox.attr("data-depth"));
const categorySeq = checkBox.attr("data-categoryseq");
$(".depth"+depth+"Tr").find(".categoryCheckBox").prop("checked", false);
checkBox[0].checked = true;
setCategoryTable(depth+1, categorySeq);
})
$(document).on('click', '#categoryDownBtn', function (){
const selectedCategory = getSelectedCategory();
const categorySeq = selectedCategory.attr("data-categoryseq");
if(parentCheck(categorySeq)){
childCheck(categorySeq);
const categoryName = selectedCategory.attr("data-categoryname");
2021-12-21 02:43:29 +00:00
const depth = selectedCategory.attr("data-depth");
2021-12-20 09:40:21 +00:00
let categoryHtml = "<li class='nav-item mx-3 btn btn-secondary btn-sm selectedCategory'" +
2021-12-21 02:43:29 +00:00
" id='selectedCategory"+categorySeq+"' data-categoryseq='"+categorySeq+"'" +
" data-categoryname='"+categoryName+"' data-depth='"+depth+"'>" +
2021-12-20 09:40:21 +00:00
"<input type='radio' class='categoryRadio' id='categoryRadio"+categorySeq+"' name='categoryRadio'>"+
"<label for='categoryRadio"+categorySeq+"'> "+categoryName+"</label></li>";
$("#selectedCategoryDiv").append(categoryHtml);
}
})
$(document).on('click', '#categoryUpBtn', function (){
$(".categoryRadio:checked").parent().remove();
})
$(document).on('click', '#categorySelectBtn', function (){
const selectedCategory = $(".selectedCategory");
2021-12-21 02:43:29 +00:00
let boardCategory = "";
2021-12-20 09:40:21 +00:00
let categoryNames = "";
selectedCategory.each(function (idx, el){
2021-12-21 02:43:29 +00:00
boardCategory += $(el).attr("data-categoryseq")+","+$(el).attr("data-depth")+"|";
2021-12-20 09:40:21 +00:00
categoryNames += $(el).attr("data-categoryName")+", ";
})
2021-12-21 02:43:29 +00:00
$("#boardCategoryAry").val(boardCategory.slice(0, -1));
2021-12-20 09:40:21 +00:00
$("#categoryName").val(categoryNames.slice(0, -2));
$("#categorySelectModal").find(".btn-close").click();
})
$(document).on('click', '#searchBtn', function (){
2021-12-21 02:43:29 +00:00
const param = getSearchParam();
2021-12-20 09:40:21 +00:00
$.ajax({
2021-12-21 02:43:29 +00:00
url: '/board/fullSearchBoardContent',
data: param,
2021-12-20 09:40:21 +00:00
type: 'GET',
2021-12-21 02:43:29 +00:00
processData: false,
contentType: false,
2021-12-20 09:40:21 +00:00
dataType:"html",
success: function(html){
2021-12-21 02:43:29 +00:00
$("#searchResultDiv").empty().append(html)
2021-12-20 09:40:21 +00:00
},
error:function(){
}
});
})
2021-12-21 02:43:29 +00:00
function getSearchParam(){
const param = {board: {}};
let boardCategoryAry = $("#boardCategoryAry").val();
if(boardCategoryAry){
boardCategoryAry = boardCategoryAry.split('|');
param.boardCategoryList = [];
boardCategoryAry.forEach((value) => {
const boardCategory = value.split(',');
param.boardCategoryList.push({categorySeq: boardCategory[0], depth: boardCategory[1]});
})
}
const title = $("#title").val();
if(title){
param.board.title = title;
}
const createName = $("#createName").val();
if(createName){
param.board.createName = createName;
}
let tagNameAry = $("#tagName").val();
if(tagNameAry){
tagNameAry = tagNameAry.split(',')
param.hasTagList = [];
tagNameAry.forEach((value => {
param.hasTagList.push({tagName: value})
}))
}
const startDate = $("#startDate").val();
if(startDate){
param.board.startDate = startDate;
}
const endDate = $("#endDate").val();
if(endDate){
param.board.endDate = endDate;
}
const originalName = $("#originalName").val();
if(originalName){
param.board.searchFileName = originalName;
}
return param;
}
2021-12-20 09:40:21 +00:00
function parentCheck(categorySeq){
const radio = $("#categoryRadio"+categorySeq);
if(radio.length>0){
alert("상위 분류 "+radio.parent().attr("data-categoryname")+"이(가) 선택되어 있습니다.")
return false;
}else{
const parentseq = $("[data-categoryseq='"+categorySeq+"']").parents("tr").attr("data-parentseq");
if(!parentseq){
return true;
}else{
return parentCheck(parentseq);
}
}
}
function childCheck(parentSeq){
const childCategorys = $("[data-parentseq='"+parentSeq+"']");
childCategorys.each(function (idx, el){
const categorySeq = $(el).find(".categoryCheckBox").attr("data-categoryseq");
const radio = $("#categoryRadio"+categorySeq)
if(radio.length>0){
alert("하위분류 "+radio.parent().attr("data-categoryname")+"가 삭제되었습니다.");
radio.parent().remove();
}
childCheck(categorySeq);
})
}
function setCategoryTable(depth, parentSeq){
setTableDefault(depth);
let childCategoryIsNull = true;
const nextTr = $(".depth"+depth+"Tr");
nextTr.each(function (idx, el){
const tr = $(el)
if(tr.attr("data-parentseq")===parentSeq){
tr.show();
childCategoryIsNull = false;
}else{
tr.hide();
}
})
if(childCategoryIsNull){
$(nextTr[0]).show();
}
}
function setTableDefault(depth){
for(let i=depth; i<=4; i++){
const nextDepthTr = $(".depth"+i+"Tr");
nextDepthTr.hide();
nextDepthTr.find(".categoryCheckBox").prop("checked", false);
$(nextDepthTr[0]).show();
}
}
function getSelectedCategory(){
for(let i=4; i>0; i--){
const checkBox = $(".depth"+i+"Tr").find(".categoryCheckBox:checked")
if(checkBox.length>0){
return checkBox;
}
}
}