-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
import Vue from 'vue' | ||
import CheckStamp from 'check-stamp.vue' | ||
import store from 'check-store.js' | ||
import CSRF from 'csrf' | ||
import 'whatwg-fetch' | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const checkStamp = document.getElementById('js-check-stamp') | ||
if (checkStamp) { | ||
const checkableId = checkStamp.getAttribute('data-checkable-id') | ||
const checkableType = checkStamp.getAttribute('data-checkable-type') | ||
new Vue({ | ||
store, | ||
render: (h) => | ||
h(CheckStamp, { | ||
props: { | ||
checkableId: checkableId, | ||
checkableType: checkableType | ||
} | ||
}) | ||
}).$mount('#js-check-stamp') | ||
} | ||
setChecks() | ||
}) | ||
|
||
const setChecks = () => { | ||
const checkStamp = document.getElementById('js-check-stamp') | ||
if (!checkStamp) return | ||
|
||
const checkableType = checkStamp.getAttribute('data-checkable-type') | ||
const checkableId = checkStamp.getAttribute('data-checkable-id') | ||
fetch( | ||
`/api/checks.json/?checkable_type=${checkableType}&checkable_id=${checkableId}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'X-Requested-With': 'XMLHttpRequest', | ||
'X-CSRF-Token': CSRF.getToken() | ||
}, | ||
credentials: 'same-origin' | ||
} | ||
) | ||
.then((response) => { | ||
return response.json() | ||
}) | ||
.then((json) => { | ||
const checkStampElement = document.querySelector('.stamp-approve') | ||
|
||
if (!json[0]) return checkStampElement.classList.add('is-hidden') | ||
|
||
checkStampElement.classList.remove('is-hidden') | ||
|
||
const checkedUserName = document.querySelector('.is-user-name') | ||
const checkedCreatedAt = document.querySelector('.is-created-at') | ||
checkedUserName.textContent = json[0].user.login_name | ||
checkedCreatedAt.textContent = json[0].created_at | ||
|
||
store.dispatch('setCheckable', { | ||
checkableId: checkableId, | ||
checkableType: checkableType | ||
}) | ||
}) | ||
.catch((error) => { | ||
console.warn(error) | ||
}) | ||
} | ||
|
||
export default setChecks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.stamp.stamp-approve.show.is-hidden | ||
h2.stamp__content.is-title | ||
| 確認済 | ||
time.stamp__content.is-created-at | ||
.stamp__content.is-user-name | ||
.stamp__content-inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters