관리자 등록 ,목록 수정

This commit is contained in:
주수현
2025-06-19 20:27:47 +09:00
parent 2402be3b44
commit 68b396921f
31 changed files with 400 additions and 112 deletions

View File

@@ -7,27 +7,28 @@
<form
method="post"
th:action="@{/settings/admins/create}"
th:object="${bindingVO}">
th:object="${bindingVO}"
name="adminCreateForm">
<table class="type-form">
<tbody>
<tr>
<th><label for="roleIds">권한<i class="ico-required-mark" role="img" aria-label="필수">*</i></label></th>
<th><label for="roleId">권한<i class="ico-required-mark" role="img" aria-label="필수">*</i></label></th>
<td>
<div class="d-flex">
<div class="component-input">
<div class="component-select">
<select class="select-list" id="roleIds"
th:classappend="${#fields.hasErrors('roleIds')} ? 'is-invalid'"
th:field="*{roleIds}"
<select class="select-list" id="roleId"
th:classappend="${#fields.hasErrors('roleId')} ? 'is-invalid'"
th:field="*{roleId}"
onchange="onRoleChange(this);">
<option value="">선택</option>
<option th:each="role : ${roles}" th:text="${role.description}"
th:value="${role.id}"></option>
</select>
</div>
<div class="invalid-feedback fw-bold" th:errors="*{roleIds}"
th:if="${#fields.hasErrors('roleIds')}">
<div class="invalid-feedback fw-bold" th:errors="*{roleId}"
th:if="${#fields.hasErrors('roleId')}">
에러 메세지
</div>
</div>
@@ -40,13 +41,18 @@
<div class="component-input">
<div class="input-field">
<input id="id"
name="id"
th:classappend="${#fields.hasErrors('id')} ? 'is-invalid'"
th:field="*{id}"/>
<button type="button" class="btn btn-primary" onclick="adminIdCheckDuplicate();">
<span class="btn-txt">중복확인</span>
</button>
<div class="invalid-feedback fw-bold" th:errors="*{id}"
th:if="${#fields.hasErrors('id')}">
에러 메세지
</div>
</div>
<span>4~15자 / 영문,숫자,한글 가능/ 특수문자 _,- 사용가능</span>
</div>
</td>
<th><label for="password">Password<i class="ico-required-mark" role="img" aria-label="필수">*</i></label></th>
@@ -61,11 +67,51 @@
에러 메세지
</div>
</div>
<span>총 5자 / 숫자 + 특수문자 1개 이상 (!,@,#,$,%,_,-)</span>
</div>
</td>
</tr>
<tr class="researcherArea"
th:classappend="${bindingVO.roleId == 'ROLE_LOCAL_INSPECTOR'} ? 'd-none'">
<th><label for="name">이름<i class="ico-required-mark" role="img" aria-label="필수">*</i></label></th>
<td>
<div class="component-input">
<div class="input-field">
<input id="name" type="text" name="name"
th:classappend="${#fields.hasErrors('name')} ? 'is-invalid'"
th:field="*{name}"/>
<div class="invalid-feedback fw-bold"
th:if="${#fields.hasErrors('name')}">
에러 메세지
</div>
</div>
</div>
</td>
<th><label for="name">전화번호<i class="ico-required-mark" role="img" aria-label="필수">*</i></label></th>
<td>
010-
<div class="component-input">
<div class="input-field">
<input id="phone1" name="phone1" type="number" maxlength="4" th:field="*{phone1}"
th:classappend="${#fields.hasErrors('name')} ? 'is-invalid'"
/>
</div>
</div>
<div class="component-input">
<div class="input-field">
<input id="phone2" name="phone2" type="number" maxlength="4" th:field="*{phone2}"
th:classappend="${#fields.hasErrors('name')} ? 'is-invalid'"
/>
</div>
</div>
<div class="invalid-feedback fw-bold"
th:if="${#fields.hasErrors('phone1')}">
에러 메세지
</div>
</td>
</tr>
<tr class="regionMainCodeArea"
th:classappend="${#lists.isEmpty(bindingVO.roleIds) or #lists.contains(bindingVO.roleIds, 'ROLE_ADMIN')} ? 'd-none'">
th:classappend="${bindingVO.roleId != 'ROLE_ADMIN'} ? 'd-none'">
<th><label for="regionMainCode">실사<i class="ico-required-mark" role="img" aria-label="필수">*</i></label></th>
<td>
<div class="component-select">
@@ -118,7 +164,7 @@
<button type="button" class="btn btn-secondary" onclick="gotoList();return false;">
<span class="btn-txt">목록으로 이동</span>
</button>
<button type="submit" class="btn btn-primary">
<button type="button" class="btn btn-primary" onclick="createAdmin();">
<span class="btn-txt">저장</span>
</button>
</div>
@@ -137,14 +183,69 @@
}
$(document).ready(() => {
const roleSelect = document.getElementById('roleIds');
const roleSelect = document.getElementById('roleId');
onRoleChange(roleSelect);
});
const onRoleChange = (el) => {
const selectedValues = Array.from(el.selectedOptions).map(option => option.value);
const isAdmin = !selectedValues.length || selectedValues.includes('ROLE_ADMIN');
const idResearcher = !selectedValues.length || selectedValues.includes('ROLE_RESEARCHER');
$('.regionMainCodeArea').toggle(!isAdmin);
$('.researcherArea').toggle(idResearcher);
};
let checkDuplicate = false;
const adminIdCheckDuplicate = () => {
const f = document.adminCreateForm;
if (!f.id.value) {
alert("아이디를 입력해주세요.");
return;
}
ajaxUtil._ajaxMethod(
'/api/settings/admin/idCheck',
{ id : f.id.value },
function(response) { // 성공
const message = response > 0
? "이미 사용하고 있는 아이디 입니다. 아이디를 입력해주세요."
: "사용 가능한 아이디입니다.";
alert(message);
checkDuplicate = response <= 0;
},
function (code, rstData) {
console.log("error : ", code);
if(code == 400) alert("아이디를 입력해주세요.");
},
'get',
'json'
);
}
const createAdmin = () => {
if (!checkDuplicate) {
alert("아이디 중복 확인을 해주세요.");
return false;
}
const f = document.adminCreateForm;
let dataOj = $(f).serializeObject();
ajaxUtil._ajaxMethod(
'/api/settings/admin/create',
JSON.stringify(dataOj),
function(response) { // 성공
alert("등록이 완료되었습니다.");
location.href = '/settings/admins';
},
function (code, rstData) {
if(code == 422) alert(rstData.responseText);
if(code == 400) alert(rstData.responseJSON.message);
},
'post',
'json',
{ handle422Type: 'alert' }
);
}
</script>
</th:block>

View File

@@ -17,14 +17,26 @@
<div class="form-area">
<div class="input-group">
<div class="input-label">
<p class="label-txt"><label for="searchField">검색필드</label></p>
<p class="label-txt">권한</p>
</div>
<div class="component-select">
<select class="select-list" id="searchRole" th:field="*{searchRole}">
<option selected value="">전체</option>
<option th:each="role : ${roles}" th:text="${role.description}"
th:value="${role.id}"></option>
</select>
</div>
</div>
<div class="input-group">
<div class="input-label">
<p class="label-txt"><label for="searchField">정보</label></p>
</div>
<div class="d-flex">
<div class="component-select">
<select class="select-list" id="searchField" th:field="*{searchField}">
<option selected value="">선택</option>
<option selected value="">전체</option>
<option value="id">ID</option>
<option value="email">Email</option>
<option value="name">이름</option>
</select>
</div>
<div class="component-input">
@@ -38,13 +50,25 @@
</div>
<div class="input-group">
<div class="input-label">
<p class="label-txt">권한</p>
<p class="label-txt">실사</p>
</div>
<div class="component-select">
<select class="select-list" id="searchRole" th:field="*{searchRole}">
<select class="select-list" id="searchArea" th:field="*{searchRole}">
<option selected value="">전체</option>
<option th:each="role : ${roles}" th:text="${role.id}"
th:value="${role.id}"></option>
<option th:each="region : ${regionMainCode}" th:text="${region.codeText}"
th:value="${region.id}"></option>
</select>
</div>
</div>
<div class="input-group">
<div class="input-label">
<p class="label-txt">계정사용여부</p>
</div>
<div class="component-select">
<select class="select-list" id="searchDisabled" th:field="*{searchRole}">
<option selected value="">전체</option>
<option value="false">사용</option>
<option value="true">미사용</option>
</select>
</div>
</div>

View File

@@ -32,7 +32,11 @@
<tr>
<th>내용</th>
<td>
<textarea id="content" name="content" rows="5" cols="50"></textarea>
<div class="component-input">
<div class="input-textarea-field">
<textarea id="content" name="content" class="textarea" placeholder=""></textarea>
</div>
</div>
</td>
</tr>
<tr>