|
|
@@ -0,0 +1,273 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en" xmlns:th=http://www.thymeleaf.org>
|
|
|
+<head>
|
|
|
+ <meta charset="utf-8"/>
|
|
|
+ <meta name="viewport" content="width=device-width,initial-scale=1"/>
|
|
|
+ <meta name="theme-color" content="#000000"/>
|
|
|
+ <meta name="description" content="포항시 교통정보센터입니다"/>
|
|
|
+ <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
|
|
+ <title>포항시 교통정보센터</title>
|
|
|
+ <th:block th:include="/include/head.html"></th:block>
|
|
|
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
|
|
|
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
|
|
|
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
|
|
|
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
|
|
|
+ <link rel="stylesheet" th:href="@{/css/notice.css}">
|
|
|
+</head>
|
|
|
+<body id="body">
|
|
|
+<th:block th:include="/include/admin-header.html"></th:block>
|
|
|
+<div class="noticeWrap">
|
|
|
+ <div class="container view">
|
|
|
+ <h2 class="admin-header">팝업공지</h2>
|
|
|
+ <div class="content admin-view">
|
|
|
+ <div class="button-box">
|
|
|
+ <div class="bl-button" onclick="movePath('/phits/popup-list')">목록</div>
|
|
|
+ <div style="display: flex;">
|
|
|
+ <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" name="b_subject" th:value="${popup.getTitle()}" readonly>
|
|
|
+ <textarea class="b_content" rows="15" th:text="${popup.getUrl()}" readonly></textarea>
|
|
|
+ <div class="post-box">
|
|
|
+ <div>공지 기간</div>
|
|
|
+ <input type="text" id="post" class="post_from" name="post_from" disabled="disabled">
|
|
|
+<!-- <div>~</div>-->
|
|
|
+<!-- <input type="date" class="post_to" name="post_to" th:value="${popup.getPostTo()}">-->
|
|
|
+ </div>
|
|
|
+ <div class="attach-box admin">
|
|
|
+ <div class="attach">
|
|
|
+ <div th:if="${popup.getImgId() == null or #strings.isEmpty(popup.getImgId())}">첨부파일 없음</div>
|
|
|
+ <div class="attach-file" th:if="${popup.getImgName() != null and not #strings.isEmpty(popup.getImgName())}"
|
|
|
+ th:text="${popup.getImgName()}" th:title="${popup.getImgName() + ' 다운로드'}"
|
|
|
+ th:onclick="attachFileDownload([[${popup.getImgId()}]], [[${popup.getImgName()}]])"
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
+ <input type="file" name="attachFile" id="attach-file" accept="image/*">
|
|
|
+ <div class="bl-button off attach-btn" onclick="attachFile()">파일첨부</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</div>
|
|
|
+<th:block th:include="/include/footer.html"></th:block>
|
|
|
+</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 popup = [[${popup}]];
|
|
|
+ const popupId = popup.popupid;
|
|
|
+ const popupTitle = popup.title;
|
|
|
+ const $post = $('#post');
|
|
|
+ const post = $post.daterangepicker({
|
|
|
+ timePicker: false,
|
|
|
+ startDate: new Date(popup.post_from),
|
|
|
+ endDate: new Date(popup.post_to),
|
|
|
+ locale: {
|
|
|
+ format: 'YYYY-MM-DD',
|
|
|
+ separator: " ~ ",
|
|
|
+ applyLabel: "확인",
|
|
|
+ cancelLabel : "취소",
|
|
|
+ daysOfWeek: ["일", "월", "화", "수", "목", "금", "토"],
|
|
|
+ monthNames: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
|
|
|
+ },
|
|
|
+ disabled : true,
|
|
|
+ autoApply: true,
|
|
|
+ opens: 'center',
|
|
|
+ drops: 'up',
|
|
|
+ });
|
|
|
+
|
|
|
+ let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
|
|
+
|
|
|
+ if (isMobile) {
|
|
|
+ $content.attr('rows', 10);
|
|
|
+ }
|
|
|
+
|
|
|
+ function attachFileDownload(attachFileId, fileName) {
|
|
|
+ const param = {
|
|
|
+ imgId : attachFileId,
|
|
|
+ imgName : fileName,
|
|
|
+ }
|
|
|
+ getDataAsync('/api/popup/attach', 'POST', param, null, (jsonData)=>{
|
|
|
+ const attachFile = jsonData.attach_file;
|
|
|
+
|
|
|
+ if (attachFile && attachFile.length > 0) {
|
|
|
+ const file = b64ToBlob(attachFile);
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = file;
|
|
|
+ link.download = fileName;
|
|
|
+ link.click();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ alert(jsonData.message);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, 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');
|
|
|
+ $post.prop("disabled", false);
|
|
|
+ $title.attr('readonly', false);
|
|
|
+ $content.attr('readonly', false);
|
|
|
+ $title.prop('placeholder', '팝업 제목을 입력해주세요.');
|
|
|
+ $content.prop('placeholder', '링크 주소가 있다면 URL을 입력해주세요. ex) https://www.naver.com');
|
|
|
+ $post.addClass("modify");
|
|
|
+
|
|
|
+ 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>")
|
|
|
+ }
|
|
|
+
|
|
|
+ function delEvent() {
|
|
|
+ if (confirm( "번호 : " + popupId + "\n제목 : " + popupTitle + '\n게시물을 삭제하시겠습니까?')) {
|
|
|
+ getDataAsync('/api/popup/deletePopup', 'DELETE', {popupId : popupId}, null, (jsonData)=>{
|
|
|
+ if (jsonData) {
|
|
|
+ alert(jsonData.message);
|
|
|
+ if (jsonData.success === "S") {
|
|
|
+ window.location.href = '/phits/popup-list';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, (error)=>{
|
|
|
+ console.log(error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function save() {
|
|
|
+ const file = $attachFile[0].files[0];
|
|
|
+ const title = $title.val();
|
|
|
+ const url = $content.val();
|
|
|
+ const attachNm = popup.img_name;
|
|
|
+ const postVal = $post.val();
|
|
|
+ let postFrom = "";
|
|
|
+ let postTo = "";
|
|
|
+ if (isNull(postVal)) {
|
|
|
+ const postArray = postVal.split("~");
|
|
|
+ if (postArray.length === 2) {
|
|
|
+ postFrom = postArray[0].trim();
|
|
|
+ postTo = postArray[1].trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (popup.title === title && popup.url === url) {
|
|
|
+ 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("popupId", popupId);
|
|
|
+ formData.append("title", title);
|
|
|
+ formData.append("url", url);
|
|
|
+ formData.append("attachFile", file);
|
|
|
+ $.ajax({
|
|
|
+ url: '/api/popup/modifyPopup',
|
|
|
+ processData : false,
|
|
|
+ contentType: false,
|
|
|
+ data: formData,
|
|
|
+ type: 'POST',
|
|
|
+ success: function(jsonData) {
|
|
|
+ if (jsonData) {
|
|
|
+ alert(jsonData.message);
|
|
|
+ if (jsonData.success === "S") {
|
|
|
+ window.location.href = "/phits/popup-view/" + popupId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 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);
|
|
|
+ $title.prop('placeholder', '');
|
|
|
+ $content.prop('placeholder', '');
|
|
|
+ $post.prop("disabled", true);
|
|
|
+ $post.removeClass("modify");
|
|
|
+
|
|
|
+ const attachFileName = popup.img_name;
|
|
|
+
|
|
|
+ let attachText = "첨부파일 없음";
|
|
|
+ if (attachFileName) {
|
|
|
+ attachText = `<div class="attach-file" title="${attachFileName} 다운로드"
|
|
|
+ onclick="attachFileDownload('${popup.img_id}','${attachFileName}')">
|
|
|
+ ${attachFileName}
|
|
|
+ </div>`;
|
|
|
+ $attach.html(attachText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|