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

Removed the flash success message

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