Debounce refactor: remove double clicks problem

stable
Jesús Espino 2014-09-18 16:06:07 +02:00
parent 51159a1058
commit 15b99b76ea
16 changed files with 48 additions and 33 deletions

View File

@ -20,6 +20,7 @@
### ###
taiga = @.taiga taiga = @.taiga
debounce = @.taiga.debounce
module = angular.module("taigaKanban") module = angular.module("taigaKanban")
@ -92,7 +93,7 @@ CreateMembersDirective = ($rs, $rootScope, $confirm, lightboxService) ->
$el.find("fieldset:last > a").removeClass("icon-plus add-fieldset") $el.find("fieldset:last > a").removeClass("icon-plus add-fieldset")
.addClass("icon-delete delete-fieldset") .addClass("icon-delete delete-fieldset")
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
onSuccess = (data) -> onSuccess = (data) ->

View File

@ -27,6 +27,7 @@ toString = @.taiga.toString
joinStr = @.taiga.joinStr joinStr = @.taiga.joinStr
groupBy = @.taiga.groupBy groupBy = @.taiga.groupBy
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaAdmin") module = angular.module("taigaAdmin")
@ -85,7 +86,7 @@ class ProjectValuesController extends mixOf(taiga.Controller, taiga.PageMixin)
@.loadValues(), @.loadValues(),
])) ]))
moveValue: (ctx, itemValue, itemIndex) => moveValue: debounce 2000, (ctx, itemValue, itemIndex) =>
values = @scope.values values = @scope.values
r = values.indexOf(itemValue) r = values.indexOf(itemValue)
values.splice(r, 1) values.splice(r, 1)
@ -152,7 +153,7 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame) ->
if focus if focus
$(".new-value input").focus() $(".new-value input").focus()
submit = => submit = debounce 2000, =>
promise = $repo.save($scope.project) promise = $repo.save($scope.project)
promise.then -> promise.then ->
$confirm.notify("success") $confirm.notify("success")
@ -160,7 +161,7 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame) ->
promise.then null, (data) -> promise.then null, (data) ->
$confirm.notify("error", data._error_message) $confirm.notify("error", data._error_message)
saveValue = (target)-> saveValue = debounce 2000, (target) ->
form = target.parents("form").checksley() form = target.parents("form").checksley()
return if not form.validate() return if not form.validate()
@ -197,7 +198,7 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame) ->
goToBottomList(true) goToBottomList(true)
$el.on "click", ".add-new", (event) -> $el.on "click", ".add-new", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
form = $el.find(".new-value").parents("form").checksley() form = $el.find(".new-value").parents("form").checksley()
return if not form.validate() return if not form.validate()

View File

@ -23,6 +23,7 @@ taiga = @.taiga
mixOf = @.taiga.mixOf mixOf = @.taiga.mixOf
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaAdmin") module = angular.module("taigaAdmin")
@ -108,7 +109,7 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
promise.then null, => promise.then null, =>
@confirm.notify('error') @confirm.notify('error')
setComputable: -> setComputable: debounce 2000, ->
onSuccess = => onSuccess = =>
@confirm.notify("success") @confirm.notify("success")
@ -148,7 +149,7 @@ NewRoleDirective = ($tgrepo, $confirm) ->
$el.find(".new").focus() $el.find(".new").focus()
$el.find(".add-button").hide() $el.find(".add-button").hide()
$el.on "keyup", ".new", (event) -> $el.on "keyup", ".new", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
if event.keyCode == 13 # Enter key if event.keyCode == 13 # Enter key
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@ -305,7 +306,7 @@ RolePermissionsDirective = ($rootscope, $repo, $confirm) ->
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
target.next().toggleClass("open") target.next().toggleClass("open")
$el.on "change", ".category-item input", (event) -> $el.on "change", ".category-item input", debounce 2000, (event) ->
getActivePermissions = -> getActivePermissions = ->
activePermissions = _.filter($el.find(".category-item input"), (t) -> activePermissions = _.filter($el.find(".category-item input"), (t) ->
angular.element(t).is(":checked") angular.element(t).is(":checked")

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaBacklog") module = angular.module("taigaBacklog")
@ -143,7 +144,7 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading)
else else
$el.find(".last-sprint-name").removeClass("disappear") $el.find(".last-sprint-name").removeClass("disappear")
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
submit(event) submit(event)

View File

@ -22,6 +22,7 @@
taiga = @.taiga taiga = @.taiga
timeout = @.taiga.timeout timeout = @.taiga.timeout
cancelTimeout = @.taiga.cancelTimeout cancelTimeout = @.taiga.cancelTimeout
debounce = @.taiga.debounce
NOTIFICATION_MSG = { NOTIFICATION_MSG = {
@ -59,7 +60,7 @@ class ConfirmService extends taiga.Service
defered = @q.defer() defered = @q.defer()
# Assign event handlers # Assign event handlers
@.el.on "click.confirm-dialog", "a.button-green", (event) => @.el.on "click.confirm-dialog", "a.button-green", debounce 2000, (event) =>
event.preventDefault() event.preventDefault()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@loading.start(target) @loading.start(target)
@ -89,7 +90,7 @@ class ConfirmService extends taiga.Service
defered = @q.defer() defered = @q.defer()
# Assign event handlers # Assign event handlers
@.el.on "click.confirm-dialog", "a.button-green", (event) => @.el.on "click.confirm-dialog", "a.button-green", debounce 2000, (event) =>
event.preventDefault() event.preventDefault()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@loading.start(target) @loading.start(target)

View File

@ -22,6 +22,7 @@
taiga = @.taiga taiga = @.taiga
trim = @.taiga.trim trim = @.taiga.trim
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaCommon") module = angular.module("taigaCommon")
@ -437,7 +438,7 @@ HistoryDirective = ($log, $loading) ->
# Events # Events
$el.on "click", ".add-comment a.button-green", (event) -> $el.on "click", ".add-comment a.button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@ -492,12 +493,12 @@ HistoryDirective = ($log, $loading) ->
$el.find(".history-tabs li a").toggleClass("active") $el.find(".history-tabs li a").toggleClass("active")
$el.find(".history section").toggleClass("hidden") $el.find(".history section").toggleClass("hidden")
$el.on "click", ".comment-delete", (event) -> $el.on "click", ".comment-delete", debounce 2000, (event) ->
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
activityId = target.data('activity-id') activityId = target.data('activity-id')
$ctrl.deleteComment(type, objectId, activityId) $ctrl.deleteComment(type, objectId, activityId)
$el.on "click", ".comment-restore", (event) -> $el.on "click", ".comment-restore", debounce 2000, (event) ->
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
activityId = target.data('activity-id') activityId = target.data('activity-id')
$ctrl.undeleteComment(type, objectId, activityId) $ctrl.undeleteComment(type, objectId, activityId)

View File

@ -23,6 +23,7 @@ module = angular.module("taigaCommon")
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
timeout = @.taiga.timeout timeout = @.taiga.timeout
debounce = @.taiga.debounce
############################################################################# #############################################################################
## Common Lightbox Services ## Common Lightbox Services
@ -247,7 +248,7 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService,
lightboxService.open($el) lightboxService.open($el)
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
form = $el.find("form").checksley() form = $el.find("form").checksley()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@ -306,7 +307,7 @@ CreateBulkUserstoriesDirective = ($repo, $rs, $rootscope, lightboxService, $load
} }
lightboxService.open($el) lightboxService.open($el)
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
form = $el.find("form").checksley({ form = $el.find("form").checksley({
@ -439,7 +440,7 @@ AssignedToLightboxDirective = (lightboxService, lightboxKeyboardNavigationServic
$scope.$watch "usersSearch", (searchingText) -> $scope.$watch "usersSearch", (searchingText) ->
render(selectedUser, searchingText) if searchingText? render(selectedUser, searchingText) if searchingText?
$el.on "click", ".watcher-single", (event) -> $el.on "click", ".watcher-single", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@ -449,7 +450,7 @@ AssignedToLightboxDirective = (lightboxService, lightboxKeyboardNavigationServic
$scope.$broadcast("assigned-to:added", target.data("user-id"), selectedItem) $scope.$broadcast("assigned-to:added", target.data("user-id"), selectedItem)
$scope.usersSearch = null $scope.usersSearch = null
$el.on "click", ".remove-assigned-to", (event) -> $el.on "click", ".remove-assigned-to", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -534,7 +535,7 @@ WatchersLightboxDirective = ($repo, lightboxService, lightboxKeyboardNavigationS
users = getFilteredUsers(searchingText) users = getFilteredUsers(searchingText)
render(users) render(users)
$el.on "click", ".watcher-single", (event) -> $el.on "click", ".watcher-single", debounce 2000, (event) ->
closeLightbox() closeLightbox()
event.preventDefault() event.preventDefault()

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaCommon") module = angular.module("taigaCommon")
@ -73,7 +74,7 @@ UsStatusDirective = ($repo, popoverService) ->
# pop = $el.find(".pop-status") # pop = $el.find(".pop-status")
# popoverService.open(pop) # popoverService.open(pop)
$el.on "click", ".status", (event) -> $el.on "click", ".status", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@ -152,7 +153,7 @@ RelatedTaskStatusDirective = ($repo, popoverService) ->
# pop = $el.find(".pop-status") # pop = $el.find(".pop-status")
# popoverService.open(pop) # popoverService.open(pop)
$el.on "click", ".status", (event) -> $el.on "click", ".status", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaIssues") module = angular.module("taigaIssues")
@ -49,7 +50,7 @@ CreateIssueDirective = ($repo, $confirm, $rootscope, lightboxService) ->
$scope.$on "$destroy", -> $scope.$on "$destroy", ->
$el.off() $el.off()
submit = -> submit = debounce 2000, ->
if not form.validate() if not form.validate()
return return
@ -90,7 +91,7 @@ CreateBulkIssuesDirective = ($repo, $rs, $confirm, $rootscope, lightboxService)
bulk: "" bulk: ""
} }
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
form = $el.find("form").checksley() form = $el.find("form").checksley()

View File

@ -22,6 +22,7 @@
taiga = @.taiga taiga = @.taiga
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
timeout = @.taiga.timeout timeout = @.taiga.timeout
debounce = @.taiga.debounce
module = angular.module("taigaProject") module = angular.module("taigaProject")
@ -106,7 +107,7 @@ CreateProject = ($rootscope, $repo, $confirm, $location, $navurls, $rs, $project
$el.find('.progress-bar').removeClass().addClass('progress-bar').addClass(step) $el.find('.progress-bar').removeClass().addClass('progress-bar').addClass(step)
$el.on "click", ".button-submit", (event) -> $el.on "click", ".button-submit", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
submit() submit()

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
trim = @.taiga.trim trim = @.taiga.trim
debounce = @.taiga.debounce
module = angular.module("taigaRelatedTasks", []) module = angular.module("taigaRelatedTasks", [])
@ -86,7 +87,7 @@ RelatedTaskRowDirective = ($repo, $compile, $confirm, $rootscope) ->
""") """)
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
saveTask = (task) -> saveTask = debounce 2000, (task) ->
task.subject = $el.find('input').val() task.subject = $el.find('input').val()
promise = $repo.save(task) promise = $repo.save(task)
promise.then => promise.then =>
@ -191,7 +192,7 @@ RelatedTaskCreateFormDirective = ($repo, $compile, $confirm, $tgmodel) ->
} }
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
createTask = (task) -> createTask = debounce 2000, (task) ->
task.subject = $el.find('input').val() task.subject = $el.find('input').val()
task.assigned_to = $scope.newTask.assigned_to task.assigned_to = $scope.newTask.assigned_to
task.status = $scope.newTask.status task.status = $scope.newTask.status
@ -330,7 +331,7 @@ RelatedTaskAssignedToInlineEditionDirective = ($repo, $rootscope, popoverService
$el.unbind("click") $el.unbind("click")
$el.find("a").addClass("not-clickable") $el.find("a").addClass("not-clickable")
$scope.$on "assigned-to:added", (ctx, userId, updatedRelatedTask) => $scope.$on "assigned-to:added", debounce 2000, (ctx, userId, updatedRelatedTask) =>
if updatedRelatedTask.id == task.id if updatedRelatedTask.id == task.id
updatedRelatedTask.assigned_to = userId updatedRelatedTask.assigned_to = userId
if autoSave if autoSave

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, lightboxService) -> CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, lightboxService) ->
link = ($scope, $el, attrs) -> link = ($scope, $el, attrs) ->
@ -52,7 +53,7 @@ CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, lightboxService) ->
$el.find(".title").html("Edit task ") #TODO: i18n $el.find(".title").html("Edit task ") #TODO: i18n
lightboxService.open($el) lightboxService.open($el)
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
form = $el.find("form").checksley() form = $el.find("form").checksley()
@ -85,7 +86,7 @@ CreateBulkTasksDirective = ($repo, $rs, $rootscope, lightboxService) ->
lightboxService.open($el) lightboxService.open($el)
$scope.form = {data: "", sprintId: sprintId, usId: usId} $scope.form = {data: "", sprintId: sprintId, usId: usId}
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
form = $el.find("form").checksley() form = $el.find("form").checksley()

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce
module = angular.module("taigaUserSettings") module = angular.module("taigaUserSettings")
@ -53,7 +54,7 @@ DeleteUserDirective = ($repo, $rootscope, $auth, $location, $navUrls, lightboxSe
event.preventDefault() event.preventDefault()
lightboxService.close($el) lightboxService.close($el)
$el.on "click", ".button-green", (event) -> $el.on "click", ".button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
submit() submit()

View File

@ -25,6 +25,7 @@ mixOf = @.taiga.mixOf
groupBy = @.taiga.groupBy groupBy = @.taiga.groupBy
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
unslugify = @.taiga.unslugify unslugify = @.taiga.unslugify
debounce = @.taiga.debounce
module = angular.module("taigaWiki") module = angular.module("taigaWiki")
@ -157,7 +158,7 @@ module.controller("WikiDetailController", WikiDetailController)
############################################################################# #############################################################################
class WikiEditController extends WikiDetailController class WikiEditController extends WikiDetailController
save: -> save: debounce 2000, ->
onSuccess = => onSuccess = =>
ctx = { ctx = {
project: @scope.projectSlug project: @scope.projectSlug

View File

@ -26,6 +26,7 @@ groupBy = @.taiga.groupBy
bindOnce = @.taiga.bindOnce bindOnce = @.taiga.bindOnce
slugify = @.taiga.slugify slugify = @.taiga.slugify
unslugify = @.taiga.slugify unslugify = @.taiga.slugify
debounce = @.taiga.debounce
module = angular.module("taigaWiki") module = angular.module("taigaWiki")
@ -120,7 +121,7 @@ WikiNavDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
promise.then null, -> promise.then null, ->
$confirm.notify("error") $confirm.notify("error")
$el.on "keyup", ".new input", (event) -> $el.on "keyup", ".new input", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
if event.keyCode == 13 if event.keyCode == 13
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)

View File

@ -104,7 +104,7 @@ joinStr = (str, coll) ->
debounce = (wait, func) -> debounce = (wait, func) ->
return _.debounce(func, wait) return _.debounce(func, wait, {leading: true, trailing: false})
startswith = (str1, str2) -> startswith = (str1, str2) ->
return _.str.startsWith(str1, str2) return _.str.startsWith(str1, str2)