Skip to content
Snippets Groups Projects
Commit 6abc3870 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

move some javascript to view

parent 146adfe9
No related branches found
No related tags found
No related merge requests found
// 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);
});
});
\ No newline at end of file
......@@ -33,23 +33,12 @@
<% unless @learning_object.thumbnail.blank? %>
<div>
<%= image_tag @learning_object.default_thumbnail.url %>
<%= image_tag @learning_object.default_thumbnail.url(:small) %>
<i id="remove_thumbnail" class="fa fa-trash fa-1"></i></div>
<script>
$("#remove_thumbnail").click(function(){
if(confirm("Você tem certeza?")){
$(this).parent().remove()
$.ajax({
url: "<%= remove_thumbnail_path(@learning_object) %>",
method: 'POST'
})
}
});
</script>
<% end %>
<%= f.file_field :thumbnail, required: true, id: 'thumbnail_btn' %>
<button type="submit" class="btn-submit btn btn-success btn-outline-rounded green">
Enviar <i style="margin-left:10px;" class="fa fa-paper-plane"></i>
</button>
......@@ -63,4 +52,32 @@
<% end %>
<% end %>
<!-- -->
\ No newline at end of file
<!-- -->
<script>
$("#remove_thumbnail").click(function(){
if(confirm("Você tem certeza?")){
$(this).parent().remove()
$.ajax({
url: "<%= remove_thumbnail_path(@learning_object) %>",
method: 'POST'
})
}
});
// 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);
});
});
</script>
\ 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