From 278c16306ec849c014c4428341beaf282da64173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=84=9D=20=EC=B5=9C?= Date: Wed, 24 Aug 2022 17:27:30 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A9=94=EB=89=B4=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EA=B2=80=EC=83=89,=20=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faisp/controller/MenuMgtController.java | 16 ++ .../dbnt/faisp/menuMgt/MenuMgtService.java | 56 +++++- .../com/dbnt/faisp/menuMgt/model/MenuMgt.java | 7 +- src/main/resources/application-dev.properties | 2 +- .../resources/mybatisMapper/menuMgtMapper.xml | 7 +- src/main/resources/static/js/common.js | 12 +- .../resources/static/js/menuMgt/menuMgt.js | 77 +++++++- .../templates/adminPage/codeMgt/codeMgt.html | 2 +- .../adminPage/menuMgt/menuEditModal.html | 71 ++++++++ .../templates/adminPage/menuMgt/menuMgt.html | 171 +++++++----------- 10 files changed, 303 insertions(+), 118 deletions(-) create mode 100644 src/main/resources/templates/adminPage/menuMgt/menuEditModal.html diff --git a/src/main/java/com/dbnt/faisp/controller/MenuMgtController.java b/src/main/java/com/dbnt/faisp/controller/MenuMgtController.java index 4ea4cb15..338ea287 100644 --- a/src/main/java/com/dbnt/faisp/controller/MenuMgtController.java +++ b/src/main/java/com/dbnt/faisp/controller/MenuMgtController.java @@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; +import java.util.List; + @RestController @RequiredArgsConstructor @@ -25,9 +27,23 @@ public class MenuMgtController { return mav; } + @GetMapping("/menuEditModal") + public ModelAndView menuEditModal(MenuMgt menuMgt){ + ModelAndView mav = new ModelAndView("/adminPage/menuMgt/menuEditModal"); + mav.addObject("menuMgt", menuMgt); + return mav; + } + @PostMapping("/saveMenuMgt") public String saveMenuMgt(MenuMgt menuMgt){ return menuMgtService.saveMenuMgt(menuMgt); } + @PostMapping("/deleteMenuMgt") + @ResponseBody + public String deleteMenuMgt(@RequestBody List menuMgt){ + menuMgtService.deleteMenuMgt(menuMgt); + return ""; + } + } diff --git a/src/main/java/com/dbnt/faisp/menuMgt/MenuMgtService.java b/src/main/java/com/dbnt/faisp/menuMgt/MenuMgtService.java index b1d15f4f..aef3a8f5 100644 --- a/src/main/java/com/dbnt/faisp/menuMgt/MenuMgtService.java +++ b/src/main/java/com/dbnt/faisp/menuMgt/MenuMgtService.java @@ -17,7 +17,8 @@ public class MenuMgtService { private final MenuMgtMapper menuMgtMapper; public List selectMenuMgtList(MenuMgt menuMgt){ - return menuMgtMapper.selectMenuMgtList(menuMgt); + List menuList = menuMgtMapper.selectMenuMgtList(menuMgt); + return menuListRowspanSet(menuList); } public Integer selectMenuMgtListCnt(MenuMgt menuMgt){ @@ -26,12 +27,59 @@ public class MenuMgtService { @Transient public String saveMenuMgt(MenuMgt menuMgt) { - MenuMgt duplMenu = menuMgtRepository.findTopByCat1CdAndCat2CdAndCat3Cd(menuMgt.getCat1Cd(), menuMgt.getCat2Cd(), menuMgt.getCat3Cd()); - if(duplMenu!=null){ - return duplMenu.getMenuUrl(); + if(menuMgt.getMenuKey()==null){ + MenuMgt duplMenu = menuMgtRepository.findTopByCat1CdAndCat2CdAndCat3Cd(menuMgt.getCat1Cd(), menuMgt.getCat2Cd(), menuMgt.getCat3Cd()); + if(duplMenu!=null){ + return duplMenu.getMenuUrl(); + }else{ + menuMgtRepository.save(menuMgt); + return ""; + } }else{ menuMgtRepository.save(menuMgt); return ""; } } + + @Transient + public void deleteMenuMgt(List menuList) { + menuMgtRepository.deleteAll(menuList); + } + + private List menuListRowspanSet(List menuList){ + for(int i=0; i diff --git a/src/main/resources/static/js/common.js b/src/main/resources/static/js/common.js index e47522fe..07f1e7db 100644 --- a/src/main/resources/static/js/common.js +++ b/src/main/resources/static/js/common.js @@ -17,4 +17,14 @@ function sessionReload(){ $(document).on('click', '.allChk', function (){ $(this).parents('table').find('[type="checkbox"]').prop("checked", this.checked); -}) \ No newline at end of file +}) +$(document).on('click', '.page-item', function (){ + searchFormSubmit($(this).attr("data-pageindex")) +}) +$(document).on('change', '#rowCnt', function (){ + searchFormSubmit(1) +}) +function searchFormSubmit(pageIndex){ + $("#pageIndex").val(pageIndex); + $("#searchBtn").click(); +} \ No newline at end of file diff --git a/src/main/resources/static/js/menuMgt/menuMgt.js b/src/main/resources/static/js/menuMgt/menuMgt.js index ee0c5cee..42c2f8db 100644 --- a/src/main/resources/static/js/menuMgt/menuMgt.js +++ b/src/main/resources/static/js/menuMgt/menuMgt.js @@ -1,5 +1,23 @@ - +$(document).on('click', '#addMenuBtn', function (){ + $("#menuEditModalLabel").text("메뉴 추가") + getModalForm(); +}) +$(document).on('click', '.menuTr', function (event){ + if(event.target.classList.value!=="menuCheckBox"){ + if(event.target.cellIndex !== 0){ + $("#menuEditModalLabel").text("메뉴 수정") + const row = $(this) + getModalForm({ + menuKey: row.find(".menuKey").val(), + cat1Cd: row.find(".cat1Cd").val(), + cat2Cd: row.find(".cat2Cd").val(), + cat3Cd: row.find(".cat3Cd").val(), + menuUrl: row.find(".menuUrl").val() + }) + } + } +}) $(document).on('click', '#saveMenuBtn', function (){ let valueChk = true; if(!$("#cat1Cd").val()){ @@ -30,7 +48,7 @@ $(document).on('click', '#saveMenuBtn', function (){ if(result!==""){ alert("url: "+result+"로 저장되어있습니다.") }else{ - location.reload(); + // location.reload(); alert("저장되었습니다.") } contentFade("out"); @@ -41,4 +59,57 @@ $(document).on('click', '#saveMenuBtn', function (){ } }) } -}) \ No newline at end of file +}) +$(document).on('click', '#deleteMenuBtn', function (){ + if(confirm("삭제 하시겠습니까?")){ + deleteMenu([{menuKey: Number($("#menuKey").val())}]) + } +}) +$(document).on('click', '#deleteCheckedBtn', function (){ + if(confirm("선택된 대상을 모두 삭제 하시겠습니까?")){ + const menuList = []; + $(".menuCheckBox:checked").each(function (idx, el){ + menuList.push({}); + const target = $(el); + menuList[idx].menuKey = Number(target.parents('tr').find('.menuKey').val()); + }) + deleteMenu(menuList) + } +}) +function getModalForm(menuMgt){ + $.ajax({ + url: '/menuMgt/menuEditModal', + data: menuMgt, + type: 'GET', + dataType:"html", + success: function(html){ + $("#menuEditModalContent").empty().append(html) + $("#menuEditModal").modal('show') + }, + error:function(){ + + } + }); +} + +function deleteMenu(menuList){ + contentFade("in"); + $.ajax({ + type : 'POST', + url : "/menuMgt/deleteMenuMgt", + data : JSON.stringify(menuList), + contentType: 'application/json', + beforeSend: function (xhr){ + xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); + }, + success : function(data) { + alert("삭제되었습니다."); + contentFade("out"); + location.reload(); + }, + error : function(xhr, status) { + alert("삭제를 실패하였습니다.") + contentFade("out"); + } + }) +} \ No newline at end of file diff --git a/src/main/resources/templates/adminPage/codeMgt/codeMgt.html b/src/main/resources/templates/adminPage/codeMgt/codeMgt.html index 86abfe2b..3fba41a6 100644 --- a/src/main/resources/templates/adminPage/codeMgt/codeMgt.html +++ b/src/main/resources/templates/adminPage/codeMgt/codeMgt.html @@ -3,7 +3,7 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{layout/layout}"> - +
diff --git a/src/main/resources/templates/adminPage/menuMgt/menuEditModal.html b/src/main/resources/templates/adminPage/menuMgt/menuEditModal.html new file mode 100644 index 00000000..36b8d97a --- /dev/null +++ b/src/main/resources/templates/adminPage/menuMgt/menuEditModal.html @@ -0,0 +1,71 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/adminPage/menuMgt/menuMgt.html b/src/main/resources/templates/adminPage/menuMgt/menuMgt.html index 895ddfbc..e20d37b0 100644 --- a/src/main/resources/templates/adminPage/menuMgt/menuMgt.html +++ b/src/main/resources/templates/adminPage/menuMgt/menuMgt.html @@ -8,46 +8,61 @@

메뉴 관리

+ +
-
-
- +
+
+ + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
-
- -
-
- -
-
- -
- -
+
@@ -56,7 +71,7 @@ - + @@ -64,18 +79,23 @@ - + + + + + + - + - + - + - + @@ -92,7 +112,9 @@
대분류 중분류 소분류
-
+
+ +
- +
@@ -133,66 +155,7 @@