this fucker finally works how I want it to
This commit is contained in:
parent
7a0b3f4af7
commit
486d5d18f2
|
@ -28,16 +28,19 @@
|
|||
console.log jqxhr, status, error
|
||||
showNotification "An error occurred, a developer should check the console for details", false
|
||||
complete: (jqxhr, status) ->
|
||||
btn.removeAttr 'disabled'
|
||||
if success
|
||||
switch action
|
||||
when 'vote'
|
||||
btn.attr 'disabled', 'disabled'
|
||||
btn[0].dataset.action = 'unvote'
|
||||
other_btn = ($ "button[name=mod-vote][data-id=#{id}][data-action=vote]")
|
||||
other_btn.attr 'disabled', 'disabled'
|
||||
console.log("vote for #{upvote ? 'downvote' : 'upvote'}")
|
||||
other_btn = $ "button[name=mod-vote][data-id=#{id}][data-vote-type=#{if upvote then 'downvote' else 'upvote'}]"
|
||||
other_btn.removeAttr 'disabled'
|
||||
other_btn[0].dataset.action = 'unvote'
|
||||
when 'unvote'
|
||||
btn.removeAttr 'disabled'
|
||||
btn[0].dataset.action = 'vote'
|
||||
other_btn = ($ "button[name=mod-vote][data-id=#{id}][data-action=unvote]")
|
||||
other_btn.removeAttr 'disabled'
|
||||
console.log("vote for #{upvote ? 'downvote' : 'upvote'}")
|
||||
other_btn = $ "button[name=mod-vote][data-id=#{id}][data-vote-type=#{if upvote then 'downvote' else 'upvote'}]"
|
||||
other_btn.removeAttr 'disabled', 'disabled'
|
||||
other_btn[0].dataset.action = 'vote'
|
|
@ -139,4 +139,11 @@ class User < ActiveRecord::Base
|
|||
report.moderation_votes.each { |s| return true if s.user_id == self.id }
|
||||
false
|
||||
end
|
||||
|
||||
# @param upvote [Boolean]
|
||||
def report_x_voted?(report, upvote)
|
||||
return false unless mod?
|
||||
report.moderation_votes.where(upvote: upvote).each { |s| return true if s.user_id == self.id }
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
%span.mod-count{id: "mod-count-#{report.id}"}
|
||||
= report.votes
|
||||
.btn-group
|
||||
%button.btn.btn-success.btn-sm{name: "mod-vote", disabled: current_user.report_voted?(report) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'upvote' }}
|
||||
%button.btn.btn-success.btn-sm{name: "mod-vote", disabled: current_user.report_x_voted?(report, true) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'upvote' }}
|
||||
%i.fa.fa-thumbs-up
|
||||
%button.btn.btn-danger.btn-sm{name: "mod-vote", disabled: current_user.report_voted?(report) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'downvote' }}
|
||||
%button.btn.btn-danger.btn-sm{name: "mod-vote", disabled: current_user.report_x_voted?(report, false) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'downvote' }}
|
||||
%i.fa.fa-thumbs-down
|
||||
%button.btn.btn-primary.btn-sm
|
||||
%i.fa.fa-comments
|
||||
|
|
Loading…
Reference in New Issue