diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index 23500eb811a4c13a2e33762ffd27dac67116a8de..ef7b7e9a6504632565768a37264f6a727a22f863 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 %> diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 83f6a8e69ea3846fcbd2d028f3a9acdd23fb4d70..c2a4aceb0c2a881e04b770d240f086f03d81600c 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -137,6 +137,7 @@ pt-BR: object_type: "Tipo do objeto" language: "Idioma" author: "Autor" + topics: "Assunto" create: notice: failure: "Não foi possÃvel criar o objeto." diff --git a/config/routes.rb b/config/routes.rb index 97360dff80f42298d301109f7a26d3e02552af96..21a8b208e12d38ba879a65d986314ec23166ac90 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,6 +72,7 @@ Rails.application.routes.draw do end post 'learning_objects/:id/remove_file/:attachment_id' => 'learning_objects#destroy_attachment', as: 'remove_file' + post 'learning_objects/:id/remove_thumbnail', to: 'learning_objects#remove_thumbnail', as: 'remove_thumbnail' resources :learning_objects do resources :build, controller: 'learning_objects/build' get :reviews, to: 'reviews#list', as: 'reviews'