added JS for following/unfollowing
This commit is contained in:
parent
81c4f14a62
commit
814a509f60
|
@ -72,7 +72,6 @@ $(document).on "click", "button[name=ib-answer]", ->
|
||||||
btn.button "reset"
|
btn.button "reset"
|
||||||
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"
|
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"
|
||||||
|
|
||||||
# TODO
|
|
||||||
$(document).on "click", "button[name=ab-destroy]", ->
|
$(document).on "click", "button[name=ab-destroy]", ->
|
||||||
btn = $(this)
|
btn = $(this)
|
||||||
btn.button "loading"
|
btn.button "loading"
|
||||||
|
@ -92,6 +91,49 @@ $(document).on "click", "button[name=ab-destroy]", ->
|
||||||
complete: (jqxhr, status) ->
|
complete: (jqxhr, status) ->
|
||||||
btn.button "reset"
|
btn.button "reset"
|
||||||
|
|
||||||
|
$(document).on "click", "button[name=user-action]", ->
|
||||||
|
btn = $(this)
|
||||||
|
btn.button "loading"
|
||||||
|
target = btn[0].dataset.target
|
||||||
|
action = btn[0].dataset.action
|
||||||
|
count = Number($("h4.entry-text#follower-count").html())
|
||||||
|
|
||||||
|
target_url = switch action
|
||||||
|
when 'follow'
|
||||||
|
count++
|
||||||
|
'/ajax/create_friend'
|
||||||
|
when 'unfollow'
|
||||||
|
count--
|
||||||
|
'/ajax/destroy_friend'
|
||||||
|
|
||||||
|
success = false
|
||||||
|
|
||||||
|
$.ajax
|
||||||
|
url: target_url
|
||||||
|
type: 'POST'
|
||||||
|
data:
|
||||||
|
screen_name: target
|
||||||
|
success: (data, status, jqxhr) ->
|
||||||
|
success = data.success
|
||||||
|
if data.success
|
||||||
|
$("h4.entry-text#follower-count").html(count)
|
||||||
|
showNotification data.message, data.success
|
||||||
|
error: (jqxhr, status, error) ->
|
||||||
|
console.log jqxhr, status, error
|
||||||
|
showNotification "An error occurred, a developer should check the console for details", false
|
||||||
|
complete: (jqxhr, status) ->
|
||||||
|
btn.button "reset"
|
||||||
|
if success
|
||||||
|
switch action
|
||||||
|
when 'follow'
|
||||||
|
btn[0].dataset.action = 'unfollow'
|
||||||
|
btn.attr 'class', 'btn btn-default btn-block'
|
||||||
|
btn.html 'Unfollow'
|
||||||
|
when 'unfollow'
|
||||||
|
btn[0].dataset.action = 'follow'
|
||||||
|
btn.attr 'class', 'btn btn-primary btn-block'
|
||||||
|
btn.html 'Follow'
|
||||||
|
|
||||||
$(document).on "click", "button#create-account", ->
|
$(document).on "click", "button#create-account", ->
|
||||||
Turbolinks.visit "/sign_up"
|
Turbolinks.visit "/sign_up"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue