gitlab-org--gitlab-foss/app/assets/javascripts/todos.js.coffee

67 lines
1.5 KiB
CoffeeScript
Raw Normal View History

class @Todos
constructor: (@name) ->
@clearListeners()
@initBtnListeners()
clearListeners: ->
$('.done-todo').off('click')
2016-03-17 13:08:59 +00:00
$('.js-todos-mark-all').off('click')
2016-03-30 17:28:36 +00:00
$('.todo').off('click')
initBtnListeners: ->
$('.done-todo').on('click', @doneClicked)
2016-03-17 13:08:59 +00:00
$('.js-todos-mark-all').on('click', @allDoneClicked)
2016-03-30 14:17:03 +00:00
$('.todo').on('click', @goToTodoUrl)
doneClicked: (e) =>
e.preventDefault()
e.stopImmediatePropagation()
$this = $(e.currentTarget)
$this.disable()
$.ajax
type: 'POST'
url: $this.attr('href')
dataType: 'json'
data: '_method': 'delete'
success: (data) =>
2016-03-17 13:08:59 +00:00
@clearDone $this.closest('li')
@updateBadges data
2016-03-17 13:08:59 +00:00
allDoneClicked: (e) =>
e.preventDefault()
e.stopImmediatePropagation()
$this = $(e.currentTarget)
$this.disable()
$.ajax
type: 'POST'
url: $this.attr('href')
dataType: 'json'
data: '_method': 'delete'
success: (data) =>
$this.remove()
$('.js-todos-list').remove()
@updateBadges data
clearDone: ($row) ->
$ul = $row.closest('ul')
$row.remove()
if not $ul.find('li').length
$ul.parents('.panel').remove()
2016-03-17 13:08:59 +00:00
updateBadges: (data) ->
$('.todos-pending .badge, .todos-pending-count').text data.count
$('.todos-done .badge').text data.done_count
2016-03-30 14:17:03 +00:00
2016-04-08 16:46:32 +00:00
goToTodoUrl: (e)->
todoLink = $(this).data('url')
if e.metaKey
e.preventDefault()
window.open(todoLink,'_blank')
else
Turbolinks.visit(todoLink)