|
|
@@ -19,23 +19,27 @@
|
|
|
<div class="button-box">
|
|
|
<div class="bl-button" onclick="movePath('/phits/notice-list')">목록</div>
|
|
|
<div style="display: flex;">
|
|
|
- <div class="bl-button" onclick="edit()">편집</div>
|
|
|
- <div class="wt-button" onclick="delEvent()">삭제</div>
|
|
|
+ <div class="bl-button edit-btn" onclick="edit()">편집</div>
|
|
|
+ <div class="bl-button off save-btn" onclick="save()">저장</div>
|
|
|
+ <div class="wt-button del-btn" onclick="delEvent()">삭제</div>
|
|
|
+ <div class="wt-button off x-btn" onclick="cancel()">취소</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="view-box">
|
|
|
<div>
|
|
|
- <input class="title" th:value="${notice.getBSubject()}" readonly>
|
|
|
- <textarea class="b_content" rows="16" th:text="${notice.getBContent()}" readonly></textarea>
|
|
|
- <div class="attach-box">
|
|
|
+ <input class="title" name="b_subject" th:value="${notice.getBSubject()}" readonly>
|
|
|
+ <textarea class="b_content" rows="16" name="b_content" th:text="${notice.getBContent()}" readonly></textarea>
|
|
|
+ <div class="attach-box admin">
|
|
|
<div class="attach">
|
|
|
<div th:if="${notice.getAttachFile() == '||' or #strings.isEmpty(notice.getAttachFile())}">첨부파일 없음</div>
|
|
|
<div class="attach-file" th:if="${notice.getAttachFile() != '||' and not #strings.isEmpty(notice.getAttachFile())}"
|
|
|
th:each="item, i : ${#strings.arraySplit(notice.getAttachFile(), '|')}"
|
|
|
th:text="${item}" th:title="${item + ' 다운로드'}"
|
|
|
- th:onclick="attachFileDownload([[${i.index}]], [[${notice}]], [[${item}]])"
|
|
|
+ th:onclick="attachFileDownload([[${i.index}]], [[${notice.getBoardNo()}]], [[${notice.getAttachFileId()}]],[[${item}]])"
|
|
|
></div>
|
|
|
</div>
|
|
|
+ <input type="file" name="attachFile" id="attach-file">
|
|
|
+ <div class="bl-button off attach-btn" onclick="attachFile()">파일첨부</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -46,19 +50,29 @@
|
|
|
</body>
|
|
|
</html>
|
|
|
<script th:inline="javascript">
|
|
|
+ const $delete = $('.del-btn');
|
|
|
+ const $save = $('.save-btn');
|
|
|
+ const $edit = $('.edit-btn');
|
|
|
+ const $cancel = $('.x-btn');
|
|
|
+ const $title = $('.title');
|
|
|
+ const $content = $('.b_content');
|
|
|
+ const $attach = $('.attach');
|
|
|
+ const $attachBtn = $('.attach-btn');
|
|
|
+ const $attachFile = $('#attach-file');
|
|
|
+ const notice = [[${notice}]];
|
|
|
+
|
|
|
let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
|
|
|
|
|
if (isMobile) {
|
|
|
- $('.b_content').attr('rows', 10);
|
|
|
+ $content.attr('rows', 10);
|
|
|
}
|
|
|
|
|
|
- function attachFileDownload(index, notice, fileName) {
|
|
|
- let attachFileId = notice.attach_file_id;
|
|
|
+ function attachFileDownload(index, id, attachFileId, fileName) {
|
|
|
if (attachFileId && attachFileId.split('|').length > 0) {
|
|
|
attachFileId = attachFileId.split('|')[index];
|
|
|
}
|
|
|
const param = {
|
|
|
- boardNo : notice.board_no,
|
|
|
+ boardNo : id,
|
|
|
fileId : attachFileId,
|
|
|
}
|
|
|
getDataAsync('/api/notice/attach', 'POST', param, null, (jsonData)=>{
|
|
|
@@ -68,9 +82,11 @@
|
|
|
if (!ext) {
|
|
|
return alert("파일 확장자명이 잘못 되었습니다.");
|
|
|
}
|
|
|
- const file = new Blob([attachFile], {type: "application/" + ext});
|
|
|
+ const file = b64ToBlob(attachFile);
|
|
|
+ // const file = new Blob([attachFile], {type: "image/" + ext});
|
|
|
const link = document.createElement('a');
|
|
|
- link.href = window.URL.createObjectURL(file);
|
|
|
+ // link.href = window.URL.createObjectURL(file);
|
|
|
+ link.href = file;
|
|
|
link.download = fileName;
|
|
|
link.click();
|
|
|
}
|
|
|
@@ -81,11 +97,145 @@
|
|
|
}, null);
|
|
|
}
|
|
|
|
|
|
+ const b64ToBlob = (byteData) => {
|
|
|
+ const byteCharacters = atob(byteData);
|
|
|
+ const byteNumbers = new Array(byteCharacters.length);
|
|
|
+ for (let i = 0; i < byteCharacters.length; i++) {
|
|
|
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
|
+ }
|
|
|
+ const byteArray = new Uint8Array(byteNumbers);
|
|
|
+ const blob = new Blob([byteArray]);
|
|
|
+ const blobUrl = window.URL.createObjectURL(blob);
|
|
|
+
|
|
|
+ return blobUrl;
|
|
|
+ };
|
|
|
+
|
|
|
+ function attachFile() {
|
|
|
+ $attachFile.click();
|
|
|
+ }
|
|
|
+
|
|
|
+ $attachFile.on("change", function() {
|
|
|
+ const changeFile = $(this)[0].files[0];
|
|
|
+ if (changeFile) {
|
|
|
+ const fileName = changeFile.name;
|
|
|
+ $attach.html('<div><span class="attach-delete" title="첨부파일 제거" onclick="deleteAttach()"></span>' + fileName + '</div>');
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
function edit() {
|
|
|
+ $delete.addClass('off');
|
|
|
+ $edit.addClass('off');
|
|
|
+ $save.removeClass('off');
|
|
|
+ $cancel.removeClass('off');
|
|
|
+ $title.addClass('modify');
|
|
|
+ $content.addClass('modify');
|
|
|
+ $attach.addClass('modify');
|
|
|
+ $attachBtn.removeClass('off');
|
|
|
+
|
|
|
+ $title.attr('readonly', false);
|
|
|
+ $content.attr('readonly', false);
|
|
|
|
|
|
+ const fileName = $attach.children().eq(0).text();
|
|
|
+ if (fileName !== '첨부파일 없음') {
|
|
|
+ $attach.html('<div><span class="attach-delete" title="첨부파일 제거" onclick="deleteAttach()"></span>' + fileName + '</div>')
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function deleteAttach() {
|
|
|
+ $attachFile.val("");
|
|
|
+ $attach.html("<div>첨부파일 없음</div>")
|
|
|
+ console.log($attachFile[0].files[0]);
|
|
|
}
|
|
|
|
|
|
function delEvent() {
|
|
|
+ const boardNo = [[${notice.getBoardNo()}]];
|
|
|
+ const bSubject = [[${notice.getBSubject()}]];
|
|
|
+ if (confirm( "번호 : " + boardNo + "\n제목 : " + bSubject + '\n게시물을 삭제하시겠습니까?')) {
|
|
|
+ getDataAsync('/api/notice/deleteNotice', 'DELETE', {boardNo : boardNo}, null, (jsonData)=>{
|
|
|
+ if (jsonData) {
|
|
|
+ alert(jsonData.message);
|
|
|
+ if (jsonData.success === "S") {
|
|
|
+ window.location.href = '/phits/notice-list';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, (error)=>{
|
|
|
+ console.log(error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ function save() {
|
|
|
+ const file = $attachFile[0].files[0];
|
|
|
+ const title = $title.val();
|
|
|
+ const content = $content.val();
|
|
|
+ const attachNm = notice.attach_file.split("|")[0];
|
|
|
+
|
|
|
+ if (notice.b_subject === title && notice.b_content === content) {
|
|
|
+ if (file) {
|
|
|
+ if (file.name === attachNm) {
|
|
|
+ return alert("수정하신 내용이 없습니다. 내용을 확인 해 주세요");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ const attachFileName = $attach.children().eq(0).text();
|
|
|
+ if ( (attachFileName === "첨부파일 없음" && attachNm === "") || attachFileName === attachNm) {
|
|
|
+ return alert("수정하신 내용이 없습니다. 내용을 확인 해 주세요");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("boardNo", notice.board_no);
|
|
|
+ formData.append("bSubject", title);
|
|
|
+ formData.append("bContent", content);
|
|
|
+ formData.append("attachFile", file);
|
|
|
+ $.ajax({
|
|
|
+ url: '/api/notice/modifyNotice',
|
|
|
+ processData : false,
|
|
|
+ contentType: false,
|
|
|
+ data: formData,
|
|
|
+ type: 'POST',
|
|
|
+ success: function(jsonData) {
|
|
|
+ if (jsonData) {
|
|
|
+ alert(jsonData.message);
|
|
|
+ if (jsonData.success === "S") {
|
|
|
+ window.location.href = "/phits/notice-view/" + notice.board_no;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(error) {
|
|
|
+ alert(error.responseJSON.message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function cancel() {
|
|
|
+ $delete.removeClass('off');
|
|
|
+ $edit.removeClass('off');
|
|
|
+ $save.addClass('off');
|
|
|
+ $cancel.addClass('off');
|
|
|
+ $title.removeClass('modify');
|
|
|
+ $content.removeClass('modify');
|
|
|
+ $attach.removeClass('modify');
|
|
|
+ $attachBtn.addClass('off');
|
|
|
+ $title.attr('readonly', true);
|
|
|
+ $content.attr('readonly', true);
|
|
|
+
|
|
|
+ const attachFileNames = notice.attach_file;
|
|
|
+
|
|
|
+ if (attachFileNames) {
|
|
|
+ const attachFileName = attachFileNames.split("|")[0];
|
|
|
+ let attachText = "첨부파일 없음";
|
|
|
+ if (attachFileName) {
|
|
|
+ attachText = `<div class="attach-file" title="${attachFileName} 다운로드"
|
|
|
+ onclick="attachFileDownload(0, ${notice.board_no}, '${notice.attach_file_id}','${attachFileName}')">
|
|
|
+ ${attachFileName}
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+ $attach.html(attachText);
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|