Skip to content
Snippets Groups Projects
Commit ef285694 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

Merge branch 'bugfix-upload-thumbnail' into 'master'


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

Signed-off-by: default avatarman13 <man13@inf.ufpr.br>

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