Remove legacy moderation CoffeeScript

This commit is contained in:
Andreas Nedbal 2022-01-08 02:56:27 +01:00 committed by Andreas Nedbal
parent ede117fe18
commit 630e2847c2
6 changed files with 0 additions and 251 deletions

View File

@ -1,54 +0,0 @@
load = ->
return unless document.getElementById('ban-control-super') != null
modalEl = $("#modal-ban")
modalEl.modal "hide"
modalForm = modalEl.find("form")[0]
banCheckbox = modalForm.querySelector('[name="ban"][type="checkbox"]')
permabanCheckbox = modalForm.querySelector('[name="permaban"][type="checkbox"]')
if banCheckbox
banCheckbox.addEventListener "change", (event) ->
$t = $ this
if $t.is(":checked")
$("#ban-controls").show()
else
$("#ban-controls").hide()
permabanCheckbox.addEventListener "change", (event) ->
$t = $ this
if $t.is(":checked")
$("#ban-controls-time").hide()
else
$("#ban-controls-time").show()
modalForm.addEventListener "submit", (event) ->
event.preventDefault();
data = {
ban: "0"
user: modalForm.elements["user"].value
}
if banCheckbox && banCheckbox.checked
data.ban = "1"
data.reason = modalForm.elements["reason"].value.trim()
unless permabanCheckbox.checked
data.duration = modalForm.elements["duration"].value.trim()
data.duration_unit = modalForm.elements["duration_unit"].value.trim()
$.ajax
url: '/ajax/mod/ban'
type: 'POST'
data: data
success: (data, status, jqxhr) ->
showNotification data.message, data.success
error: (jqxhr, status, error) ->
console.error 'request failed', data
console.log jqxhr, status, error
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->
$(document).on "DOMContentLoaded", ->
load()
$(document).on "page:load", ->
load()

View File

@ -1,95 +0,0 @@
# Toggle button
$(document).on "click", "button[name=mod-comments]", ->
btn = $(this)
id = btn[0].dataset.id
state = btn[0].dataset.state
commentBox = $("#mod-comments-section-#{id}")
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=mod-comment-new]", (evt) ->
input = $(this)
id = input[0].dataset.id
ctr = $("span#mod-comment-charcount-#{id}")
cbox = $("div[name=mod-comment-new-group][data-id=#{id}]")
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/mod/create_comment'
type: 'POST'
data:
id: id
comment: input.val()
dataType: 'json' # jQuery can't guess the datatype correctly here...
success: (data, status, jqxhr) ->
console.log data
if data.success
$("#mod-comments-#{id}").html data.render
input.val ''
ctr.html 160
$("span#mod-comment-count-#{id}").html data.count
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=mod-comment-new]", (evt) ->
input = $(this)
id = input[0].dataset.id
ctr = $("span#mod-comment-charcount-#{id}")
cbox = $("div[name=mod-comment-new-group][data-id=#{id}]")
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'
# destroy
$(document).on "click", "a[data-action=mod-comment-destroy]", (ev) ->
ev.preventDefault()
btn = $(this)
cid = btn[0].dataset.id
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/mod/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) ->

View File

@ -1,26 +0,0 @@
$(document).on "click", "button[name=mod-delete-report]", ->
btn = $(this)
id = btn[0].dataset.id
swal
title: translate('frontend.destroy_report.confirm.title')
text: translate('frontend.destroy_report.confirm.text')
type: "warning"
showCancelButton: true
confirmButtonColor: "#DD6B55"
confirmButtonText: translate('views.actions.delete')
cancelButtonText: translate('views.actions.cancel')
closeOnConfirm: true
, ->
$.ajax
url: '/ajax/mod/destroy_report'
type: 'POST'
data:
id: id
success: (data, status, jqxhr) ->
if data.success
$("div.moderationbox[data-id=#{id}]").slideUp()
showNotification data.message, data.success
error: (jqxhr, status, error) ->
console.log jqxhr, status, error
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->

View File

@ -1,24 +0,0 @@
($ document).on "click", "input[type=checkbox][name=check-your-privileges]", ->
box = $(this)
box.attr 'disabled', 'disabled'
privType = box[0].dataset.type
boxChecked = box[0].checked
$.ajax
url: '/ajax/mod/privilege'
type: 'POST'
data:
user: box[0].dataset.user
type: privType
status: boxChecked
success: (data, status, jqxhr) ->
if data.success
box[0].checked = if data.checked? then data.checked else !boxChecked
showNotification data.message, data.success
error: (jqxhr, status, error) ->
box[0].checked = false
console.log jqxhr, status, error
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->
box.removeAttr "disabled"

View File

@ -1,46 +0,0 @@
($ document).on "click", "button[name=mod-vote]", ->
btn = $(this)
id = btn[0].dataset.id
action = btn[0].dataset.action
upvote = btn[0].dataset.voteType == 'upvote'
btn.attr 'disabled', 'disabled'
target_url = switch action
when 'vote'
'/ajax/mod/create_vote'
when 'unvote'
'/ajax/mod/destroy_vote'
success = false
$.ajax
url: target_url
type: 'POST'
data:
id: id
upvote: upvote
success: (data, status, jqxhr) ->
success = data.success
if success
($ "span#mod-count-#{id}").html(data.count)
showNotification data.message, data.success
error: (jqxhr, status, error) ->
console.log jqxhr, status, error
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->
if success
switch action
when 'vote'
btn.attr 'disabled', 'disabled'
btn[0].dataset.action = 'unvote'
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'
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'

View File

@ -2,10 +2,4 @@ import 'tempusdominus-bootstrap-4'
require('tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.css')
import '../legacy/moderation/ban'
import '../legacy/moderation/comment'
import '../legacy/moderation/destroy'
import '../legacy/moderation/privileges'
import '../legacy/moderation/vote'
$('.datetimepicker-input').datetimepicker({})