fa570525db
Fixes #13656 A good first step and boring solution.
48 lines
No EOL
1.3 KiB
CoffeeScript
48 lines
No EOL
1.3 KiB
CoffeeScript
class @Todos
|
|
_this = null;
|
|
constructor: (@name) ->
|
|
_this = @
|
|
@initBtnListeners()
|
|
|
|
initBtnListeners: ->
|
|
$('.done-todo').on('click', @doneClicked)
|
|
|
|
doneClicked: (e) ->
|
|
$this = $(this)
|
|
doneURL = $this.attr('href')
|
|
e.preventDefault()
|
|
e.stopImmediatePropagation()
|
|
$spinner = $('<i></i>').addClass('fa fa-spinner fa-spin')
|
|
$this.addClass("disabled")
|
|
$this.append($spinner)
|
|
$.ajax
|
|
type: 'POST'
|
|
url: doneURL
|
|
dataType: 'json'
|
|
data: '_method': 'delete'
|
|
error: (data, textStatus, jqXHR) ->
|
|
new Flash('Unable to update your todos.', 'alert')
|
|
_this.clearDone($this.closest('li'))
|
|
return
|
|
|
|
success: (data, textStatus, jqXHR) ->
|
|
new Flash(data.notice, 'success')
|
|
_this.clearDone($this.closest('li'))
|
|
return
|
|
|
|
clearDone: ($row) ->
|
|
$ul = $row.closest('ul')
|
|
$row.remove()
|
|
if not $ul.find('li').length
|
|
Turbolinks.visit(location.href)
|
|
else
|
|
$pendingBadge = $('.todos-pending .badge')
|
|
$pendingBadge.text parseInt($pendingBadge.text()) - 1
|
|
|
|
$doneBadge = $('.todos-done .badge')
|
|
$doneBadge.text parseInt($doneBadge.text()) + 1
|
|
|
|
$mainTodosPendingBadge = $('.todos-pending-count')
|
|
$mainTodosPendingBadge.text parseInt($mainTodosPendingBadge.text()) - 1
|
|
return
|
|
|