Commit 421215e3 authored by Phil Hughes's avatar Phil Hughes

Removed the flash success message

Removes the group if empty
parent 8f872020
class @Todos class @Todos
_this = null;
constructor: (@name) -> constructor: (@name) ->
_this = @ @clearListeners()
@initBtnListeners() @initBtnListeners()
clearListeners: ->
$('.done-todo').off('click')
initBtnListeners: -> initBtnListeners: ->
$('.done-todo').on('click', @doneClicked) $('.done-todo').on('click', @doneClicked)
doneClicked: (e) -> doneClicked: (e) =>
$this = $(this)
doneURL = $this.attr('href')
e.preventDefault() e.preventDefault()
e.stopImmediatePropagation() e.stopImmediatePropagation()
$spinner = $('<i></i>').addClass('fa fa-spinner fa-spin')
$this.addClass("disabled") $this = $(e.currentTarget)
$this.append($spinner) $this.disable()
$.ajax $.ajax
type: 'POST' type: 'POST'
url: doneURL url: $this.attr('href')
dataType: 'json' dataType: 'json'
data: '_method': 'delete' data: '_method': 'delete'
error: (data, textStatus, jqXHR) -> success: (data) =>
new Flash('Unable to update your todos.', 'alert') @clearDone $this.closest('li'), data
_this.clearDone($this.closest('li'))
return
success: (data, textStatus, jqXHR) ->
_this.clearDone($this.closest('li'))
return
clearDone: ($row) -> clearDone: ($row, data) ->
$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
Turbolinks.visit(location.href) $ul.parents('.panel').remove()
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
\ No newline at end of file
...@@ -208,3 +208,13 @@ ...@@ -208,3 +208,13 @@
background-color: #e4e7ed !important; background-color: #e4e7ed !important;
} }
} }
.btn-loading {
&:not(.disabled) .fa {
display: none;
}
.fa {
margin-right: 5px;
}
}
...@@ -5,12 +5,6 @@ ...@@ -5,12 +5,6 @@
width: 100%; width: 100%;
z-index: 100; z-index: 100;
.flash-success {
@extend .alert;
@extend .alert-success;
margin: 0;
}
.flash-notice { .flash-notice {
@extend .alert; @extend .alert;
@extend .alert-info; @extend .alert-info;
......
class Dashboard::TodosController < Dashboard::ApplicationController class Dashboard::TodosController < Dashboard::ApplicationController
before_action :find_todos, only: [:index, :destroy_all] before_action :find_todos, only: [:index, :destroy, :destroy_all]
def index def index
@todos = @todos.page(params[:page]).per(PER_PAGE) @todos = @todos.page(params[:page]).per(PER_PAGE)
...@@ -14,7 +14,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -14,7 +14,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
format.html { redirect_to dashboard_todos_path, notice: todo_notice } format.html { redirect_to dashboard_todos_path, notice: todo_notice }
format.js { render nothing: true } format.js { render nothing: true }
format.json do format.json do
render json: { status: 'OK', notice: todo_notice } render json: { count: @todos.size, done_count: current_user.todos.done.count }
end end
end end
end end
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
- if todo.pending? - if todo.pending?
.todo-actions.pull-right .todo-actions.pull-right
= link_to 'Done', [:dashboard, todo], method: :delete, class: 'btn done-todo' = link_to [:dashboard, todo], method: :delete, class: 'btn btn-loading done-todo' do
= icon('spinner spin')
Done
.todo-body .todo-body
.todo-note .todo-note
......
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