Retrospring/app/assets/javascripts/moderation/ban.coffee

70 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2015-05-11 00:01:48 -07:00
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"]')
2015-05-11 00:01:48 -07:00
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()
untilInput = $ modalForm.elements["until"]
untilInput.datetimepicker
defaultDate: untilInput.val()
2015-04-23 12:21:58 -07:00
sideBySide: true
2015-04-23 12:07:39 -07:00
icons:
time: "fa fa-clock-o"
date: "fa fa-calendar"
up: "fa fa-chevron-up"
down: "fa fa-chevron-down"
previous: "fa fa-chevron-left"
next: "fa fa-chevron-right"
today: "fa fa-home"
clear: "fa fa-trash-o"
close: "fa fa-times"
modalForm.addEventListener "submit", (event) ->
event.preventDefault();
checktostr = (el) ->
if el.checked
"1"
else
"0"
data = {
ban: checktostr banCheckbox
permaban: checktostr permabanCheckbox
until: modalForm.elements["until"].value.trim()
reason: modalForm.elements["reason"].value.trim()
user: modalForm.elements["user"].value
}
$.ajax
url: '/ajax/mod/ban'
type: 'POST'
data: data
success: (data, status, jqxhr) ->
showNotification data.message, data.success
error: (jqxhr, status, error) ->
console.log jqxhr, status, error
2015-06-08 11:35:16 -07:00
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->
2015-05-11 00:01:48 -07:00
$(document).on "DOMContentLoaded", ->
load()
$(document).on "page:load", ->
load()