-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost-update.html
More file actions
600 lines (566 loc) · 28.1 KB
/
post-update.html
File metadata and controls
600 lines (566 loc) · 28.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Post Update Form</title>
<meta content="" name="description" />
<meta content="" name="keywords" />
<!-- Favicons -->
<link href="assets/img/favicon.png" rel="icon" />
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon" />
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,600;1,700&family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Inter:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
rel="stylesheet"
/>
<!-- Vendor CSS Files -->
<link
href="assets/vendor/bootstrap/css/bootstrap.min.css"
rel="stylesheet"
/>
<link
href="assets/vendor/bootstrap-icons/bootstrap-icons.css"
rel="stylesheet"
/>
<link
href="assets/vendor/fontawesome-free/css/all.min.css"
rel="stylesheet"
/>
<link
href="assets/vendor/glightbox/css/glightbox.min.css"
rel="stylesheet"
/>
<link
href="assets/vendor/swiper/swiper-bundle.min.css"
rel="stylesheet"
/>
<link href="assets/vendor/aos/aos.css" rel="stylesheet" />
<!-- Template Main CSS File -->
<link href="assets/css/main.css" rel="stylesheet" />
<style>
.form-control:focus {
background-color: #ffffe0; /* 옅은 노란색 */
border-color: #ced4da;
box-shadow: none;
}
.form-control {
background-color: #ffffe0; /* 옅은 노란색 */
color: #495057;
}
.form-label {
color: #6c757d; /* 회색 */
}
#InputContent {
resize: none;
}
</style>
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
<!-- =======================================================
* Template Name: Logis
* Template URL: https://bootstrapmade.com/logis-bootstrap-logistics-website-template/
* Updated: Mar 17 2024 with Bootstrap v5.3.3
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
</head>
<body>
<header id="header" class="header d-flex align-items-center fixed-top">
<div
class="container-fluid container-xl d-flex align-items-center justify-content-between"
>
<a href="index.html" class="logo d-flex align-items-center">
<!-- Uncomment the line below if you also wish to use an image logo -->
<!-- <img src="assets/img/logo.png" alt=""> -->
<h1>IF</h1>
</a>
<i class="mobile-nav-toggle mobile-nav-show bi bi-list"></i>
<i class="mobile-nav-toggle mobile-nav-hide d-none bi bi-x"></i>
<nav id="navbar" class="navbar">
<ul>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="pricing.html">Pricing</a></li>
<li><a href="contact.html">Contact</a></li>
<li><span class="user-name"></span></li>
<li>
<a href="#" class="LoginBtn">Login</a>
</li>
<li><a href="#" id="userNameDisplay"></a></li>
<li>
<a href="#" id="profileLink">Profile</a>
</li>
<li><a href="#" class="LogoutBtn">Logout</a></li>
</ul>
</nav>
<!-- .navbar -->
</div>
</header>
<!-- End Header -->
<!-- End Header -->
<main id="main">
<!-- ======= Breadcrumbs ======= -->
<div class="breadcrumbs">
<div
class="page-header d-flex align-items-center"
style="background-image: url('assets/img/page-header.jpg')"
>
<div class="container position-relative">
<div class="row d-flex justify-content-center">
<div class="col-lg-6 text-center">
<h2>Update Post</h2>
<p>
Odio et unde deleniti. Deserunt numquam
exercitationem. Officiis quo odio sint
voluptas consequatur ut a odio voluptatem.
Sit dolorum debitis veritatis natus dolores.
Quasi ratione sint. Sit quaerat ipsum
dolorem.
</p>
</div>
</div>
</div>
</div>
<nav>
<div class="container">
<ol>
<li><a href="index.html">Home</a></li>
<li>Update Post</li>
</ol>
</div>
</nav>
</div>
<!-- End Breadcrumbs -->
<!-- ======= Post Create Section ======= -->
<section id="pricing" class="pricing">
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="post-form-container border p-5">
<h2 class="mb-4">포스트 수정</h2>
<form
method="POST"
enctype="multipart/form-data"
id="postForm"
>
<div class="mb-3">
<label
for="InputTitle"
class="form-label"
>제목</label
>
<input
type="text"
class="form-control"
id="InputTitle"
name="title"
required
/>
</div>
<div class="mb-3">
<label
for="InputCategory"
class="form-label"
>카테고리</label
>
<select
class="form-control"
id="InputCategory"
name="category"
required
></select>
</div>
<div class="mb-3">
<label
for="InputContent"
class="form-label"
>내용</label
>
<textarea
class="form-control"
id="InputContent"
name="content"
rows="3"
required
></textarea>
</div>
<div class="mb-3">
<label
for="InputImage"
class="form-label"
>이미지 업로드</label
>
<input
type="file"
class="form-control"
id="InputImage"
name="image"
accept="image/*"
/>
</div>
<div class="mb-3">
<label
for="InputFile"
class="form-label"
>파일 업로드</label
>
<input
type="file"
class="form-control"
id="InputFile"
name="file_upload"
accept=".pdf,.doc,.docx"
/>
</div>
<div class="d-grid gap-2">
<input
type="submit"
class="btn btn-primary"
value="포스트 수정"
/>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- End #main -->
<!-- ======= Footer ======= -->
<footer id="footer" class="footer">
<div class="container">
<div class="row gy-4">
<div class="col-lg-5 col-md-12 footer-info">
<a
href="index.html"
class="logo d-flex align-items-center"
>
<span>IF </span>
</a>
<p>물류 혁신을 위한 AI 첨단 기술 기업</p>
<div class="social-links d-flex mt-4">
<a href="#" class="twitter"
><i class="bi bi-twitter"></i
></a>
<a href="#" class="facebook"
><i class="bi bi-facebook"></i
></a>
<a href="#" class="instagram"
><i class="bi bi-instagram"></i
></a>
<a href="#" class="linkedin"
><i class="bi bi-linkedin"></i
></a>
</div>
</div>
<div class="col-lg-2 col-6 footer-links">
<h4>Useful Links</h4>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Terms of service</a></li>
<li><a href="#">Privacy policy</a></li>
</ul>
</div>
<div class="col-lg-2 col-6 footer-links">
<h4>Our Services</h4>
<ul>
<li><a href="#">AI 기반 재고 예측 솔루션 </a></li>
<li><a href="#">수요 데이터 분석 및 최적화 </a></li>
<li>
<a href="#">물류 프로세스 자동화 시스템 </a>
</li>
<li>
<a href="#">AI 플랫폼 통합 및 구축 컨설팅</a>
</li>
<li><a href="#">물류 블로그</a></li>
</ul>
</div>
<div
class="col-lg-3 col-md-12 footer-contact text-center text-md-start"
>
<h4>Contact Us</h4>
<p>
서울특별시 강남구 테헤란로 427, 13층 (삼성동)
<br /><br />
<strong>전화:</strong> 1800-9876
<br />
<strong>이메일:</strong> info@logisai.com
<br />
</p>
</div>
</div>
</div>
<div class="container mt-4">
<div class="copyright">
© Copyright <strong><span>IF</span></strong
>. All Rights Reserved
</div>
<div class="credits">
<!-- All the links in the footer should remain intact. -->
<!-- You can delete the links only if you purchased the pro version. -->
<!-- Licensing information: https://bootstrapmade.com/license/ -->
<!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/logis-bootstrap-logistics-website-template/ -->
Designed by
<a href="https://bootstrapmade.com/">BootstrapMade</a>
</div>
</div>
</footer>
<!-- End Footer -->
<a
href="#"
class="scroll-top d-flex align-items-center justify-content-center"
><i class="bi bi-arrow-up-short"></i>
</a>
<div id="preloader"></div>
<!-- Vendor JS Files -->
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/purecounter/purecounter_vanilla.js"></script>
<script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
<script src="assets/vendor/swiper/swiper-bundle.min.js"></script>
<script src="assets/vendor/aos/aos.js"></script>
<script src="assets/vendor/php-email-form/validate.js"></script>
<!-- Template Main JS File -->
<script src="assets/js/main.js"></script>
<script>
CKEDITOR.replace('InputContent');
document.addEventListener('DOMContentLoaded', () => {
const access = localStorage.getItem('access');
const loginBtnEl = document.querySelector('.LoginBtn');
const logoutBtnEl = document.querySelector('.LogoutBtn');
const userNameDisplayEl =
document.querySelector('#userNameDisplay');
const postForm = document.getElementById('postForm');
const profileLinkEl = document.getElementById('profileLink');
const isAuthenticated = !!access;
if (isAuthenticated) {
// 토큰 갱신
fetch('http://43.203.201.118/api/token/refresh/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
refresh: localStorage.getItem('refresh'),
}),
})
.then((response) => response.json())
.then((data) => {
const { access: newToken } = data;
localStorage.setItem('access', newToken);
// 사용자 이름 가져오기
fetch(
'http://43.203.201.118/api/accounts/profile/',
{
headers: {
Authorization: `Bearer ${newToken}`,
},
}
)
.then((response) => response.json())
.then((userData) => {
if (userNameDisplayEl) {
userNameDisplayEl.textContent =
userData.username;
}
if (loginBtnEl) {
loginBtnEl.style.display = 'none';
loginBtnEl.textContent =
userData.username;
}
})
.catch((error) => {
console.error(
'Error fetching username:',
error
);
});
if (logoutBtnEl) {
logoutBtnEl.style.display = 'block';
logoutBtnEl.addEventListener('click', () => {
// 로컬 스토리지에서 인증 토큰 삭제
localStorage.removeItem('access');
localStorage.removeItem('refresh');
// index.html로 리다이렉트
location.href = 'index.html';
});
}
})
.catch((error) => {
console.error('Error refreshing token:', error);
});
// URL에서 postId 값을 가져오는 함수
function getPostIdFromUrl() {
const queryParams = new URLSearchParams(
window.location.search
);
return queryParams.get('postId');
}
// postId를 사용하여 게시물의 세부 정보를 가져오는 함수
function fetchPostDetails(postId) {
fetch(`http://43.203.201.118/api/posts/${postId}/`, {
headers: {
Authorization: `Bearer ${localStorage.getItem(
'access'
)}`,
},
})
.then((response) => response.json())
.then((data) => {
fillPostDetailsForm(data);
})
.catch((error) => {
console.error(
'Error fetching post details:',
error
);
});
}
// 가져온 게시물의 세부 정보를 폼에 채우는 함수
function fillPostDetailsForm(post) {
document.getElementById('InputTitle').value =
post.title;
CKEDITOR.instances.InputContent.setData(post.content);
// document.getElementById('InputCategory').value =
// post.category.id;
if (post.category) {
// post.category 객체가 존재하는지 확인
document.getElementById('InputCategory').value =
post.category.id;
} else {
// post.category가 null이거나 존재하지 않을 때의 처리
// 예를 들어, 기본 값을 설정하거나, 사용자에게 카테고리가 없음을 알릴 수 있습니다.
console.log(
'이 게시물에는 카테고리가 지정되지 않았습니다.'
);
}
// 이미지와 파일 필드도 채워주어야 할 경우 추가 로직 필요
}
const postId = getPostIdFromUrl();
if (postId) {
fetchPostDetails(postId);
}
// 카테고리 목록 가져오기
fetch('http://43.203.201.118/api/posts/categories/', {
headers: {
Authorization: `Bearer ${localStorage.getItem(
'access'
)}`,
},
})
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((data) => {
const categories = data.results || [];
console.log('카테고리데이터:', categories);
const categorySelect =
document.getElementById('InputCategory');
categories.forEach((category) => {
const option = document.createElement('option');
option.value = category.id;
option.text = category.name;
categorySelect.add(option);
});
})
.catch((error) => {
console.error('Error fetching categories:', error);
});
const postForm = document.getElementById('postForm');
postForm.addEventListener('submit', function (e) {
e.preventDefault();
const postId = getPostIdFromUrl();
if (!postId) {
alert('유효한 접근이 아닙니다.');
return;
}
const formData = new FormData(postForm);
const editorData =
CKEDITOR.instances.InputContent.getData();
formData.append('content', editorData);
const categorySelect =
document.getElementById('InputCategory');
const selectedCategoryId = categorySelect.value;
formData.append('category', selectedCategoryId);
// CSRF 토큰 가져오기
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (
cookie.substring(0, name.length + 1) ===
name + '='
) {
cookieValue = decodeURIComponent(
cookie.substring(name.length + 1)
);
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
formData.append('csrfmiddlewaretoken', csrftoken);
fetch(
`http://43.203.201.118/api/posts/${postId}/update/`,
{
method: 'PATCH',
headers: {
Authorization: `Bearer ${localStorage.getItem(
'access'
)}`,
},
body: formData,
}
)
.then((response) => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then((data) => {
console.log(data);
location.href = 'services.html';
})
.catch((error) => {
console.error(
'There has been a problem with your fetch operation:',
error
);
});
});
profileLinkEl.addEventListener('click', () => {
location.href = 'profile.html';
});
} else {
// 로그인 되어 있지 않은 경우
if (loginBtnEl) {
loginBtnEl.style.display = 'block';
// 로그인 버튼에 이벤트 리스너 추가
loginBtnEl.addEventListener('click', () => {
// login.html로 리다이렉트
location.href = 'login.html';
});
}
if (logoutBtnEl) {
logoutBtnEl.style.display = 'none';
}
if (userNameDisplayEl) {
userNameDisplayEl.style.display = 'none';
}
}
});
</script>
</body>
</html>