Skip to content
Snippets Groups Projects
Commit 4928c1a5 authored by Matheus Agio Nerone's avatar Matheus Agio Nerone
Browse files

Fixing script that give feedback to the user about the uploaded thumbnail (fixes #28)


Signed-off-by: default avatarman13 <man13@inf.ufpr.br>
parent 552a6538
No related branches found
No related tags found
No related merge requests found
......@@ -29,13 +29,14 @@
<h3 class="head text-center">Envie uma foto de destaque para <strong><%= @learning_object.name %></strong></h3>
<%= form_for @learning_object, url: wizard_path, method: :put, html: { multipart: true } do |f| %>
<div id="preview_image_target"></div>
<% unless @learning_object.thumbnail.blank? %>
<div>
<%= image_tag @learning_object.default_thumbnail.url(:small) %>
<i id="remove_thumbnail" class="fa fa-trash fa-1"></i></div>
<% end %>
<div id="preview_image_target">
<div>
<% unless @learning_object.thumbnail.blank? %>
<%= image_tag @learning_object.default_thumbnail.url(:medium) %>
<i id="remove_thumbnail" class="fa fa-trash fa-1"></i>
<% end %>
</div>
</div>
<%= f.file_field :thumbnail, required: true, id: 'thumbnail_btn' %>
......@@ -50,34 +51,36 @@
<button type="button" class="btn-submit btn btn-danger btn-outline-rounded red">Voltar</button>
<% end %>
<% end %>
<% end %>
<!-- -->
<script>
$("#remove_thumbnail").click(function(){
<script>
$("#remove_thumbnail").click(function(){
if(confirm("Você tem certeza?")){
$(this).parent().remove()
$.ajax({
url: "<%= remove_thumbnail_path(@learning_object) %>",
method: 'POST'
})
$(this).parent().remove()
$.ajax({
url: "<%= remove_thumbnail_path(@learning_object) %>",
method: 'POST'
})
}
});
});
// show preview image
$(function() {
// show preview image
$(function() {
$('#thumbnail_btn').on('change', function(event) {
var files = event.target.files;
var image = files[0]
var reader = new FileReader();
reader.onload = function(file) {
var img = new Image();
console.log(file);
img.src = file.target.result;
$('#preview_image_target').html(img);
}
reader.readAsDataURL(image);
console.log(files);
var files = event.target.files;
var image = files[0]
var reader = new FileReader();
reader.onload = function(file) {
var img = new Image();
console.log(file);
img.src = file.target.result;
$('#preview_image_target').html(img);
$('#preview_image_target > img').height(300)
$('#preview_image_target > img').width(300)
}
reader.readAsDataURL(image);
console.log(files);
});
});
</script>
\ No newline at end of file
});
</script>
<% end %>
<!-- -->
\ No newline at end of file
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