diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9f0492501532e0c1b47294aef88e01cad5ba1c6f..11c83322671ce450091f92ea95d6722a7d718dc6 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -28,7 +28,7 @@ $(document).ready(function () { }); $(function() { - return $(document).on('ajax:success', '.bookmark', function(status, data, xhr) { + return $(document).on('ajax:success', '.bookmark-btn', function(status, data, xhr) { if ( $(this).hasClass('btn-default') ) { $(this).removeClass('btn-default').addClass('btn-success'); $(this).data('method', 'delete'); diff --git a/app/assets/javascripts/application/learning_objects.coffee.erb b/app/assets/javascripts/application/learning_objects.coffee.erb index 5d95b36d89c6f6da782b686bca834366772f4a1b..f77e8aa2051ef476ec253007c02833ca7b7dcca4 100644 --- a/app/assets/javascripts/application/learning_objects.coffee.erb +++ b/app/assets/javascripts/application/learning_objects.coffee.erb @@ -9,3 +9,17 @@ $ -> $('.vote img').attr('alt', 'Descurtir').reload() return return + +bookmarks_btn = -> + $(document).on 'ajax:success', '.bookmark', (status, data, xhr) -> + if $('.fa-bookmark').attr('id') == 'bookmarked' + $('.fa-bookmark').attr('style', '') + $('.fa-bookmark').attr('id', 'not-bookmarked').reload() + $('.fa-bookmark').parent().data('method', 'post').reload() + else + $('.fa-bookmark').attr('style', 'color:#27ae60') + $('.fa-bookmark').attr('id', 'bookmarked').reload() + $('.fa-bookmark').parent().data('method', 'delete').reload() + return + +$(document).on('page:load', bookmarks_btn ) diff --git a/app/views/learning_objects/_bookmarks_button.html.erb b/app/views/learning_objects/_bookmarks_button.html.erb index 4dd838d73002665f3286ce5454786e5b4ee60f40..47f6c27f932124691f8adb72ae64514ecd9fb2fd 100644 --- a/app/views/learning_objects/_bookmarks_button.html.erb +++ b/app/views/learning_objects/_bookmarks_button.html.erb @@ -1,9 +1,9 @@ <% unless current_user.bookmark_learning_objects.include? learning_object %> - <%= link_to bookmark_add_path(id: learning_object.id, type: learning_object.class.to_s), class: 'bookmark btn btn-default btn-xs', title: "Adicionar aos favoritos", method: :post, remote: true do %> + <%= link_to bookmark_add_path(id: learning_object.id, type: learning_object.class.to_s), class: 'bookmark-btn btn btn-default btn-xs', title: "Adicionar aos favoritos", method: :post, remote: true do %> <i class="fa fa-bookmark" aria-hidden="true"></i> <% end %> <% else %> - <%= link_to bookmark_remove_path(id: learning_object.id, type: learning_object.class.to_s), class: 'bookmark btn btn-success btn-xs', title: "Remover dos favoritos",method: :delete, remote: true do %> + <%= link_to bookmark_remove_path(id: learning_object.id, type: learning_object.class.to_s), class: 'bookmark-btn btn btn-success btn-xs', title: "Remover dos favoritos",method: :delete, remote: true do %> <i class="fa fa-bookmark" aria-hidden="true"></i> <% end %> <% end %> diff --git a/app/views/learning_objects/show.html.erb b/app/views/learning_objects/show.html.erb index 2f944de25ae73feece470f290f832e3ff28e8ed8..c8b9e52eec4f55300e2d96865d0c9df8fe37adac 100644 --- a/app/views/learning_objects/show.html.erb +++ b/app/views/learning_objects/show.html.erb @@ -80,9 +80,16 @@ </a> </div> <div class="action"> - <%= link_to bookmark_add_path(id: @learning_object.id, type: @learning_object.class.to_s), class:"btn btn-primary bookmark", title: "Adicionar aos favoritos", method: :post, remote: true do %> - <i class="fa fa-bookmark"></i> - <%end%> + <% unless current_user.bookmark_learning_objects.include? @learning_object %> + <%= link_to bookmark_add_path(id: @learning_object.id, type: @learning_object.class.to_s), class: 'bookmark btn btn-default', title: "Adicionar aos favoritos", method: :post, remote: true do %> + <i id="not-bookmarked" class="fa fa-bookmark" aria-hidden="true" style=""></i> + <% end %> + <% else %> + <%= link_to bookmark_remove_path(id: @learning_object.id, type: @learning_object.class.to_s), class: 'bookmark btn btn-default', title: "Remover dos favoritos", method: :delete, remote: true do %> + <i id="bookmarked" class="fa fa-bookmark" aria-hidden="true" style="color:#27ae60"></i> + <% end %> + <% end %> + </div> <div class="action"> <%= render 'complaints/complaints_button' %>