Commit 41c107be authored by Phil Hughes's avatar Phil Hughes

Mark all as done through AJAX

parent 421215e3
...@@ -5,9 +5,11 @@ class @Todos ...@@ -5,9 +5,11 @@ class @Todos
clearListeners: -> clearListeners: ->
$('.done-todo').off('click') $('.done-todo').off('click')
$('.js-todos-mark-all').off('click')
initBtnListeners: -> initBtnListeners: ->
$('.done-todo').on('click', @doneClicked) $('.done-todo').on('click', @doneClicked)
$('.js-todos-mark-all').on('click', @allDoneClicked)
doneClicked: (e) => doneClicked: (e) =>
e.preventDefault() e.preventDefault()
...@@ -22,14 +24,33 @@ class @Todos ...@@ -22,14 +24,33 @@ class @Todos
dataType: 'json' dataType: 'json'
data: '_method': 'delete' data: '_method': 'delete'
success: (data) => success: (data) =>
@clearDone $this.closest('li'), data @clearDone $this.closest('li')
@updateBadges data
clearDone: ($row, data) -> 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') $ul = $row.closest('ul')
$row.remove() $row.remove()
$('.todos-pending .badge, .todos-pending-count').text data.count
$('.todos-done .badge').text data.done_count
if not $ul.find('li').length if not $ul.find('li').length
$ul.parents('.panel').remove() $ul.parents('.panel').remove()
updateBadges: (data) ->
$('.todos-pending .badge, .todos-pending-count').text data.count
$('.todos-done .badge').text data.done_count
...@@ -25,6 +25,10 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -25,6 +25,10 @@ class Dashboard::TodosController < Dashboard::ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' } format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
format.js { render nothing: true } format.js { render nothing: true }
format.json do
find_todos
render json: { count: @todos.size, done_count: current_user.todos.done.count }
end
end end
end end
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
- if todo.pending? - if todo.pending?
.todo-actions.pull-right .todo-actions.pull-right
= link_to [:dashboard, todo], method: :delete, class: 'btn btn-loading done-todo' do = link_to [:dashboard, todo], method: :delete, class: 'btn btn-loading done-todo' do
= icon('spinner spin')
Done Done
= icon('spinner spin')
.todo-body .todo-body
.todo-note .todo-note
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
.nav-controls .nav-controls
- if @todos.any?(&:pending?) - if @todos.any?(&:pending?)
= link_to 'Mark all as done', destroy_all_dashboard_todos_path(todos_filter_params), class: 'btn', method: :delete = link_to destroy_all_dashboard_todos_path(todos_filter_params), class: 'btn btn-loading js-todos-mark-all', method: :delete do
Mark all as done
= icon('spinner spin')
.todos-filters .todos-filters
.gray-content-block.second-block .gray-content-block.second-block
...@@ -44,7 +46,7 @@ ...@@ -44,7 +46,7 @@
.prepend-top-default .prepend-top-default
- if @todos.any? - if @todos.any?
- @todos.group_by(&:project).each do |group| - @todos.group_by(&:project).each do |group|
.panel.panel-default.panel-small .panel.panel-default.panel-small.js-todos-list
- project = group[0] - project = group[0]
.panel-heading .panel-heading
= link_to project.name_with_namespace, namespace_project_path(project.namespace, project) = link_to project.name_with_namespace, namespace_project_path(project.namespace, project)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment