Skip to content
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

[Review] 289 - As an artist, I want to receive a warning when I try to upload the wrong file format, so I can publish the right one. #517

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,8 @@ msgstr "Digite o código que você recebeu em seu e-mail."
msgid "Type your username or e-mail"
msgstr "Digite seu nome de usuário ou email"

#: src/ARte/users/jinja2/users/signup.jinja2:29
msgid "Remember me"
msgstr "Lembre-se de mim"

#: src/ARte/users/jinja2/users/login.jinja2:35
#: src/ARte/users/jinja2/users/signup.jinja2:29
msgid "Remember me"
msgstr "Lembre-se de mim"

Expand Down Expand Up @@ -759,4 +756,9 @@ msgstr "Não encontramos nenhum objeto por aqui :( Tente fazer upload."

#: src/ARte/users/jinja2/users/upload-marker.jinja2:19
msgid "Choose Marker's title"
msgstr "Escolha o título do seu Marcador"
msgstr "Escolha o título do seu Marcador"

#: src/ARte/users/jinja2/users/upload-object.jinja2:138
#: src/ARte/users/jinja2/users/edit-object.jinja2:88
msgid "Invalid file type! Only image or video files are accepted."
msgstr "Arquivo inválido! Apenas imagens ou videos são aceitos."
42 changes: 33 additions & 9 deletions src/users/jinja2/users/edit-object.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,43 @@

$("#id_source").change(
function(e) {
for (var i = 0; i < e.originalEvent.srcElement.files.length; i++) {
var file = e.originalEvent.srcElement.files[i];

var image_preview = document.createElement("img");
var reader = new FileReader();
reader.onloadend = function() {
var file = e.originalEvent.srcElement.files[0];
var image_preview = null;
var previewAndLoadFile = null;
var content_box = document.createElement("div");
content_box.id = "content-box";

if (file.type === "video/mp4" || file.type === "video/webm") {
image_preview = document.createElement("video");
previewAndLoadFile = function () {
image_preview.src = reader.result;
image_preview.id = "img-preview";
image_preview.controls = "controls";
image_preview.autoplay = "autoplay";
image_preview.muted = "muted";
document.getElementById("id_source").after(content_box);
document.getElementById("content-box").appendChild(image_preview); //make preview image of the object/marker show
}
} else if (file.type.includes("image/")) {
image_preview = document.createElement("img");
previewAndLoadFile = function () {
image_preview.src = reader.result;
image_preview.id = "img-preview";
image_preview.hidden = "hidden";
document.getElementById("id_source").after(content_box);
document.getElementById("content-box").appendChild(image_preview); //make preview image of the object/marker show
}
reader.readAsDataURL(file);
$("input").after(image_preview); //make preview image of the object/marker show
} else {
alert("{{ _("Invalid file type! Only image or video files are accepted.") }}")

document.getElementById("id_source").value = "";

if (document.querySelector('#img-preview'))
document.querySelector('#img-preview').remove();
}

var reader = new FileReader();
reader.onloadend = previewAndLoadFile;
reader.readAsDataURL(file);
}
);

Expand Down
10 changes: 9 additions & 1 deletion src/users/jinja2/users/upload-object.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
var previewAndLoadFile = null;
var content_box = document.createElement("div");
content_box.id = "content-box";

if (file.type === "video/mp4" || file.type === "video/webm") {
image_preview = document.createElement("video");
previewAndLoadFile = function() {
Expand All @@ -125,14 +126,21 @@
document.getElementById("id_source").after(content_box);
document.getElementById("content-box").appendChild(image_preview); //make preview image of the object/marker show
}
} else {
} else if(file.type.includes("image/")) {
image_preview = document.createElement("img");
previewAndLoadFile = function() {
image_preview.src = reader.result;
image_preview.id = "img-preview";
document.getElementById("id_source").after(content_box);
document.getElementById("content-box").appendChild(image_preview); //make preview image of the object/marker show
}
} else {
alert("{{ _("Invalid file type! Only image or video files are accepted.") }}")

document.getElementById("id_source").value = "";

if (document.querySelector('#img-preview'))
document.querySelector('#img-preview').remove();
}

var reader = new FileReader();
Expand Down