-
Notifications
You must be signed in to change notification settings - Fork 72
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
卒業証書のPDFファイルをアップロードできる機能を追加 #8190
base: main
Are you sure you want to change the base?
Changes from 5 commits
496b8ec
8385b8a
3d8dc4e
f3bc5cc
d16a661
fd1d8db
b2ff53d
3aeb25a
6b5d653
9b55b38
7d82332
97b19ed
ba692b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,42 @@ document.addEventListener('DOMContentLoaded', () => { | |
} | ||
initializeFileInput(document) | ||
}) | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const removePdfButton = document.getElementById('js-remove-pdf-button') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この辺りの変数名も、先のコメントで触れたように関数で括れば変数名にpdfってつけなくて良さそうです。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 変数名の変更とリファクタリングも一緒に行いました。 |
||
const pdfUploadField = document.getElementById('js-pdf-upload-field') | ||
const pdfFileLink = document.getElementById('js-pdf-file-link') | ||
const removePdfFlag = document.getElementById('js-remove-pdf-flag') | ||
const pdfFileNameDisplay = document.getElementById('js-pdf-name') | ||
|
||
removePdfButton.addEventListener('click', () => { | ||
if (pdfFileLink) pdfFileLink.style.display = 'none' | ||
pdfUploadField.style.display = 'flex' | ||
pdfUploadField.querySelector('input[type="file"]').value = '' | ||
removePdfFlag.value = '1' | ||
|
||
if (pdfFileNameDisplay) { | ||
pdfFileNameDisplay.textContent = '' | ||
pdfFileNameDisplay.style.display = 'none' | ||
} | ||
}) | ||
|
||
const fileInput = pdfUploadField.querySelector('input[type="file"]') | ||
fileInput.addEventListener('change', () => { | ||
if (fileInput.files && fileInput.files[0]) { | ||
const fileName = fileInput.files[0].name | ||
|
||
if (pdfFileNameDisplay) { | ||
pdfFileNameDisplay.textContent = fileName | ||
pdfFileNameDisplay.style.display = 'block' | ||
} | ||
|
||
removePdfFlag.value = '0' | ||
} else { | ||
if (pdfFileNameDisplay) { | ||
pdfFileNameDisplay.textContent = '' | ||
pdfFileNameDisplay.style.display = 'none' | ||
} | ||
} | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
.a-file-input | ||
label | ||
height: 10rem | ||
max-width: 100% | ||
margin-inline: auto | ||
border: solid 1px var(--input-border) | ||
background-color: var(--base) | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
+position(relative) | ||
overflow: hidden | ||
cursor: pointer | ||
border-radius: .25rem | ||
padding: .5rem .5rem 2.75rem .5rem | ||
&.is-thumbnail | ||
label | ||
height: 15rem | ||
img | ||
max-height: 100% | ||
transition: all .2s ease-out | ||
&:hover | ||
opacity: .6 | ||
&.is-square img | ||
+size(7rem) | ||
object-fit: cover | ||
&.is-book img | ||
max-height: 100% | ||
max-width: 100% | ||
object-fit: contain | ||
border: solid 1px var(--border-tint) | ||
.a-pdf-input | ||
display: flex | ||
gap: .75rem | ||
+media-breakpoint-down(sm) | ||
flex-direction: column | ||
|
||
.a-pdf-input__inner | ||
flex: 1 | ||
background-color: var(--base) | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
+position(relative) | ||
overflow: hidden | ||
cursor: pointer | ||
border-radius: .25rem | ||
height: 2.25rem | ||
input | ||
overflow: hidden | ||
+size(0) | ||
+position(absolute, left 0, top 0) | ||
opacity: 0 | ||
p | ||
+size(100% 2.25rem) | ||
background-color: var(--base) | ||
+position(absolute, left 0, bottom 0, right 0) | ||
+text-block(.8125rem 1, flex 600) | ||
justify-content: center | ||
align-items: center | ||
border-top: solid 1px var(--input-border) | ||
transition: all .2s ease-out | ||
&:hover | ||
background-color: #e8e8e8 | ||
|
||
a.a-pdf-input__inner | ||
text-decoration: none | ||
color: var(--default-text) | ||
|
||
.a-pdf-input__file | ||
padding: .5rem | ||
flex: 1 | ||
border-radius: .25rem 0 0 .25rem | ||
border: solid 1px var(--input-border) | ||
border-right: none | ||
height: 2.25rem | ||
|
||
.a-pdf-input__file-name | ||
font-size: .875rem | ||
white-space: nowrap | ||
overflow: hidden | ||
text-overflow: ellipsis | ||
display: block | ||
+media-breakpoint-up(md) | ||
max-width: 18rem | ||
+media-breakpoint-down(sm) | ||
max-width: 8rem | ||
|
||
.a-pdf-input__upload.a-button | ||
border-radius: 0 .25rem .25rem 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.a-pdf-input | ||
display: flex | ||
gap: .75rem | ||
+media-breakpoint-down(sm) | ||
flex-direction: column | ||
|
||
.a-pdf-input__inner | ||
flex: 1 | ||
background-color: var(--base) | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
+position(relative) | ||
overflow: hidden | ||
cursor: pointer | ||
border-radius: .25rem | ||
height: 2.25rem | ||
input | ||
overflow: hidden | ||
+size(0) | ||
+position(absolute, left 0, top 0) | ||
opacity: 0 | ||
|
||
a.a-pdf-input__inner | ||
text-decoration: none | ||
color: var(--default-text) | ||
|
||
.a-pdf-input__file | ||
padding: .5rem | ||
flex: 1 | ||
border-radius: .25rem 0 0 .25rem | ||
border: solid 1px var(--input-border) | ||
border-right: none | ||
height: 2.25rem | ||
|
||
.a-pdf-input__file-name | ||
font-size: .875rem | ||
white-space: nowrap | ||
overflow: hidden | ||
text-overflow: ellipsis | ||
display: block | ||
+media-breakpoint-up(md) | ||
max-width: 18rem | ||
+media-breakpoint-down(sm) | ||
max-width: 8rem | ||
|
||
.a-pdf-input__upload.a-button | ||
border-radius: 0 .25rem .25rem 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,28 @@ | |
.form-item-block__item | ||
= render 'users/form/graduate', f: f | ||
|
||
.form-item | ||
// 卒業証書 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このコメントは必要ないかもです🙆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 削除しました |
||
= f.hidden_field :remove_diploma, value: '0', id: 'js-remove-pdf-flag' | ||
= f.label :diploma_file, class: 'a-form-label' | ||
.a-pdf-input | ||
- if @user.diploma_file.attached? | ||
= link_to url_for(@user.diploma_file), class: 'a-pdf-input__inner', id: 'js-pdf-file-link', target: '_blank', rel: 'noopener' do | ||
.a-pdf-input__file | ||
span.a-pdf-input__file-name | ||
= @user.diploma_file.filename | ||
.a-pdf-input__upload.a-button.is-md.is-secondary | ||
| PDFを確認 | ||
- display = @user.diploma_file.attached? ? 'display: none' : 'display: flex' | ||
label.a-pdf-input__inner#js-pdf-upload-field(style="#{display}") | ||
= f.file_field :diploma_file | ||
.a-pdf-input__file | ||
span.a-pdf-input__file-name#js-pdf-name | ||
.a-pdf-input__upload.a-button.is-md.is-secondary | ||
| PDFを選択 | ||
button.a-button.is-md.is-secondary(type='button' id='js-remove-pdf-button') | ||
| 削除 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. button_tagが使えそうです! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 変更しました There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ファイルがアップロードされていない状態で削除ボタンがあるのはおかしい気がします🤔 |
||
.form-item-block | ||
.form-item-block__inner | ||
header.form-item-block__header | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ ja: | |
other_editor: その他のエディタ | ||
hide_mentor_profile: プロフィール非公開 | ||
invoice_payment: 「請求書払い」 | ||
diploma_file: 卒業証書PDF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 提案です! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. そちらの方がいいと思います。変更しました |
||
discord_profile: | ||
account_name: Discord アカウント | ||
times_url: 分報URL | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="ja"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>卒業証書</title> | ||
</head> | ||
<body> | ||
<h1>卒業証書</h1> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今回実装する部分を関数にして↑の DOMContentLoadedに入れてはどうでしょうか?
あと画面の読み込み時に実行していますが、該当する画面でない場合のreturnがなさそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
変更しました
6b5d653