Skip to content

Commit

Permalink
Merge pull request #20 from tio-iis/branch94
Browse files Browse the repository at this point in the history
#94
  • Loading branch information
tio-iis committed Feb 27, 2022
2 parents 7187db2 + 8a9f278 commit 498afb7
Showing 1 changed file with 65 additions and 9 deletions.
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

0 comments on commit 498afb7

Please sign in to comment.