From ba6fa06877b72dee6840f2bdba934185c6577e59 Mon Sep 17 00:00:00 2001 From: Giovanne Marcelo <gms15@inf.ufpr.br> Date: Thu, 24 Mar 2016 16:36:13 -0300 Subject: [PATCH] Fixing bookmarks button in learning object show --- app/assets/javascripts/application.js | 2 +- .../application/learning_objects.coffee.erb | 14 ++++++++++++++ .../learning_objects/_bookmarks_button.html.erb | 4 ++-- app/views/learning_objects/show.html.erb | 13 ++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9f0492501..11c833226 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 5d95b36d8..f77e8aa20 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 4dd838d73..47f6c27f9 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 2f944de25..c8b9e52ee 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' %> -- GitLab