Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Géocontrib Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
externe Matthieu
Géocontrib Frontend
Commits
fc202727
Commit
fc202727
authored
3 years ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
validate attachments for comment
parent
eb50668f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/views/feature/Feature_detail.vue
+50
-10
50 additions, 10 deletions
src/views/feature/Feature_detail.vue
with
50 additions
and
10 deletions
src/views/feature/Feature_detail.vue
+
50
−
10
View file @
fc202727
...
...
@@ -301,7 +301,7 @@
style=
"display: none"
name=
"attachment_file"
id=
"attachment_file"
@
change=
"
getAttachmentFileData($event)
"
@
change=
"
onFileChange
"
/>
</div>
<div
class=
"field"
>
...
...
@@ -314,6 +314,11 @@
{{
comment_form
.
title
.
errors
}}
</div>
</div>
<ul
v-if=
"comment_form.attachment_file.errors"
class=
"errorlist"
>
<li>
{{
comment_form
.
attachment_file
.
errors
}}
</li>
</ul>
<button
@
click=
"postComment"
type=
"button"
...
...
@@ -503,15 +508,50 @@ export default {
this
.
comment_form
.
comment
.
value
=
null
;
},
getAttachmentFileData
(
evt
)
{
const
files
=
evt
.
target
.
files
||
evt
.
dataTransfer
.
files
;
const
period
=
files
[
0
].
name
.
lastIndexOf
(
"
.
"
);
const
fileName
=
files
[
0
].
name
.
substring
(
0
,
period
);
const
fileExtension
=
files
[
0
].
name
.
substring
(
period
+
1
);
const
shortName
=
fileName
.
slice
(
0
,
10
)
+
"
[...].
"
+
fileExtension
;
this
.
comment_form
.
attachment_file
.
file
=
files
[
0
];
this
.
comment_form
.
attachment_file
.
value
=
shortName
;
this
.
comment_form
.
title
.
value
=
shortName
;
validateImgFile
(
files
,
handleFile
)
{
let
url
=
window
.
URL
||
window
.
webkitURL
;
let
image
=
new
Image
();
image
.
onload
=
function
()
{
handleFile
(
true
);
};
image
.
onerror
=
function
()
{
handleFile
(
false
);
};
image
.
src
=
url
.
createObjectURL
(
files
);
URL
.
revokeObjectURL
(
image
.
src
);
},
onFileChange
(
e
)
{
// * read image file
const
files
=
e
.
target
.
files
||
e
.
dataTransfer
.
files
;
const
_this
=
this
;
//* 'this' is different in onload function
function
handleFile
(
isValid
)
{
if
(
isValid
)
{
const
period
=
files
[
0
].
name
.
lastIndexOf
(
"
.
"
);
const
fileName
=
files
[
0
].
name
.
substring
(
0
,
period
);
const
fileExtension
=
files
[
0
].
name
.
substring
(
period
+
1
);
const
shortName
=
fileName
.
slice
(
0
,
10
)
+
"
[...].
"
+
fileExtension
;
_this
.
comment_form
.
attachment_file
.
file
=
files
[
0
];
//* store the file to post later
_this
.
comment_form
.
attachment_file
.
value
=
shortName
;
//* for display
_this
.
comment_form
.
title
.
value
=
shortName
;
_this
.
comment_form
.
attachment_file
.
errors
=
null
;
}
else
{
_this
.
comment_form
.
attachment_file
.
errors
=
"
Transférez une image valide. Le fichier que vous avez transféré n'est pas une image, ou il est corrompu.
"
;
}
}
if
(
files
.
length
)
{
//* exception for pdf
if
(
files
[
0
].
type
===
"
application/pdf
"
)
{
handleFile
(
true
);
}
else
{
this
.
comment_form
.
attachment_file
.
errors
=
null
;
//* check if file is an image and pass callback to handle file
this
.
validateImgFile
(
files
[
0
],
handleFile
);
}
}
},
goBackToProject
(
message
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment