공지사항

This commit is contained in:
주우성
2025-06-18 20:52:21 +09:00
parent 9a1bea4f50
commit c5beca58cb
67 changed files with 2365 additions and 34 deletions

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace="app.module.admin.usecase.communication.notice.createNotice.adapters.persistence.CreateNoticeMapper">
<insert id="createNotice" keyProperty="id">
<!-- createNotice 게시글 등록 -->
<selectKey keyProperty="id" order="BEFORE" resultType="long">
SELECT nextval('notice_seq')
</selectKey>
INSERT INTO notice (
id,
content,
end_date,
start_date,
title,
visible,
created_at,
created_by,
updated_at,
updated_by,
is_deleted
) VALUES (
#{id},
#{content},
#{endDate},
#{startDate},
#{title},
#{visible},
#{createdAt},
#{createdBy},
#{updatedAt},
#{updatedBy},
false
)
</insert>
<insert id="createNoticeHasUploadFile">
<!-- createNoticeHasUploadFile 게시글 등록 시, 첨부파일 join 데이터 등록 -->
INSERT INTO notice_has_upload_file
(
notice_id,
upload_files_id,
<include refid="common.fields.CreateUpdateBaseColumns"/>
)
VALUES
<foreach collection="fileMappingIds" item="fileId" separator=",">
(
#{id},
#{fileId},
<include refid="common.fields.CreateUpdateBaseValues"/>
)
</foreach>
</insert>
</mapper>

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace="app.module.admin.usecase.communication.notice.getNotice.adapters.persistence.GetNoticeMapper">
<select id="getNotice"
resultType="app.module.admin.usecase.communication.notice.getNotice.ports.application.domain.GetNotice">
/* getNotice 상세 게시글 조회 */
<if test="id != null">
SELECT
a.id AS id,
a.title AS title,
a.content AS content,
a.visible AS visible,
a.start_date AS startDate,
a.end_date AS endDate,
a.created_at AS createdAt,
a.created_by AS createdBy,
a.updated_at AS updatedAt,
a.updated_by AS updatedBy
FROM notice a
WHERE a.id = #{id}
AND a.is_deleted = false
</if>
</select>
<select id="getUploadFiles"
resultType="app.module.admin.usecase.communication.notice.getNotice.ports.application.domain.GetNoticeUploadFile">
/* getUploadFiles 상세 게시글 조회 시, 첨부파일 조회 */
SELECT
awuf.notice_id AS noticeId,
awuf.upload_files_id AS uploadfileId,
uf.id AS id,
uf.created_at AS createdAt,
uf.created_by AS createdBy,
uf.updated_at AS updatedAt,
uf.updated_by AS updatedBy,
uf.file_length AS fileLength,
uf.name AS name,
uf.origin_name AS originName,
uf.path AS path,
uf.type AS type
FROM notice_has_upload_file awuf
INNER JOIN upload_file uf
ON awuf.upload_files_id = uf.id
WHERE awuf.notice_id = #{id} AND awuf.is_deleted = false
</select>
</mapper>

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace="app.module.admin.usecase.communication.notice.getNoticesUI.adapters.persistence.GetNoticesMapper">
<select id="getNotices"
resultType="app.module.admin.usecase.communication.notice.getNoticesUI.adapters.persistence.model.GetNoticesDto">
/* getNotices : 게시물 리스트 */
SELECT
a.id,
a.updated_by,
a.updated_at,
a.created_by,
a.created_at,
a.title,
a.content,
a.visible,
a.start_date,
a.end_date,
COUNT(*) OVER () AS total
FROM notice a
WHERE a.is_deleted = false
<if test="cmd.searchField != null and cmd.searchField != ''">
<choose>
<when test="cmd.searchField eq 'titleContent'">
AND ( a.title ILIKE '%' || #{cmd.searchValue} || '%' OR a.content ILIKE '%' || #{cmd.searchValue} || '%' )
</when>
<when test="cmd.searchField eq 'title'">
AND a.title ILIKE '%' || #{cmd.searchValue} || '%'
</when>
<when test="cmd.searchField eq 'content'">
AND a.content ILIKE '%' || #{cmd.searchValue} || '%'
</when>
<when test="cmd.searchField eq 'updatedBy'">
AND a.updated_by ILIKE '%' || #{cmd.searchValue} || '%'
</when>
</choose>
</if>
<if test="cmd.searchOpen != null and cmd.searchOpen != ''">
<choose>
<when test="cmd.searchOpen eq 'true'">
AND a.visible = true
</when>
<when test="cmd.searchOpen eq 'false'">
AND a.visible = false
</when>
</choose>
</if>
<if test="pageable.sort != null and !pageable.sort.isEmpty()">
ORDER BY
<foreach collection="pageable.sort" item="order" separator=",">
<choose>
<when test="order.property eq 'title'">a.title</when>
<when test="order.property eq 'visible'">a.visible</when>
<when test="order.property eq 'startDate'">a.start_date</when>
<when test="order.property eq 'endDate'">a.end_date</when>
<when test="order.property eq 'updatedBy'">a.updated_by</when>
<when test="order.property eq 'updatedAt'">a.updated_at</when>
<when test="order.property eq 'createdBy'">a.created_by</when>
<when test="order.property eq 'createdAt'">a.created_at</when>
<otherwise>a.id</otherwise>
</choose>
<choose>
<when test="order.direction.toString() eq 'DESC'">DESC</when>
<otherwise>ASC</otherwise>
</choose>
</foreach>
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
</if>
</select>
<select id="getUploadFiles"
resultType="app.module.admin.usecase.communication.notice.getNoticesUI.ports.application.domain.GetNoticeFiles">
/* getUploadFiles : 게시물 리스트의 대표 이미지 */
SELECT
awuf.notice_id,
uf.id,
uf.type,
uf.path,
uf.name,
uf.origin_name,
uf.file_length
FROM notice_has_upload_file awuf
INNER JOIN upload_file uf ON awuf.upload_files_id = uf.id
WHERE awuf.notice_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND uf.type = #{fileUploadType}
AND uf.is_deleted = false
</select>
</mapper>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace="app.module.admin.usecase.communication.notice.removeNotices.adapters.persistence.RemoveNoticesMapper">
<update id="deleteNotices">
/* deleteNotices : 게시물 삭제 */
UPDATE notice
SET <include refid="common.fields.DeleteBaseSet" />
WHERE id IN
<foreach collection="removeIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="deleteNoticeHasFiles">
/* deleteNoticeHasFiles : 게시물-파일 매핑 논리 삭제 */
UPDATE notice_has_upload_file
SET <include refid="common.fields.DeleteBaseSet" />
WHERE notice_id IN
<foreach collection="removeIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace="app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence.UpdateNoticeMapper">
<update id="deleteFileUploads">
/* deleteFileUploads 게시글 수정 시, 첨부파일 join 데이터 삭제 */
UPDATE notice_has_upload_file
SET
<include refid="common.fields.DeleteBaseSet"/>
WHERE notice_id = #{noticeId}
</update>
<insert id="createFileUploads">
/* createFileUploads 게시글 수정 시, 첨부파일 join 데이터 등록 */
INSERT INTO notice_has_upload_file
(
notice_id,
upload_files_id,
<include refid="common.fields.CreateUpdateBaseColumns"/>
)
VALUES
<foreach collection="fileMappingId" item="fileId" separator=",">
(
#{id},
#{fileId},
<include refid="common.fields.CreateUpdateBaseValues"/>
)
</foreach>
</insert>
<update id="updateNotice">
/* updateNotice 게시글 수정 */
UPDATE notice
SET
content = #{content},
end_date = #{endDate},
start_date = #{startDate},
title = #{title},
visible = #{visible},
<include refid="common.fields.UpdateBaseSet"/>
WHERE id = #{id}
</update>
</mapper>

View File

@@ -37,6 +37,9 @@ let uiUtil = {
isoStrToReadable(isoStr) {
return isoStr.replace(/T/, ' ').substring(0, 19);
},
isoStrToDateOnly(isoStr) {
return isoStr.split('T')[0];
},
// Pagination UI 생성 함수
getPagingUI(curPageNo, size, totalPages, moveHandler) {
curPageNo = parseInt(curPageNo);
@@ -280,6 +283,8 @@ uiUtil.showFileInfo = (input, uploadFile, showImg) => {
inputGroup.find('.fileInfo').remove();
inputGroup.append(`
<div class="fileInfo row text-muted fw-normal" style="display: none">
<img src="${showImg ? uploadFile.referURL : ''}" class="w-75 mt-3 mb-3"/>
@@ -292,6 +297,7 @@ uiUtil.showFileInfo = (input, uploadFile, showImg) => {
</div>
`);
const fileInfo = inputGroup.find('.fileInfo');
if (!showImg) {
fileInfo.find('img').remove();

View File

@@ -0,0 +1,182 @@
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{layout/layout}">
<section layout:fragment="content">
<form autocomplete="off"
th:action="@{/communication/notices/create}"
method="post" class="fw-bold" name="reqForm">
<div class="content-inner">
<!-- 테이블 영역 -->
<table class="type-form">
<tbody>
<tr>
<th>제목<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3">
<div class="component-input">
<div class="input-field">
<input type="text" name="title" id="title" placeholder="">
</div>
</div>
</td>
</tr>
<tr>
<th>내용<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3">
<textarea class="form-control" id="noticeContent" rows="10" name="content"></textarea>
</td>
</tr>
<tr>
<th>첨부파일<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3">
<div class="btns-row align-left publicFileInputs">
<button type="button" class="btn btn-secondary" onclick="addFileInput();">
<span class="btn-txt">다건 파일 첨부</span>
</button>
</div>
</td>
</tr>
<tr>
<th>게시기간<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="2">
<div class="d-flex">
<div class="component-input">
<div class="input-field">
<input id="boardStartDate" class="form-control flatpickr" name="startDate" type="text" placeholder="시작일을 선택하세요"/>
</div>
</div>-
<div class="component-input">
<div class="input-field">
<input id="boardEndDate" class="form-control flatpickr" name="endDate" type="text" placeholder="종료일을 선택하세요"/>
</div>
</div>
</div>
</td>
<td></td>
</tr>
<tr>
<th>노출여부<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td>
<div class="component-select">
<select class="select-list" name="visible" id="open">
<option value="true">Y</option>
<option value="false">N</option>
</select>
</div>
</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<div class="component-btns bottom-btn-group">
<div class="btns-row align-right">
<button type="button" class="btn btn-secondary" onclick="location.href='/household/households'">
<span class="btn-txt">취소</span>
</button>
<button type="button" class="btn btn-primary" onclick="goSave();">
<span class="btn-txt">등록</span>
</button>
</div>
</div>
</div>
</form>
</section>
<section layout:fragment="script">
<script src="/static/library/tinymce/6.0.3/tinymce.min.js" referrerpolicy="origin"></script>
<script src="/static/ui/editorImageUpload.js"></script>
<script th:inline="javascript">
initEditor('#noticeContent');
$(".flatpickr").flatpickr({
dateFormat: "Y-m-d\\TH:i",
// altInput: true,
// altFormat: "Y-m-d H:i",
monthSelectorType: 'static',
enableTime: true,
time_24hr: true
});
</script>
<script th:inline="javascript">
function addFileInput() {
$('.publicFileInputs').append(`
<div class="input-group w-50">
<input class="form-control mb-2" type="file" name="multipartAttachments"
onchange="uiUtil.uploadFile('NOTICE', this);">
<div class="invalid-feedback fw-bold">
에러 메세지
</div>
</div>
`);
}
const goSave = () => {
const f = document.reqForm;
// tinymce 는 사용자 입력을 받는 순간 몇몇 문자(&)를 escaping 한다.
// xss 방지를 위한 html escape 는 필터를 통해 자동처리되니 전달시에는 원문 그대로를 던진다.
f.content.value = uiUtil.unescapeHtml(tinymce.get('noticeContent').getContent());
const obj = $(f).serializeObject();
if(obj.fileMappingId) {
if (!Array.isArray(obj.fileMappingId)) {
obj.fileMappingId = [obj.fileMappingId];
}
}
const csrfToken = $('meta[name="_csrf"]').attr('content');
const csrfHeader = $('meta[name="_csrf_header"]').attr('content');
$.ajax({
'method': 'POST',
'url': '/api/communication/notices/create',
contentType: 'application/json',
data: JSON.stringify(obj),
beforeSend: function(xhr) {
xhr.setRequestHeader(csrfHeader, csrfToken);
},
// 'data': obj,
success: (res) => {
alert(`'${f.title.value}' 게시물이 생성되었습니다.\n이전 화면으로 이동합니다.`);
history.back();
},
statusCode: {
// error
400: function (res) {
const resJson = res.responseJSON;
alert(resJson.message);
},
// validation fail
422: function (res) {
alert("error");
// $(res.responseJSON).each((idx, oj) => {
// let target = $(f).find('[name=' + oj.field + ']');
// target.addClass('is-invalid');
//
// target.parent().find('.invalid-feedback').text(oj.defaultMessage);
// });
}
}
});
}
</script>
</section>
</html>

View File

@@ -0,0 +1,237 @@
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{layout/layout}">
<section layout:fragment="content">
<form autocomplete="off" method="get" name="reqForm" th:action="@{/communication/notices}"
th:object="${reqVO}">
<input name="page" th:field="*{page}" type="hidden"/>
<input name="size" th:field="*{size}" type="hidden"/>
<input name="userRole" th:value="${userRole}" type="hidden"/>
<input name="userRegionMainCode" th:value="${userRegionMainCode}" type="hidden"/>
<div class="content-inner">
<!-- 필터 영역 -->
<section class="filter-wrap">
<div class="form-area">
<!-- 검색필드 -->
<div class="input-group">
<div class="input-label">
<p class="label-txt">
검색필드
</p>
</div>
<div class="component-select">
<select class="select-list" th:field="*{searchField}" id="searchField">
<option value="all" selected>전체</option>
<option value="title">제목</option>
<option value="updatedBy">작성자</option>
</select>
</div>
</div>
<div class="input-group">
<div class="input-label">
<p class="label-txt">
검색필드
</p>
</div>
<div class="component-input">
<div class="input-field">
<input type="text" id="searchValue" th:field="*{searchValue}" placeholder="검색어를 입력하세요.">
</div>
</div>
</div>
<div class="input-group">
<div class="input-label">
<p class="label-txt">
검색필드
</p>
</div>
<div class="component-select">
<select class="select-list" th:field="*{searchOpen}" id="searchOpen">
<option value="" selected>전체</option>
<option value="true">Y</option>
<option value="false">N</option>
</select>
</div>
</div>
</div>
<!-- 버튼 그룹 -->
<div class="component-btns">
<div class="btns-row">
<button type="button" class="btn" onclick="location.href = location.pathname">
<span class="btn-txt">초기화</span>
</button>
<button type="submit" class="btn btn-primary">
<span class="btn-txt">검색</span>
</button>
</div>
</div>
</section>
<section>
<p class="input-label" style="font-size: 16px;">총 <span id="totalElements">0</span>건</p>
<!-- 테이블 영역 -->
<table>
<thead>
<tr>
<th style="width:50px">
<div class="component-input">
<label class="checkbox-inner">
<input type="checkbox" id="temp_checkbox_0003" name="temp_checkbox_0001">
</label>
</div>
</th>
<th>제목</th>
<th style="width:120px">게시일</th>
<th>게시기간</th>
<th style="width:80px">노출<br>여부</th>
<th style="width:250px">최종수정자</th>
</tr>
</thead>
<tbody id="listTBody">
</tbody>
</table>
</section>
<!-- 페이지네이션 -->
<div class="row paging"></div>
<div class="component-btns bottom-btn-group">
<div class="btns-row align-right">
<!-- 관리자만 노출 -->
<button type="button" class="btn btn-danger" th:if="${userRole == 'ROLE_ADMIN'}" onclick="goRemove()">
<span class="btn-txt">삭제 </span>
</button>
<button type="button" class="btn" th:if="${userRole == 'ROLE_ADMIN'}"
onclick="location.href='/communication/notices/create'">
<span class="btn-txt">등록 </span>
</button>
</div>
</div>
</div>
</form>
</section>
<section layout:fragment="script">
<script th:inline="javascript">
// 임가 목록 조회
const getHouseholds = (pageNo) => {
const f = document.reqForm;
f.page.value = pageNo;
let dataOj = $(f).serializeObject();
ajaxUtil._ajaxMethod(
'/api/communication/notices',
dataOj,
function(response) { // 성공
console.log("response", response);
$('#totalElements').text(response.totalElements);
const tbody = $('#listTBody');
tbody.empty();
$(response.content).each((idx, ct) => {
tbody.append(
`
<tr>
<td>
<div class="component-input">
<label class="checkbox-inner">
<input type="checkbox" name="selectIds" value="${ct.id}">
</label>
</div>
</td>
<td class="underline"><a href="/communication/notices/${ct.id}">${ct.title}</a></td>
<td>${uiUtil.isoStrToDateOnly(ct.createdAt)}</td>
<td>${uiUtil.isoStrToReadable(ct.startDate)} ~ ${uiUtil.isoStrToReadable(ct.endDate)}</td>
<td>${ct.visible ? 'Y' : 'N'}</td>
<td>${ct.updatedBy}(${uiUtil.isoStrToReadable(ct.updatedAt)})</td>
</tr>
`
);
});
// nodata 처리
if (!$(response.content).length) {
tbody.append(`
<tr>
<td colspan="6" 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();
}));
},
function (code, rstData) { // 실패
console.log("error : ", code);
},
'get',
'json'
);
}
// 최초 리스트 로드
getHouseholds(document.reqForm.page.value);
</script>
<script th:inline="javascript">
const goSearch = () => {
const f = document.reqForm;
f.method = 'GET';
f.submit();
}
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/communication/notices/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>

View File

@@ -0,0 +1,239 @@
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{layout/layout}">
<section layout:fragment="content">
<form autocomplete="off"
th:action="@{/communication/notices/create}"
method="post" class="fw-bold" name="reqForm">
<input type="hidden" name="id" th:value="${id}">
<div class="content-inner">
<!-- 테이블 영역 -->
<table class="type-form">
<tbody>
<tr>
<th>제목<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3">
<div class="component-input">
<div class="input-field">
<input type="text" name="title" id="title" placeholder="">
</div>
</div>
</td>
</tr>
<tr>
<th>내용<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3">
<textarea class="form-control" id="noticeContent" rows="10" name="content"></textarea>
</td>
</tr>
<tr>
<th>첨부파일<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3">
<div class="btns-row align-left publicFileInputs">
<button type="button" class="btn btn-secondary" onclick="addFileInput();">
<span class="btn-txt">다건 파일 첨부</span>
</button>
</div>
</td>
</tr>
<tr>
<th>게시기간<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="2">
<div class="d-flex">
<div class="component-input">
<div class="input-field">
<input id="boardStartDate" class="form-control flatpickr" name="startDate" type="text" placeholder="시작일을 선택하세요"/>
</div>
</div>-
<div class="component-input">
<div class="input-field">
<input id="boardEndDate" class="form-control flatpickr" name="endDate" type="text" placeholder="종료일을 선택하세요"/>
</div>
</div>
</div>
</td>
<td></td>
</tr>
<tr>
<th>노출여부<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td>
<div class="component-select">
<select class="select-list" name="visible" id="open">
<option value="true">Y</option>
<option value="false">N</option>
</select>
</div>
</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<div class="component-btns bottom-btn-group">
<div class="btns-row align-right">
<button type="button" class="btn btn-secondary" onclick="gotoList();">
<span class="btn-txt">취소</span>
</button>
<button type="button" class="btn btn-primary" onclick="goSave();">
<span class="btn-txt">등록</span>
</button>
</div>
</div>
</div>
</form>
</section>
<section layout:fragment="script">
<script src="/static/library/tinymce/6.0.3/tinymce.min.js" referrerpolicy="origin"></script>
<script src="/static/ui/editorImageUpload.js"></script>
<script th:inline="javascript">
$(".flatpickr").flatpickr({
dateFormat: "Y-m-d\\TH:i",
// altInput: true,
// altFormat: "Y-m-d H:i",
monthSelectorType: 'static',
enableTime: true,
time_24hr: true
});
</script>
<script th:inline="javascript">
const goPrev = () => {
history.back();
}
const gotoList = () => {
location.href = '/communication/notices';
}
function addFileInput() {
const inputGroup = $(`
<div class="input-group w-50">
<input class="form-control mb-2" type="file" name="multipartAttachments"
onchange="uiUtil.uploadFile('NOTICE', this);">
<div class="invalid-feedback fw-bold">
에러 메세지
</div>
</div>
`);
$('.publicFileInputs').append(inputGroup);
return inputGroup;
}
const getNotice = () => {
const f = document.reqForm;
$.ajax({
method: 'GET',
url: '/api/communication/notices/' + f.id.value,
success(res) {
console.log(res);
initEditor('#noticeContent', (editor) => {
editor.on('init', function () {
setTimeout(() => {
tinymce.get('noticeContent').setContent(uiUtil.unescapeHtml(res.content));
}, 0);
});
});
f.title.value = uiUtil.unescapeHtml(res.title);
f.startDate.value = res.startDate.substring(0, 16);
f.endDate.value = res.endDate.substring(0, 16);
f.visible.value = res.visible;
res.uploadFiles.forEach((uploadFile) => {
let inputGroup = addFileInput();
inputGroup.append(`<input type="hidden" name="fileMappingId" value="${uploadFile.id}"/>`);
uiUtil.showFileInfo(inputGroup.find('input[type=file]'), uploadFile, false);
});
}
});
}
// 상세정보 얻기
getNotice();
const goSave = () => {
const f = document.reqForm;
// tinymce 는 사용자 입력을 받는 순간 몇몇 문자(&)를 escaping 한다.
// xss 방지를 위한 html escape 는 필터를 통해 자동처리되니 전달시에는 원문 그대로를 던진다.
f.content.value = uiUtil.unescapeHtml(tinymce.get('noticeContent').getContent());
const obj = $(f).serializeObject();
if(obj.fileMappingId) {
if (!Array.isArray(obj.fileMappingId)) {
obj.fileMappingId = [obj.fileMappingId];
}
}
const csrfToken = $('meta[name="_csrf"]').attr('content');
const csrfHeader = $('meta[name="_csrf_header"]').attr('content');
$.ajax({
'method': 'PUT',
'url': '/api/communication/notices/update',
contentType: 'application/json',
data: JSON.stringify(obj),
beforeSend: function(xhr) {
xhr.setRequestHeader(csrfHeader, csrfToken);
},
success: (res) => {
if (confirm(`'${uiUtil.unescapeHtml(res.title)}' 게시물이 수정되었습니다.\n이전 화면으로 이동하시겠습니까?`)) {
history.back();
}
},
statusCode: {
// error
400: function (res) {
const resJson = res.responseJSON;
alert(resJson.message);
},
// validation fail
422: function (res) {
alert('error');
// $(res.responseJSON).each((idx, oj) => {
// let target = $(f).find('[name=' + oj.field + ']');
// target.addClass('is-invalid');
//
// target.parent().find('.invalid-feedback').text(oj.defaultMessage);
// });
}
}
});
}
</script>
</section>
</html>

View File

@@ -1,9 +0,0 @@
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{layout/layout}">
<section layout:fragment="content">
<h1>/communication/notices</h1>
</section>
</html>