diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index 0b45c23f7e87a2865ed69189f04bf08a2cf67612..41978b12953e84793255074c1fff707cd05b48ed 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -6,7 +6,7 @@ class LearningObjectsController < ApplicationController before_action :authenticate_user!, except: [:index, :show] before_action :set_learning_object, only: [:show, :edit, :update, - :destroy, :destroy_attachment, :like, :bookmarks, + :destroy, :destroy_attachment, :remove_thumbnail, :like, :bookmarks, :collections, :upload, :upload_link, :download, :user_not_authorized] after_action :increment_learning_object_views, only: [:show] @@ -88,6 +88,12 @@ class LearningObjectsController < ApplicationController render :nothing => true, :status => 204 end + def remove_thumbnail + @learning_object.thumbnail = nil + @learning_object.save + render :nothing => true, :status => 204 + end + def download @learning_object.download current_user diff --git a/app/policies/learning_object_policy.rb b/app/policies/learning_object_policy.rb index 5d413e3c6c9f4dcabefbfa3a3b2e0297e95475a2..2237cf7910260de711c9c5fb86fe95732f108340 100644 --- a/app/policies/learning_object_policy.rb +++ b/app/policies/learning_object_policy.rb @@ -30,6 +30,10 @@ class LearningObjectPolicy < ApplicationPolicy record if owns? end + def remove_thumbnail? + record if owns? + end + def show? if user.nil? record.state == 'published' diff --git a/app/views/learning_objects/build/select_thumbnail.html.erb b/app/views/learning_objects/build/select_thumbnail.html.erb index a44be272a8435dc57695db5d75a98bb375b33e54..04f33baaa2cfc5cb387a92796eaa487fbdba0ae6 100644 --- a/app/views/learning_objects/build/select_thumbnail.html.erb +++ b/app/views/learning_objects/build/select_thumbnail.html.erb @@ -31,9 +31,24 @@ <%= form_for @learning_object, url: wizard_path, method: :put, html: { multipart: true } do |f| %> <%= f.file_field :thumbnail, required: true %> + <% unless @learning_object.thumbnail.blank? %> + <div>Thumbnail: <%= @learning_object.thumbnail_file_name %> <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 %> <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> + <%= link_to next_wizard_path do %> <button type="button" class="btn-submit btn btn-warning btn-outline-rounded yellow">Pular etapa</button> <% end %>