瀏覽代碼

메뉴ID 중복체크 기능 추가

gagamel 4 年之前
父節點
當前提交
3ae14c0f2d

+ 9 - 0
src/main/java/com/style24/admin/biz/dao/TsaSystemDao.java

@@ -109,6 +109,15 @@ public interface TsaSystemDao {
 	 */
 	Collection<Menu> getMenuList(Menu menu);
 
+	/**
+	 * 메뉴ID 건수 조회
+	 * @param menuId - 메뉴ID
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 7. 16
+	 */
+	int getMenuIdCount(String menuId);
+
 	/**
 	 * 메뉴 등록/수정
 	 * @param menu - 메뉴 정보

+ 11 - 0
src/main/java/com/style24/admin/biz/service/TsaSystemService.java

@@ -289,6 +289,17 @@ public class TsaSystemService {
 		}
 	}
 
+	/**
+	 * 메뉴ID 건수 조회
+	 * @param menuId - 메뉴ID
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 7. 16
+	 */
+	public int getMenuIdCount(String menuId) {
+		return systemDao.getMenuIdCount(menuId);
+	}
+
 	/**
 	 * 메뉴 등록/수정 및 메뉴권한 생성
 	 * @param menu - 메뉴 정보

+ 13 - 0
src/main/java/com/style24/admin/biz/web/TsaSystemController.java

@@ -310,6 +310,19 @@ public class TsaSystemController extends TsaBaseController {
 		return super.ok(message.getMessage("SUCC_0001"));
 	}
 
+	/**
+	 * 메뉴ID 조회
+	 * @param menuId - 메뉴ID
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 7. 16
+	 */
+	@GetMapping("/menu/id/{menuId}")
+	@ResponseBody
+	public int getMenuIdCount(@PathVariable("menuId") String menuId) {
+		return systemService.getMenuIdCount(menuId);
+	}
+
 	/**
 	 * 메뉴 등록/수정 처리
 	 * @return

+ 8 - 0
src/main/java/com/style24/persistence/mybatis/shop/TsaSystem.xml

@@ -330,6 +330,14 @@
 		ORDER  BY ORDBY
 	</select>
 
+	<!-- 메뉴ID 건수 -->
+	<select id="getMenuIdCount" parameterType="String" resultType="int">
+		/* TsaSystem.getMenuIdCount */
+		SELECT COUNT(*) AS CNT
+		FROM   TB_MENU
+		WHERE  MENU_ID = #{menuId}
+	</select>
+	
 	<!-- 메뉴 등록/수정 -->
 	<insert id="saveMenu" parameterType="Menu">
 		/* TsaSystem.saveMenu */

+ 41 - 1
src/main/webapp/WEB-INF/views/system/MenuForm.html

@@ -91,7 +91,8 @@
 								<tr>
 									<th>메뉴ID<i class="required" title="필수" aria-hidden="true"></i></th>
 									<td>
-										<input type="text" name="menuId" placeholder="" maxlength="20" required="required" data-valid-type="alphaNumeric" data-valid-name="메뉴ID" onkeyup="$(this).val($(this).val().toUpperCase());"/>
+										<input type="text" name="menuId" class="w150" placeholder="" maxlength="20" required="required" data-valid-type="alphaNumeric" data-valid-name="메뉴ID" onkeyup="$(this).val($(this).val().toUpperCase());"/>
+										<button type="button" class="btn btn-default btn-sm" id="menuIdDupCheck">중복체크</button>
 									</td>
 									<th>메뉴명<i class="required" title="필수" aria-hidden="true"></i></th>
 									<td>
@@ -378,12 +379,51 @@
 		$('#detailForm input[name=menuNm]').focus();
 	}
 	
+	// 메뉴ID 중복 체크
+	var isUnique = true;
+	$('#menuIdDupCheck').on('click', function() {
+		var $e = $('#registerForm input[name=menuId]');
+		if (gagajf.isNull($e.val())) {
+			mcxDialog.alertC('메뉴ID를 입력해 주세요.', {
+				sureBtnText: "확인",
+				sureBtnClick: function() {
+					$e.focus();
+				}
+			});
+			return;
+		}
+		
+		$.get('/system/menu/id/' + $e.val()
+			, function(data) {
+				if (data > 0) {
+					mcxDialog.alertC('이 ID는 이미 사용중입니다. 다른 ID를 입력해 주세요.', {
+						sureBtnText: "확인",
+						sureBtnClick: function() {
+							isUnique = false;
+							$e.val('');
+							$e.focus();
+						}
+					});
+				} else {
+					mcxDialog.alert('이 ID는 사용 가능합니다.');
+					isUnique = true;
+				}
+			});
+	});
+	
 	// 저장 처리
 	var fnSave = function(formId) {
 		// 입력 값 체크
 		if (!gagajf.validation(formId))
 			return false;
 		
+		if (formId == '#registerForm') {
+			if (!isUnique) {
+				mcxDialog.alert('메뉴ID를 중복체크해 주세요.');
+				return;
+			}
+		}
+		
 		$(formId + ' input[name=useYn]').val($(formId + ' input:checkbox[name=chkUseYn]').is(":checked") ? 'Y' : 'N');
 		$(formId + ' input[name=roleCds]').val($(formId + ' select[name=roleCd]').val());