Remove legacy answerbox CoffeeScript
This commit is contained in:
parent
077e9df2a6
commit
723ebfb823
|
@ -1,68 +0,0 @@
|
||||||
# Toggle button
|
|
||||||
$(document).on "click", "button[name=ab-comments]", ->
|
|
||||||
btn = $(this)
|
|
||||||
aid = btn[0].dataset.aId
|
|
||||||
state = btn[0].dataset.state
|
|
||||||
commentBox = $("#ab-comments-section-#{aid}")
|
|
||||||
|
|
||||||
switch state
|
|
||||||
when 'hidden'
|
|
||||||
commentBox.slideDown()
|
|
||||||
btn[0].dataset.state = 'shown'
|
|
||||||
when 'shown'
|
|
||||||
commentBox.slideUp()
|
|
||||||
btn[0].dataset.state = 'hidden'
|
|
||||||
|
|
||||||
|
|
||||||
$(document).on "keyup", "input[name=ab-comment-new]", (evt) ->
|
|
||||||
input = $(this)
|
|
||||||
aid = input[0].dataset.aId
|
|
||||||
ctr = $("span#ab-comment-charcount-#{aid}")
|
|
||||||
cbox = $("div[name=ab-comment-new-group][data-a-id=#{aid}]")
|
|
||||||
|
|
||||||
if evt.which == 13 # return key
|
|
||||||
evt.preventDefault()
|
|
||||||
return cbox.addClass "has-error" if input.val().length > 160 || input.val().trim().length == 0
|
|
||||||
input.attr 'disabled', 'disabled'
|
|
||||||
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/create_comment'
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
answer: aid
|
|
||||||
comment: input.val()
|
|
||||||
dataType: 'json' # jQuery can't guess the datatype correctly here...
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
console.log data
|
|
||||||
if data.success
|
|
||||||
$("#ab-comments-#{aid}").html data.render
|
|
||||||
input.val ''
|
|
||||||
ctr.html 160
|
|
||||||
$("span#ab-comment-count-#{aid}").html data.count
|
|
||||||
subs = $("a[data-action=ab-submarine][data-a-id=#{aid}]")[0]
|
|
||||||
subs.dataset.torpedo = "no"
|
|
||||||
subs.children[0].nextSibling.textContent = translate('views.actions.unsubscribe')
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification translate('frontend.error.message'), false
|
|
||||||
complete: (jqxhr, status) ->
|
|
||||||
input.removeAttr 'disabled'
|
|
||||||
|
|
||||||
|
|
||||||
# character count
|
|
||||||
$(document).on "input", "input[name=ab-comment-new]", (evt) ->
|
|
||||||
input = $(this)
|
|
||||||
aid = input[0].dataset.aId
|
|
||||||
ctr = $("span#ab-comment-charcount-#{aid}")
|
|
||||||
|
|
||||||
cbox = $("div[name=ab-comment-new-group][data-a-id=#{aid}]")
|
|
||||||
cbox.removeClass "has-error" if cbox.hasClass "has-error"
|
|
||||||
|
|
||||||
ctr.html 160 - input.val().length
|
|
||||||
if Number(ctr.html()) < 0
|
|
||||||
ctr.removeClass 'text-muted'
|
|
||||||
ctr.addClass 'text-danger'
|
|
||||||
else
|
|
||||||
ctr.removeClass 'text-danger'
|
|
||||||
ctr.addClass 'text-muted'
|
|
|
@ -1,27 +0,0 @@
|
||||||
$(document).on "click", "a[data-action=ab-comment-destroy]", (ev) ->
|
|
||||||
ev.preventDefault()
|
|
||||||
btn = $(this)
|
|
||||||
cid = btn[0].dataset.cId
|
|
||||||
swal
|
|
||||||
title: translate('frontend.destroy_comment.confirm.title')
|
|
||||||
text: translate('frontend.destroy_comment.confirm.text')
|
|
||||||
type: "warning"
|
|
||||||
showCancelButton: true
|
|
||||||
confirmButtonColor: "#DD6B55"
|
|
||||||
confirmButtonText: translate('views.actions.delete')
|
|
||||||
cancelButtonText: translate('views.actions.cancel')
|
|
||||||
closeOnConfirm: true
|
|
||||||
, ->
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/destroy_comment'
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
comment: cid
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
if data.success
|
|
||||||
$("li[data-comment-id=#{cid}]").slideUp()
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification translate('frontend.error.message'), false
|
|
||||||
complete: (jqxhr, status) ->
|
|
|
@ -1,5 +0,0 @@
|
||||||
$(document).on "click", "a[data-action=ab-comment-report]", (ev) ->
|
|
||||||
ev.preventDefault()
|
|
||||||
btn = $(this)
|
|
||||||
cid = btn[0].dataset.cId
|
|
||||||
reportDialog "comment", cid, -> btn.button "reset"
|
|
|
@ -1,43 +0,0 @@
|
||||||
$(document).on "click", "button[name=ab-smile-comment]", ->
|
|
||||||
btn = $(this)
|
|
||||||
cid = btn[0].dataset.cId
|
|
||||||
action = btn[0].dataset.action
|
|
||||||
count = Number $("span#ab-comment-smile-count-#{cid}").html()
|
|
||||||
btn[0].dataset.loadingText = "<i class=\"fa fa-fw fa-meh-o fa-spin\"></i> <span id=\"ab-smile-count-#{cid}\">#{count}</span>"
|
|
||||||
btn.button "loading"
|
|
||||||
|
|
||||||
target_url = switch action
|
|
||||||
when 'smile'
|
|
||||||
count++
|
|
||||||
'/ajax/create_comment_smile'
|
|
||||||
when 'unsmile'
|
|
||||||
count--
|
|
||||||
'/ajax/destroy_comment_smile'
|
|
||||||
|
|
||||||
success = false
|
|
||||||
|
|
||||||
$.ajax
|
|
||||||
url: target_url
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
id: cid
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
success = data.success
|
|
||||||
if success
|
|
||||||
$("span#ab-comment-smile-count-#{cid}").html(count)
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification translate('frontend.error.message'), false
|
|
||||||
complete: (jqxhr, status) ->
|
|
||||||
btn.button "reset"
|
|
||||||
window.setTimeout ->
|
|
||||||
if success
|
|
||||||
switch action
|
|
||||||
when 'smile'
|
|
||||||
btn[0].dataset.action = 'unsmile'
|
|
||||||
btn.html "<i class=\"fa fa-fw fa-frown-o\"></i> <span id=\"ab-comment-smile-count-#{cid}\">#{count}</span>"
|
|
||||||
when 'unsmile'
|
|
||||||
btn[0].dataset.action = 'smile'
|
|
||||||
btn.html "<i class=\"fa fa-fw fa-smile-o\"></i> <span id=\"ab-comment-smile-count-#{cid}\">#{count}</span>"
|
|
||||||
, 20
|
|
|
@ -1,27 +0,0 @@
|
||||||
$(document).on "click", "a[data-action=ab-destroy]", (ev) ->
|
|
||||||
ev.preventDefault()
|
|
||||||
btn = $(this)
|
|
||||||
aid = btn[0].dataset.aId
|
|
||||||
swal
|
|
||||||
title: translate('frontend.destroy_question.confirm.title')
|
|
||||||
text: translate('frontend.destroy_question.confirm.text')
|
|
||||||
type: "warning"
|
|
||||||
showCancelButton: true
|
|
||||||
confirmButtonColor: "#DD6B55"
|
|
||||||
confirmButtonText: translate('views.actions.y')
|
|
||||||
cancelButtonText: translate('views.actions.n')
|
|
||||||
closeOnConfirm: true
|
|
||||||
, ->
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/destroy_answer' # TODO: find a way to use rake routes instead of hardcoding them here
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
answer: aid
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
if data.success
|
|
||||||
$("div.answerbox[data-id=#{aid}]").slideUp()
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification translate('frontend.error.message'), false
|
|
||||||
complete: (jqxhr, status) ->
|
|
|
@ -1,8 +0,0 @@
|
||||||
import './comment/destroy'
|
|
||||||
import './comment/report'
|
|
||||||
import './comment/smile'
|
|
||||||
import './comment'
|
|
||||||
import './destroy'
|
|
||||||
import './report'
|
|
||||||
import './smile'
|
|
||||||
import './subscribe'
|
|
|
@ -1,5 +0,0 @@
|
||||||
$(document).on "click", "a[data-action=ab-report]", (ev) ->
|
|
||||||
ev.preventDefault()
|
|
||||||
btn = $(this)
|
|
||||||
aid = btn[0].dataset.aId
|
|
||||||
reportDialog "answer", aid, -> btn.button "reset"
|
|
|
@ -1,43 +0,0 @@
|
||||||
$(document).on "click", "button[name=ab-smile]", ->
|
|
||||||
btn = $(this)
|
|
||||||
aid = btn[0].dataset.aId
|
|
||||||
action = btn[0].dataset.action
|
|
||||||
count = Number $("span#ab-smile-count-#{aid}").html()
|
|
||||||
btn[0].dataset.loadingText = "<i class=\"fa fa-fw fa-meh-o fa-spin\"></i> <span id=\"ab-smile-count-#{aid}\">#{count}</span>"
|
|
||||||
btn.button "loading"
|
|
||||||
|
|
||||||
target_url = switch action
|
|
||||||
when 'smile'
|
|
||||||
count++
|
|
||||||
'/ajax/create_smile'
|
|
||||||
when 'unsmile'
|
|
||||||
count--
|
|
||||||
'/ajax/destroy_smile'
|
|
||||||
|
|
||||||
success = false
|
|
||||||
|
|
||||||
$.ajax
|
|
||||||
url: target_url
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
id: aid
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
success = data.success
|
|
||||||
if success
|
|
||||||
$("span#ab-smile-count-#{aid}").html(count)
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification translate('frontend.error.message'), false
|
|
||||||
complete: (jqxhr, status) ->
|
|
||||||
btn.button "reset"
|
|
||||||
window.setTimeout ->
|
|
||||||
if success
|
|
||||||
switch action
|
|
||||||
when 'smile'
|
|
||||||
btn[0].dataset.action = 'unsmile'
|
|
||||||
btn.html "<i class=\"fa fa-fw fa-frown-o\"></i> <span id=\"ab-smile-count-#{aid}\">#{count}</span>"
|
|
||||||
when 'unsmile'
|
|
||||||
btn[0].dataset.action = 'smile'
|
|
||||||
btn.html "<i class=\"fa fa-fw fa-smile-o\"></i> <span id=\"ab-smile-count-#{aid}\">#{count}</span>"
|
|
||||||
, 20
|
|
|
@ -1,28 +0,0 @@
|
||||||
# the laziest coding known to man
|
|
||||||
# TODO: so lazy, I don't know how to localize it properly
|
|
||||||
$(document).on "click", "a[data-action=ab-submarine]", (ev) ->
|
|
||||||
ev.preventDefault()
|
|
||||||
btn = $(this)
|
|
||||||
aid = btn[0].dataset.aId
|
|
||||||
torpedo = 0
|
|
||||||
if btn[0].dataset.torpedo == "yes"
|
|
||||||
torpedo = 1
|
|
||||||
|
|
||||||
endpoint = "subscribe"
|
|
||||||
if torpedo == 0
|
|
||||||
endpoint = "un" + endpoint
|
|
||||||
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/' + endpoint # TODO: find a way to use rake routes instead of hardcoding them here
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
answer: aid
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
if data.success
|
|
||||||
btn[0].dataset.torpedo = ["yes", "no"][torpedo]
|
|
||||||
btn[0].children[0].nextSibling.textContent = if torpedo then translate("views.actions.unsubscribe") else translate("views.actions.subscribe")
|
|
||||||
showNotification translate("frontend.subscription.#{endpoint}"), true
|
|
||||||
else
|
|
||||||
showNotification translate("frontend.subscription.fail.#{endpoint}"), false
|
|
||||||
error: showNotificationXHRError
|
|
||||||
complete: (jqxhr, status) ->
|
|
|
@ -17,7 +17,6 @@ require('sweetalert/dist/sweetalert.css')
|
||||||
# this file is generated by Rails
|
# this file is generated by Rails
|
||||||
import I18n from '../legacy/i18n'
|
import I18n from '../legacy/i18n'
|
||||||
|
|
||||||
import '../legacy/answerbox'
|
|
||||||
import '../legacy/memes'
|
import '../legacy/memes'
|
||||||
import '../legacy/notifications'
|
import '../legacy/notifications'
|
||||||
import '../legacy/pagination'
|
import '../legacy/pagination'
|
||||||
|
|
Loading…
Reference in New Issue