diff --git a/app/assets/javascripts/application/learning_objects.coffee.erb b/app/assets/javascripts/application/learning_objects.coffee.erb new file mode 100644 index 0000000000000000000000000000000000000000..20f241eb01d6f2286d00cbeb2112df8db2015044 --- /dev/null +++ b/app/assets/javascripts/application/learning_objects.coffee.erb @@ -0,0 +1,55 @@ +$ -> + $('.default_btn').toggleClass 'active_btn' + $(document).on 'click', '*[data-poload]', -> + e = $(this) + e.popover({content: "Carregando..."}).popover('show') + all = undefined + objects = undefined + url = $(this).data('poload') + loid = $(this).data('loid') + $.get '/collections.json', (d) -> + all = d + $.get url, (d) -> + object = d + + # generate a lookup table for object's collections id + lookup = {} + i = 0 + len = object.length + while i < len + lookup[object[i].id] = object[i] + i++ + + # mark checked objects + i = 0 + len = all.length + html = '' + while i < len + name = 'collection_' + all[i].id.split(':').slice(-1)[0] + html += '<input type="checkbox" class="collection-element" data-cid="' + all[i].id + '" data-loid="' + loid + '" id="' + name + '" value="' + all[i].id + '"' + if lookup[all[i].id] != undefined + html += " checked" + html += '>' + html += '<label for="' + name + '">' + all[i].name + '</label><br/>' + ++i + + $('.popover-content').html(html) + return + return + return + +$ -> + $(document).on 'click', '.add_to_collection', (e) -> + $('.add_to_collection').removeClass 'active' + $('.add_to_collection').not(this).popover 'hide' + return +$ -> + $(document).on 'ajax:success', 'a.vote', (status, data, xhr) -> + $('.votes-count[data-id=\'' + data.id + '\']').text data.count + if $('.vote img').attr('alt') == 'Descurtir' + $('.vote img').attr('src',"<%= image_path('icons/Curtir_01.png') %>") + $('.vote img').attr('alt', 'Curtir') + else + $('.vote img').attr('src',"<%= image_path('icons/Curtir_02.png') %>") + $('.vote img').attr('alt', 'Descurtir') + return diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index f2288acb2cf378597270251ed189ffa6d6213261..b2e41624b7bcaa2b7aee9a4ff7787931901e406e 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -13,6 +13,7 @@ class LearningObjectsController < ApplicationController # GET /learning_objects/1 # GET /learning_objects/1.json def show + @liked = learning_object_repository.liked?(current_user, @learning_object) end # GET /learning_objects/new diff --git a/app/views/learning_objects/show.html.erb b/app/views/learning_objects/show.html.erb index ee0f8edcf10ba9c47b9670b1a0730b72632fd55f..07cf7741a65dd978dfccffbf7c136c8c89ff32bb 100644 --- a/app/views/learning_objects/show.html.erb +++ b/app/views/learning_objects/show.html.erb @@ -62,7 +62,11 @@ <div class="actions"> <div class="col-md-3 action"> <%= link_to like_learning_object_path(id: @learning_object.id), class: 'vote',method: :post, remote: true do %> - <%= image_tag "icons/Curtir_01.png", alt: "Curtir" %> + <% if @liked %> + <%= image_tag "icons/Curtir_02.png", alt: "Descurtir" %> + <% else %> + <%= image_tag "icons/Curtir_01.png", alt: "Curtir" %> + <% end %> <h6>curtir objeto</h6> <% end %> </div>