popup-write.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th=http://www.thymeleaf.org>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="width=device-width,initial-scale=1"/>
  6. <meta name="theme-color" content="#000000"/>
  7. <meta name="description" content="포항시 교통정보센터입니다"/>
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  9. <title>포항시 교통정보센터</title>
  10. <th:block th:include="/include/head.html"></th:block>
  11. <link rel="stylesheet" th:href="@{/css/notice.css}">
  12. </head>
  13. <body id="body">
  14. <th:block th:include="/include/admin-header.html"></th:block>
  15. <div class="noticeWrap">
  16. <div class="container view">
  17. <h2 class="admin-header">팝업 공지</h2>
  18. <div class="content admin-view">
  19. <div class="button-box">
  20. <div class="bl-button" onclick="movePath('/phits/popup-list')">목록</div>
  21. <div style="display: flex;">
  22. <div class="bl-button save-btn" onclick="save()">저장</div>
  23. </div>
  24. </div>
  25. <div class="view-box">
  26. <div>
  27. <input class="title modify" name="b_subject" placeholder="팝업 제목을 입력해주세요.">
  28. <textarea class="b_content modify" rows="16" name="b_content" placeholder="링크 주소가 있다면 URL을 입력해주세요. ex) https://www.naver.com"></textarea>
  29. <div class="attach-box admin">
  30. <div class="attach modify">
  31. <div>첨부파일 없음</div>
  32. </div>
  33. <input type="file" name="attachFile" id="attach-file">
  34. <div class="bl-button attach-btn" onclick="attachFile()">파일첨부</div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <th:block th:include="/include/footer.html"></th:block>
  42. </body>
  43. </html>
  44. <script th:inline="javascript">
  45. const $title = $('.title');
  46. const $content = $('.b_content');
  47. const $attach = $('.attach');
  48. const $attachFile = $('#attach-file');
  49. let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
  50. if (isMobile) {
  51. $content.attr('rows', 10);
  52. }
  53. function attachFile() {
  54. $attachFile.click();
  55. }
  56. $attachFile.on("change", function() {
  57. const changeFile = $(this)[0].files[0];
  58. if (changeFile) {
  59. const fileName = changeFile.name;
  60. $attach.html('<div><span class="attach-delete" title="첨부파일 제거" onclick="deleteAttach()"></span>'+fileName+'</div>');
  61. }
  62. })
  63. function deleteAttach() {
  64. $attachFile.val("");
  65. $attach.html("<div>첨부파일 없음</div>")
  66. console.log($attachFile[0].files[0]);
  67. }
  68. function save() {
  69. const title = $title.val();
  70. const content = $content.val();
  71. const file = $attachFile[0].files[0];
  72. const formData = new FormData();
  73. if (isNull(title)) {
  74. $title.focus();
  75. return alert("공지사항 제목을 입력해주세요.");
  76. }
  77. if (isNull(content)) {
  78. $content.focus();
  79. return alert("공지사항 내용을 입력해주세요.");
  80. }
  81. formData.append("bSubject", title);
  82. formData.append("bContent", content);
  83. if (file) {
  84. formData.append("attachFile", file);
  85. }
  86. $.ajax({
  87. url: '/api/popup/writePopup',
  88. processData : false,
  89. contentType: false,
  90. data: formData,
  91. type: 'POST',
  92. success: function(jsonData) {
  93. if (jsonData) {
  94. alert(jsonData.message);
  95. if (jsonData.success === "S") {
  96. window.location.href = "/phits/popup-list";
  97. }
  98. }
  99. },
  100. error: function(error) {
  101. alert(error.responseJSON.message);
  102. }
  103. });
  104. }
  105. </script>