Skip to content
Snippets Groups Projects
Commit f9b02f39 authored by Matheus Agio Nerone's avatar Matheus Agio Nerone
Browse files

now image change when liking or disliking

parent 62aa2796
No related branches found
No related tags found
No related merge requests found
$ ->
$('.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
...@@ -13,6 +13,7 @@ class LearningObjectsController < ApplicationController ...@@ -13,6 +13,7 @@ class LearningObjectsController < ApplicationController
# GET /learning_objects/1 # GET /learning_objects/1
# GET /learning_objects/1.json # GET /learning_objects/1.json
def show def show
@liked = learning_object_repository.liked?(current_user, @learning_object)
end end
# GET /learning_objects/new # GET /learning_objects/new
......
...@@ -62,7 +62,11 @@ ...@@ -62,7 +62,11 @@
<div class="actions"> <div class="actions">
<div class="col-md-3 action"> <div class="col-md-3 action">
<%= link_to like_learning_object_path(id: @learning_object.id), class: 'vote',method: :post, remote: true do %> <%= 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> <h6>curtir objeto</h6>
<% end %> <% end %>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment