Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#94 #20

Merged
merged 1 commit into from Feb 27, 2022
Merged

#94 #20

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 65 additions & 9 deletions index.html
Expand Up @@ -146,8 +146,47 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>
return "class-checkbox"
}

class Memos {
constructor() {
this.memos = []
}

addMemo(title, body) {
const memo = new Memo(title, body)
memo.showErrorOnAddModal()

if (memoList.children.length > 0) {
Array.from(memoList.children).forEach((tr) => {
if (tr.id == memo.id) {
return
}

const t = getIdTitleInMemoList(tr.id).innerText
if (title == t) {
validationErrorInAddModal.innerHTML = "すでに登録済みのタイトルです。<br>"
}
})
}

if (validationErrorInAddModal.innerHTML.length > 0) {
validationErrorInAddModal.style.display = ""
return false
}
this.memos.push(memo)
}
}

class Memo {
constructor(title, body) {
this.errorStr = ""
if (title.length < 1 || title.length > 30) {
this.errorStr = "タイトルの文字数は1文字以上30文字以下にしてください。<br>"
}

if (body.length < 1 || body.length > 100) {
this.errorStr = errorStr + "本文の文字数は1文字以上100文字以下にしてください。<br>"
}

this.title = title
this.body = body

Expand All @@ -156,6 +195,20 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>
this.createdAt = now
this.updatedAt = now
}

getDisplayedUpdatedAt() {
if (this.createdAt = this.updatedAt) {
return "なし"
}
return this.updatedAt
}
showErrorOnAddModal() {
if (this.errorStr.length > 0) {
validationErrorInAddModal.innerHTML = this.errorStr
return false
}
return true
}
}

function getNow() {
Expand Down Expand Up @@ -220,14 +273,15 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>

function validateMemo(title, body, errorHTMLElement, memoId) {
errorHTMLElement.innerHTML = ""
if (title.length < 1 || title.length > 30) {
errorHTMLElement.innerHTML = "タイトルの文字数は1文字以上30文字以下にしてください。<br>"
}
//if (title.length < 1 || title.length > 30) {
// errorHTMLElement.innerHTML = "タイトルの文字数は1文字以上30文字以下にしてください。<br>"
//}

if (body.length < 1 || body.length > 100) {
errorHTMLElement.innerHTML = errorHTMLElement.innerHTML + "本文の文字数は1文字以上100文字以下にしてください。<br>"
}
//if (body.length < 1 || body.length > 100) {
// errorHTMLElement.innerHTML = errorHTMLElement.innerHTML + "本文の文字数は1文字以上100文字以下にしてください。<br>"
//}

//すでに登録済みのタイトルがないかをチェックする
if (memoList.children.length > 0) {
Array.from(memoList.children).forEach((tr) => {
if (tr.id == memoId) {
Expand All @@ -254,13 +308,15 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>
const title = titleInAddModal.value
const body = bodyInAddModal.value

const memo = new Memo(title, body)

if (validateMemo(title, body, validationErrorInAddModal, "0") == false) {
return
}

const createdAt = getNow()
const updatedAt = "なし"
const memoId = dayjs().valueOf()
const createdAt = memo.createdAt
const updatedAt = memo.getDisplayedUpdatedAt()
const memoId = memo.id

const tr = document.createElement("tr")
tr.setAttribute("id", memoId)
Expand Down