Skip to content
Snippets Groups Projects
Commit c015168a authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA :bicyclist:
Browse files

Merge branch 'redmine-issues/12049' into 'develop'

parents 3705e858 fc202727
No related branches found
No related tags found
No related merge requests found
...@@ -301,7 +301,7 @@ ...@@ -301,7 +301,7 @@
style="display: none" style="display: none"
name="attachment_file" name="attachment_file"
id="attachment_file" id="attachment_file"
@change="getAttachmentFileData($event)" @change="onFileChange"
/> />
</div> </div>
<div class="field"> <div class="field">
...@@ -314,6 +314,11 @@ ...@@ -314,6 +314,11 @@
{{ comment_form.title.errors }} {{ comment_form.title.errors }}
</div> </div>
</div> </div>
<ul v-if="comment_form.attachment_file.errors" class="errorlist">
<li>
{{ comment_form.attachment_file.errors }}
</li>
</ul>
<button <button
@click="postComment" @click="postComment"
type="button" type="button"
...@@ -503,15 +508,50 @@ export default { ...@@ -503,15 +508,50 @@ export default {
this.comment_form.comment.value = null; this.comment_form.comment.value = null;
}, },
getAttachmentFileData(evt) { validateImgFile(files, handleFile) {
const files = evt.target.files || evt.dataTransfer.files; let url = window.URL || window.webkitURL;
const period = files[0].name.lastIndexOf("."); let image = new Image();
const fileName = files[0].name.substring(0, period); image.onload = function () {
const fileExtension = files[0].name.substring(period + 1); handleFile(true);
const shortName = fileName.slice(0, 10) + "[...]." + fileExtension; };
this.comment_form.attachment_file.file = files[0]; image.onerror = function () {
this.comment_form.attachment_file.value = shortName; handleFile(false);
this.comment_form.title.value = shortName; };
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) { goBackToProject(message) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment