Commit fa570525 authored by Jacob Schatz's avatar Jacob Schatz Committed by Phil Hughes

Adds small AJAX optimistic functionality to todos.

Fixes #13656
A good first step and boring solution.
parent 4171933c
...@@ -14,7 +14,6 @@ class Dispatcher ...@@ -14,7 +14,6 @@ class Dispatcher
path = page.split(':') path = page.split(':')
shortcut_handler = null shortcut_handler = null
switch page switch page
when 'projects:issues:index' when 'projects:issues:index'
Issues.init() Issues.init()
...@@ -25,6 +24,8 @@ class Dispatcher ...@@ -25,6 +24,8 @@ class Dispatcher
new ZenMode() new ZenMode()
when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show' when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show'
new Milestone() new Milestone()
when 'dashboard:todos:index'
new Todos()
when 'projects:milestones:new', 'projects:milestones:edit' when 'projects:milestones:new', 'projects:milestones:edit'
new ZenMode() new ZenMode()
new DropzoneInput($('.milestone-form')) new DropzoneInput($('.milestone-form'))
......
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
\ No newline at end of file
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
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;
......
...@@ -8,9 +8,14 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -8,9 +8,14 @@ class Dashboard::TodosController < Dashboard::ApplicationController
def destroy def destroy
todo.done! todo.done!
todo_notice = 'Todo was successfully marked as done.'
respond_to do |format| respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' } format.html { redirect_to dashboard_todos_path, notice: todo_notice }
format.js { render nothing: true } format.js { render nothing: true }
format.json do
render json: { status: 'OK', notice: todo_notice }
end
end end
end end
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- if todo.pending? - if todo.pending?
.todo-actions.pull-right .todo-actions.pull-right
= link_to 'Done', [:dashboard, todo], method: :delete, class: 'btn' = link_to 'Done', [:dashboard, todo], method: :delete, class: 'btn done-todo'
.todo-body .todo-body
.todo-note .todo-note
......
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
.top-area .top-area
%ul.nav-links %ul.nav-links
%li{class: ('active' if params[:state].blank? || params[:state] == 'pending')} - todo_pending_active = ('active' if params[:state].blank? || params[:state] == 'pending')
%li{class: "todos-pending #{todo_pending_active}"}
= link_to todos_filter_path(state: 'pending') do = link_to todos_filter_path(state: 'pending') do
%span %span
To do To do
%span{class: 'badge'} %span{class: 'badge'}
= todos_pending_count = todos_pending_count
%li{class: ('active' if params[:state] == 'done')} - todo_done_active = ('active' if params[:state] == 'done')
%li{class: "todos-done #{todo_done_active}"}
= link_to todos_filter_path(state: 'done') do = link_to todos_filter_path(state: 'done') do
%span %span
Done Done
......
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