Retrospring/app/javascript/legacy/lists.coffee

91 lines
2.6 KiB
CoffeeScript
Raw Normal View History

($ document).on "click", "input[type=checkbox][name=gm-list-check]", ->
box = $(this)
box.attr 'disabled', 'disabled'
listName = box[0].dataset.list
count = Number ($ "span##{listName}-members").html()
boxChecked = box[0].checked
count += if boxChecked then 1 else -1
$.ajax
url: '/ajax/list_membership'
type: 'POST'
data:
user: box[0].dataset.user
list: listName
add: boxChecked
success: (data, status, jqxhr) ->
if data.success
box[0].checked = if data.checked? then data.checked else !boxChecked
($ "span##{listName}-members").html(count)
showNotification data.message, data.success
error: (jqxhr, status, error) ->
box[0].checked = false
console.log jqxhr, status, error
2015-06-08 11:35:16 -07:00
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->
2015-01-17 09:24:36 -08:00
box.removeAttr "disabled"
$(document).on "keyup", "input#new-list-name", (evt) ->
2015-01-17 09:24:36 -08:00
if evt.which == 13 # return key
evt.preventDefault()
$("button#create-list").trigger 'click'
2015-01-17 09:24:36 -08:00
($ document).on "click", "button#create-list", ->
2015-01-17 09:24:36 -08:00
btn = $(this)
btn.button "loading"
input = ($ "input#new-list-name")
2015-01-17 09:24:36 -08:00
$.ajax
url: '/ajax/create_list'
2015-01-17 09:24:36 -08:00
type: 'POST'
data:
name: input.val()
user: btn[0].dataset.user
dataType: 'json'
success: (data, status, jqxhr) ->
if data.success
($ "#lists-list ul.list-group").append(data.render)
2015-01-17 09:24:36 -08:00
input.val ''
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
2015-01-17 09:24:36 -08:00
complete: (jqxhr, status) ->
btn.button "reset"
2015-01-17 09:57:23 -08:00
($ document).on "click", "a#delete-list", (ev) ->
2015-01-17 09:57:23 -08:00
ev.preventDefault()
btn = $(this)
list = btn[0].dataset.list
2015-01-17 09:57:23 -08:00
swal
title: translate('frontend.list.title')
text: translate('frontend.list.text')
2015-01-17 09:57:23 -08:00
type: "warning"
showCancelButton: true
confirmButtonColor: "#DD6B55"
2015-06-08 11:35:16 -07:00
confirmButtonText: translate('views.actions.delete')
cancelButtonText: translate('views.actions.cancel')
2015-01-17 09:57:23 -08:00
closeOnConfirm: true
, ->
$.ajax
url: '/ajax/destroy_list'
2015-01-17 09:57:23 -08:00
type: 'POST'
data:
list: list
2015-01-17 09:57:23 -08:00
dataType: 'json'
success: (data, status, jqxhr) ->
if data.success
($ "li.list-group-item#list-#{list}").slideUp()
2015-01-17 09:57:23 -08:00
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
2015-01-17 09:57:23 -08:00
complete: (jqxhr, status) ->