$(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"); const depth = selectedCategory.attr("data-depth"); let categoryHtml = ""; $("#selectedCategoryDiv").append(categoryHtml); } }) $(document).on('click', '#categoryUpBtn', function (){ $(".categoryRadio:checked").parent().remove(); }) $(document).on('click', '#categorySelectBtn', function (){ const selectedCategory = $(".selectedCategory"); let boardCategory = ""; let categoryNames = ""; selectedCategory.each(function (idx, el){ boardCategory += $(el).attr("data-categoryseq")+","+$(el).attr("data-depth")+"|"; categoryNames += $(el).attr("data-categoryName")+", "; }) $("#boardCategoryAry").val(boardCategory.slice(0, -1)); $("#categoryName").val(categoryNames.slice(0, -2)); $("#categorySelectModal").find(".btn-close").click(); }) $(document).on('click', '#searchBtn', function (){ const param = getSearchParam(); $.ajax({ url: '/board/fullSearchBoardContent', data: param, type: 'GET', processData: false, contentType: false, dataType:"html", success: function(html){ $("#searchResultDiv").empty().append(html) }, error:function(){ } }); }) 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; } 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; } } }