summaryrefslogtreecommitdiff
path: root/app/assets
diff options
context:
space:
mode:
authorJacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home>2016-02-23 15:09:35 -0500
committerPhil Hughes <me@iamphill.com>2016-03-17 12:20:14 +0000
commitfa570525dbe35fb598b8a269198e1173da6d7ae3 (patch)
tree13098cbb1aaad8ec4706423ec11b4514a3cbd948 /app/assets
parent4171933c0963696626c879c2d05afa1594a71d99 (diff)
downloadgitlab-ce-fa570525dbe35fb598b8a269198e1173da6d7ae3.tar.gz
Adds small AJAX optimistic functionality to todos.
Fixes #13656 A good first step and boring solution.
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/dispatcher.js.coffee3
-rw-r--r--app/assets/javascripts/todos.js.coffee48
-rw-r--r--app/assets/stylesheets/framework/flash.scss6
3 files changed, 56 insertions, 1 deletions
diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee
index 1be86e3b820..f5e1ca9860d 100644
--- a/app/assets/javascripts/dispatcher.js.coffee
+++ b/app/assets/javascripts/dispatcher.js.coffee
@@ -14,7 +14,6 @@ class Dispatcher
path = page.split(':')
shortcut_handler = null
-
switch page
when 'projects:issues:index'
Issues.init()
@@ -25,6 +24,8 @@ class Dispatcher
new ZenMode()
when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show'
new Milestone()
+ when 'dashboard:todos:index'
+ new Todos()
when 'projects:milestones:new', 'projects:milestones:edit'
new ZenMode()
new DropzoneInput($('.milestone-form'))
diff --git a/app/assets/javascripts/todos.js.coffee b/app/assets/javascripts/todos.js.coffee
new file mode 100644
index 00000000000..b68c143b4bb
--- /dev/null
+++ b/app/assets/javascripts/todos.js.coffee
@@ -0,0 +1,48 @@
+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
diff --git a/app/assets/stylesheets/framework/flash.scss b/app/assets/stylesheets/framework/flash.scss
index 1bfd0213995..244d0e2f0c8 100644
--- a/app/assets/stylesheets/framework/flash.scss
+++ b/app/assets/stylesheets/framework/flash.scss
@@ -5,6 +5,12 @@
width: 100%;
z-index: 100;
+ .flash-success {
+ @extend .alert;
+ @extend .alert-success;
+ margin: 0;
+ }
+
.flash-notice {
@extend .alert;
@extend .alert-info;