<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- <meta name="viewport" content="width=xotmxm, initial-scale=1.0"> -->
<title>투두</title>
<style>
html,
body,
h1,
h2,
h3,
div,
span,
a,
button,
input {
margin: 0;
padding: 0;
box-sizing: content-box;
}
body {
background-color: azure;
}
.wrap {
background-color: beige;
width: 350px;
height: 700px;
margin: auto;
}
.flex-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.flex-col {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.wrap-todo {
padding: 16px;
}
h2 {
font-size: 24px;
margin: 16px;
}
.todo {
padding: 16px;
background-color: cadetblue;
border-radius: 8px;
width: 300px;
height: 30px;
margin-bottom: 8px;
}
.todo-content {
margin-left: 8px;
margin-right: auto;
color: rgb(217, 240, 13);
cursor: pointer;
}
.todo>input {
zoom: 1.5;
}
.add-form {
padding: 16px;
background-color: rgb(192, 243, 201);
border: 1px solid red;
border-radius: 8px;
width: 300px;
height: 30px;
display: none;
}
.add-form-btns {
margin-left: auto;
}
.add-form-btns>button {
margin: 0px 4px;
background-color: transparent;
border: none;
cursor: pointer;
font-size: 12px;
font-weight: 600;
}
.add-form>input {
border: none;
background-color: transparent;
font-size: 16px;
width: 200px;
}
.add-form>input:focus-visible {
outline: none;
}
.add-btn {
padding: 16px;
background-color: transparent;
border: 1px dashed rgb(54, 115, 143);
border-radius: 8px;
width: 300px;
height: 30px;
cursor: pointer;
}
.add-btn>span {
margin-bottom: 4px;
}
.add-btn>button {
margin-left: 8px;
margin-right: auto;
background-color: transparent;
border: none;
cursor: pointer;
font-size: 12px;
font-weight: 600;
}
.todo>button {
background-color: transparent;
border: none;
font-weight: 600;
cursor: pointer;
font-size: 11px;
color: coral;
}
.todo-content-modify {
background-color: transparent;
border: none;
margin: 0px 8px;
font-weight: 600;
cursor: pointer;
}
.todo-content-modify>input {
background-color: transparent;
border: none;
font-size: 16px;
margin-left: 8px;
margin-right: auto;
color: brown;
width: 160px;
}
.todo-content-modify>input:focus-visible {
outline: none;
}
.todo-content-modify>button {
margin: 0px 8px;
font-weight: 600;
cursor: pointer;
background-color: transparent;
border: none;
font-size: 11px;
}
.calender{
background-color: chartreuse;
}
.calender > h2{
margin: 16px 0px;
}
.days{
display: grid;
grid-template-columns: repeat(7,1fr);
grid-gap: 18px;
margin-bottom: 20px;
}
.days>div{
width: 30px;
height: 30px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.dates{
display: grid;
grid-template-columns: repeat(7,1fr);
grid-gap: 18px;
margin-bottom: 20px;
}
.dates>div{
width: 30px;
height: 30px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
</style>
<script>
$(document).ready(() => {
listcontent()
})
function showAddform() {
$("#add-form").css("display", "flex")
$("#add-btn").hide()
}
function hideAddform() {
if (confirm("정말취소하시겠습니가?.")) {
$("#add-form").hide()
$("#add-btn").css("display", "flex")
}
}
function addContent() {
let content = $("#content").val();
let formData = new FormData()
formData.append("content_give", content)
fetch('/post', { method: "POST", body: formData }).then(res => res.json()).then(data => {
alert(data["msg"])
window.location.reload()
})
}
function listcontent() {
fetch("/list").then(res => res.json()).then(data => {
let rows = data["result"];
rows.forEach((row) => {
let content = row["content"]
let _id = row["_id"]
let check = row["check"]
let txt_checked = ''
let txt_style = ''
if (check == "true") {
txt_checked = "checked"
txt_style = 'style="text-decoration:line-through"'
}
let temp_html = `<div id="${_id}" class="todo flex-row">
<input ${txt_checked} type="checkbox" onchange="checkContent('${_id}')">
<span style=${txt_style} onclick="showUpdateForm('${_id}')" class="todo-content">${content}</span>
<button onclick="deleteContent('${_id}')">삭제</button>
<div style="display: none;" class="todo-content-modify flex-row">
<input value="${content}" type="text">
<button onclick="modifyContent('${_id}')">수정</button>
<button onclick="hideUpdaeform('${_id}')">취소</button>
</div>
</div>
`
$("#todos").append(temp_html)
})
})
}
function test() {
if (confirm("확인 또는 취소를 선택해주세요.")) {
alert("확인을 누르셨습니다.");
} else {
alert("취소를 누르셨습니다.");
}
}
function showUpdateForm(_id) {
$(`#${_id} > span`).hide();
$(`#${_id}>button`).hide();
$(`#${_id}> input`).hide();
$(`#${_id} > div`).css('display', 'flex');
}
function hideUpdaeform(_id) {
$(`#${_id} > span`).show();
$(`#${_id}>button`).show();
$(`#${_id}> input`).show();
$(`#${_id} > div`).css('display', 'none');
}
function modifyContent(_id) {
let formData = new FormData()
formData.append("id_give", _id)
fetch('/modify', { method: "POST", body: formData }).then(res => res.json()).then(data => {
alert(data["msg"])
window.location.reload()
})
}
function deleteContent(_id) {
let formData = new FormData()
formData.append("id_give", _id)
fetch('/delete', { method: "POST", body: formData }).then(res => res.json()).then(data => {
alert(data["msg"])
window.location.reload()
})
}
function checkContent(_id) {
let is_checked = $(`#${_id}>input`).is(":checked");
let formData = new FormData()
formData.append("id_give", _id)
formData.append("check_give", is_checked)
fetch('/check', { method: "POST", body: formData }).then(res => res.json()).then(data => {
alert(data["msg"])
window.location.reload()
})
}
</script>
</head>
<body>
<div>
<div class="wrap">
<div class="calender flex-col">
<h2>2024.7월</h2>
<div class="days">
<div>일</div>
<div>월</div>
<div>화</div>
<div>수</div>
<div>목</div>
<div>금</div>
<div>토</div>
</div>
<div class="dates flex-col">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
</div>
<div class="wrap-todo flex-col">
<h1>오늘의 할일</h1>
<div id="todos" class="todos flex-col">
<div class="todos flex-col">
<!-- <div id="_id" class="todo flex-row">
<input type="checkbox">
<span onclick="showUpdateForm('_id')" class="todo-content">수정하기</span>
<div style="display: none;" class="todo-content-modify flex-row">
<input value="수정하기" type="text">
<button>수정</button>
<button onclick="hideUpdaeform(_id)">취소</button>
</div> -->
</div>
</div>
</div>
<div id="add-form" class="add-form flex-row">
<input id="content" type="text">
<div class="add-form-btns flex-row">
<button onclick="addContent()">추가</button>
<button onclick="hideAddform ()">취소</button>
</div>
</div>
<div id="add-btn" onclick="showAddform()" class="add-btn flex-row">
<span>+</span>
<button>추가하기</button>
</div>
</div>
</div>
</div>
</body>
</html>