Files
korea-research/admin/src/main/resources/templates/board/secArticles.html
2025-05-27 16:34:20 +09:00

333 lines
11 KiB
HTML

<!DOCTYPE html>
<html layout:decorate="~{layout/layout}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<section layout:fragment="content">
<form autocomplete="off" method="get" name="reqForm" th:action="@{/board/secArticles}"
th:object="${reqVO}">
<!-- hidden parameters -->
<input name="sort" th:field="*{sort}" type="hidden"/>
<input name="page" th:field="*{page}" type="hidden"/>
<div class="row p-2 mb-2 border-secondary border-top border-bottom border-1">
<div class="col-5">
<label class="col-sm-2 col-form-label" for="searchField">검색필드</label>
<select class="form-select d-inline w-25" id="searchField"
th:field="*{searchField}">
<option selected value="">선택</option>
<option value="title">제목</option>
<option value="updatedBy">작성자</option>
</select> <label>
<input class="form-control d-inline" placeholder="검색어를 입력하세요."
style="width: 250px;" th:field="*{searchValue}"
type="text">
</label>
</div>
<div class="col">
<label class="col-sm-3 col-form-label" for="searchOpen">공개여부</label>
<select class="form-select d-inline w-25" id="searchOpen"
th:field="*{searchOpen}">
<option selected value="">전체</option>
<option value="true">Y</option>
<option value="false">N</option>
</select>
</div>
<div class="col text-end">
<button class="btn btn-outline-secondary" onclick="goSearch();"
type="button">
<i class="bi bi-search"></i>
</button>
<button class="btn btn-outline-secondary" onclick="goInit();" type="button">
초기화
</button>
</div>
</div>
<div class="row">
<div class="col text-start">
<div class="fw-bolder text-muted">
TOTAL. <span id="totalElements"></span>
</div>
</div>
<div class="col text-end">
<i class="bi bi-list-ol"></i> <label>
<select
class="form-select form-select-sm" id="pageSize" name="size"
onchange="goSearch()"
th:field="*{size}">
<option
th:each="item : ${pageRows}"
th:text="${item.codeText}" th:value="${item.codeValue}"></option>
</select>
</label>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" style="width:40px;"><label>
<input class="form-check-input"
onchange="toggleCheckbox(this);" type="checkbox"/></label>
</th>
<th scope="col" style="width:60px;"></th>
<th scope="col">
<a class="order-able" data-sort-field="title"
href="#">제목</a>
</th>
<th scope="col">
<a class="order-able text-center d-inline-block w-100" data-sort-field="visible"
href="#">공개여부</a></th>
<th scope="col">
<a class="order-able" data-sort-field="startDate"
href="#">게시일</a></th>
<th scope="col">
<a class="order-able" data-sort-field="endDate"
href="#">종료일</a></th>
<th scope="col">
<a class="order-able" data-sort-field="updatedBy"
href="#">최근 수정자</a></th>
<th scope="col">
<a class="order-able" data-sort-field="updatedAt"
href="#">최근 수정일</a></th>
<th scope="col">
<a class="order-able" data-sort-field="orderNo"
href="#">정렬번호</a></th>
</tr>
</thead>
<tbody class="sortable" id="listTBody">
</tbody>
</table>
</form>
<div class="row paging"></div>
<div class="row">
<div class="col text-start">
<button class="btn btn-outline-secondary" onclick="goExcel();" type="button">
<i class="bi bi-file-earmark-spreadsheet"></i> 엑셀 다운로드
</button>
</div>
<div class="col text-end">
<button class="btn btn-outline-secondary" onclick="goSave();"
type="button">
<i class="bi bi-save2"></i> 등록
</button>
<button class="btn btn-outline-secondary" onclick="goRemove();" type="button">
<i class="bi bi-ui-checks-grid"></i> 삭제
</button>
<button class="btn btn-outline-secondary" onclick="uiUtil.sortable.update();" type="button">
<i class="bi bi-distribute-vertical"></i> 정렬 변경
</button>
</div>
</div>
</section>
<section layout:fragment="script">
<script>
const INIT_SORT = 'orderNo,DESC';
const getArticles = (pageNo) => {
const f = document.reqForm;
f.page.value = pageNo;
let dataOj = $(f).serializeObject();
$.ajax({
method: 'GET',
url: '/api/board/secArticles',
data: dataOj,
success(response) {
console.log(response);
$('#totalElements').text(response.totalElements);
// List 구성하기
const tbody = $('#listTBody');
tbody.empty();
$(response.content).each((idx, ct) => {
tbody.append(
`
<tr data-order-no="${ct.orderNo}"
data-id="${ct.id}">
<th
scope="row">${idx + (pageNo * f.size.value) + 1}</th>
<td><label>
<input class="form-check-input"
name="selectIds" type="checkbox" value="${ct.id}"/></label></td>
<td><img
src="${ct.uploadFile ? uiUtil.getFileReferURL('inline', ct.uploadFile)
: '/static/ui/img/default-img.jpg'}"
style="width: 25px;"
class="img-thumbnail"/></td>
<td><a href="javascript:goUpdate(${ct.id})">${ct.title}</a></td>
<td class="text-secondary text-center">${ct.visible ? 'Y' : 'N'}</td>
<td>${uiUtil.isoStrToReadable(ct.startDate)}</td>
<td>${uiUtil.isoStrToReadable(ct.endDate)}</td>
<td>${ct.updatedBy}</td>
<td>${uiUtil.isoStrToReadable(ct.updatedAt)}</td>
<td class="text-center">${ct.orderNo} <i
class="bi bi-distribute-vertical handle float-end fw-bold"
style="cursor: move"></i></td>
</tr>
`
);
});
if (!$(response.content).length) {
tbody.append(`
<tr>
<td colspan="10" class="text-center text-muted">게시물이 존재하지 않습니다.</td>
</tr>
`);
}
// Pagination 구성하기
const paging = $('.paging');
paging.empty();
paging.append(
uiUtil.getPagingUI(pageNo, f.size.value, response.totalPages,
(movePageNo) => {
f.page.value = movePageNo;
goSearch();
}));
// 리스트 상단 정렬 notation 및 갱신 기능 적용
uiUtil.addSortNotation(f.sort.value, (targetPage, targetSort) => {
f.page.value = targetPage;
f.sort.value = targetSort;
goSearch();
});
// sort 기능 적용
uiUtil.sortable.init(
// 드래그 가능 범위 지정 셀렉터
'.sortable',
// 드래그 핸들바 지정 셀렉터
'.handle',
// 현재 정렬이 orderNo,DESC 여부 검사 로직
() => {
return $('input[name=sort]').val() === INIT_SORT
},
// orderNo,DESC 로 정렬 변경 로직
() => {
f.sort.value = INIT_SORT;
getArticles(0);
},
// 정렬변경 수행 로직
(updateData) => {
$.ajax({
method: 'PATCH',
url: '/api/board/secArticles/sort',
data: JSON.stringify(updateData),
contentType: "application/json; charset=utf-8;",
dataType: "json",
beforeSend: function (xhr) {
xhr.setRequestHeader(
$("meta[name='_csrf_header']").attr("content"),
$("meta[name='_csrf']").attr("content"));
},
success: function () {
alert('[[#{operation.orderNo.updated}]]');
getArticles(f.page.value);
},
statusCode: {
// error
400: function (response) {
const resJson = response.responseJSON;
alert(resJson.message);
},
// validation fail
422: function (response) {
}
}
})
}
);
}
})
}
// 최초 리스트 로드
getArticles(document.reqForm.page.value);
</script>
<script th:inline="javascript">
const goSearch = () => {
const f = document.reqForm;
f.method = 'GET';
f.submit();
}
// 초기화
function goInit() {
const f = document.reqForm;
f.searchField.value = '';
f.searchValue.value = '';
f.searchOpen.value = '';
}
// 저장페이지 이동
function goSave() {
location.href = '/board/secArticles/create';
}
// 수정페이지 이동
function goUpdate(itemId) {
location.href = '/board/secArticles/' + itemId;
}
function goExcel() {
const f = document.reqForm;
const data = $(f).serializeObject();
// size 를 제거하면 전체 목록을 가져온다.
delete data.size;
location.href = '/api/board/secArticles/excel?' + new URLSearchParams(data).toString();
}
// 체크박스 선택/해제
function toggleCheckbox(oj) {
$('input[name=selectIds]').prop("checked", oj.checked);
}
function goRemove() {
if (!$('input[name=selectIds]').is(':checked')) {
alert(/*[[#{operation.common.remove.choose}]]*/);
return;
}
if (confirm(/*[[#{operation.common.remove.ask}]]*/)) {
const f = document.reqForm;
const data = $(f).serializeObject();
$.ajax({
'method': 'DELETE',
'url': '/api/board/secArticles/remove',
'data': {
'selectIds': data.selectIds
},
beforeSend: function (xhr) {
xhr.setRequestHeader(
$("meta[name='_csrf_header']").attr("content"),
$("meta[name='_csrf']").attr("content"));
},
success(res) {
alert('선택한 아이템이 삭제되었습니다.');
f.method = 'GET';
f.submit();
}
});
}
}
</script>
</section>
</html>