Make a refactor of confirm.ask

stable
David Barragán Merino 2015-10-19 13:54:40 +02:00 committed by Alejandro Alonso
parent 5547c892d8
commit 0484883db6
9 changed files with 57 additions and 27 deletions

View File

@ -359,7 +359,7 @@ class CsvExporterController extends taiga.Controller
setCsvUuid: => setCsvUuid: =>
@scope.csvUuid = @scope.project["#{@.type}_csv_uuid"] @scope.csvUuid = @scope.project["#{@.type}_csv_uuid"]
_generateUuid: (finish) => _generateUuid: (response=null) =>
promise = @rs.projects["regenerate_#{@.type}_csv_uuid"](@scope.projectId) promise = @rs.projects["regenerate_#{@.type}_csv_uuid"](@scope.projectId)
promise.then (data) => promise.then (data) =>
@ -369,7 +369,7 @@ class CsvExporterController extends taiga.Controller
@confirm.notify("error") @confirm.notify("error")
promise.finally -> promise.finally ->
finish() response.finish() if response
return promise return promise
regenerateUuid: -> regenerateUuid: ->
@ -379,7 +379,7 @@ class CsvExporterController extends taiga.Controller
@confirm.ask(title, subtitle).then @._generateUuid @confirm.ask(title, subtitle).then @._generateUuid
else else
@._generateUuid(_.identity) @._generateUuid()
class CsvExporterUserstoriesController extends CsvExporterController class CsvExporterUserstoriesController extends CsvExporterController

View File

@ -653,13 +653,11 @@ ProjectCustomAttributesDirective = ($log, $confirm, animationFrame, $translate)
title = $translate.instant("COMMON.CUSTOM_ATTRIBUTES.DELETE") title = $translate.instant("COMMON.CUSTOM_ATTRIBUTES.DELETE")
text = $translate.instant("COMMON.CUSTOM_ATTRIBUTES.CONFIRM_DELETE") text = $translate.instant("COMMON.CUSTOM_ATTRIBUTES.CONFIRM_DELETE")
$confirm.ask(title, text, message).then (finish) -> $confirm.ask(title, text, message).then (response) ->
onSucces = -> onSucces = ->
$ctrl.loadCustomAttributes().finally -> $ctrl.loadCustomAttributes().finally -> response.finish()
finish()
onError = -> onError = ->
finish(false)
$confirm.notify("error", null, "We have not been able to delete '#{message}'.") $confirm.notify("error", null, "We have not been able to delete '#{message}'.")
$ctrl.deleteCustomAttribute(attr).then(onSucces, onError) $ctrl.deleteCustomAttribute(attr).then(onSucces, onError)

View File

@ -129,7 +129,7 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
return @repo.remove(@scope.role, {moveTo: response.selected}).then onSuccess, onError return @repo.remove(@scope.role, {moveTo: response.selected}).then onSuccess, onError
setComputable: debounce 2000, -> _enableComputable: =>
onSuccess = => onSuccess = =>
@confirm.notify("success") @confirm.notify("success")
@.loadProject() @.loadProject()
@ -140,9 +140,37 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
@repo.save(@scope.role).then onSuccess, onError @repo.save(@scope.role).then onSuccess, onError
_disableComputable: =>
askOnSuccess = (response) =>
onSuccess = =>
response.finish()
@confirm.notify("success")
@.loadProject()
onError = =>
response.finish()
@confirm.notify("error")
@scope.role.revert()
@repo.save(@scope.role).then onSuccess, onError
askOnError = (response) =>
@scope.role.revert()
title = @translate.instant("ADMIN.ROLES.DISABLE_COMPUTABLE_ALERT_TITLE")
subtitle = @translate.instant("ADMIN.ROLES.DISABLE_COMPUTABLE_ALERT_SUBTITLE", {
roleName: @scope.role.name
})
message = @translate.instant("ADMIN.ROLES.DISABLE_COMPUTABLE_ALERT_MESSAGE")
return @confirm.ask(title, subtitle, message).then askOnSuccess, askOnError
toggleComputable: debounce 2000, ->
if not @scope.role.computable
@._disableComputable()
else
@._enableComputable()
module.controller("RolesController", RolesController) module.controller("RolesController", RolesController)
EditRoleDirective = ($repo, $confirm) -> EditRoleDirective = ($repo, $confirm) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
toggleView = -> toggleView = ->

View File

@ -326,8 +326,8 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading, $qqueue, $template
return if not isEditable() return if not isEditable()
title = $translate.instant("COMMON.ASSIGNED_TO.CONFIRM_UNASSIGNED") title = $translate.instant("COMMON.ASSIGNED_TO.CONFIRM_UNASSIGNED")
$confirm.ask(title).then (finish) => $confirm.ask(title).then (response) =>
finish() response.finish()
$model.$modelValue.assigned_to = null $model.$modelValue.assigned_to = null
save(null) save(null)

View File

@ -67,11 +67,12 @@ class ConfirmService extends taiga.Service
currentLoading = @loading() currentLoading = @loading()
.target(target) .target(target)
.start() .start()
defered.resolve {
defered.resolve (ok=true) => finish: (ok=true) =>
currentLoading.finish() currentLoading.finish()
if ok if ok
@.hide(el) @.hide(el)
}
el.on "click.confirm-dialog", "a.button-red", (event) => el.on "click.confirm-dialog", "a.button-red", (event) =>
event.preventDefault() event.preventDefault()
@ -118,8 +119,9 @@ class ConfirmService extends taiga.Service
.start() .start()
defered.resolve { defered.resolve {
selected: choicesField.val() selected: choicesField.val()
finish: => finish: (ok=true) =>
currentLoading.finish() currentLoading.finish()
if ok
@.hide(el) @.hide(el)
} }

View File

@ -553,7 +553,7 @@ module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", "$tgConfirm"
PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $translate) -> PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $translate) ->
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
save = $qqueue.bindAdd (issue, finish) => save = $qqueue.bindAdd (issue, askResponse) =>
data = { data = {
generated_from_issue: issue.id generated_from_issue: issue.id
project: issue.project, project: issue.project,
@ -565,12 +565,12 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $transl
} }
onSuccess = -> onSuccess = ->
finish() askResponse.finish()
$confirm.notify("success") $confirm.notify("success")
$rootScope.$broadcast("promote-issue-to-us:success") $rootScope.$broadcast("promote-issue-to-us:success")
onError = -> onError = ->
finish(false) askResponse.finish()
$confirm.notify("error") $confirm.notify("error")
$repo.create("userstories", data).then(onSuccess, onError) $repo.create("userstories", data).then(onSuccess, onError)
@ -584,9 +584,8 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $transl
message = $translate.instant("ISSUES.CONFIRM_PROMOTE.MESSAGE") message = $translate.instant("ISSUES.CONFIRM_PROMOTE.MESSAGE")
subtitle = issue.subject subtitle = issue.subject
$confirm.ask(title, subtitle, message).then (finish) => $confirm.ask(title, subtitle, message).then (response) =>
save(issue, finish) save(issue, response)
$scope.$on "$destroy", -> $scope.$on "$destroy", ->
$el.off() $el.off()

View File

@ -217,16 +217,16 @@ LeaveProjectDirective = ($repo, $confirm, $location, $rs, $navurls, $translate)
leave_project_text = $translate.instant("TEAM.ACTION_LEAVE_PROJECT") leave_project_text = $translate.instant("TEAM.ACTION_LEAVE_PROJECT")
confirm_leave_project_text = $translate.instant("TEAM.CONFIRM_LEAVE_PROJECT") confirm_leave_project_text = $translate.instant("TEAM.CONFIRM_LEAVE_PROJECT")
$confirm.ask(leave_project_text, confirm_leave_project_text).then (finish) => $confirm.ask(leave_project_text, confirm_leave_project_text).then (response) =>
promise = $rs.projects.leave($attrs.projectid) promise = $rs.projects.leave($attrs.projectid)
promise.then => promise.then =>
finish() response.finish()
$confirm.notify("success") $confirm.notify("success")
$location.path($navurls.resolve("home")) $location.path($navurls.resolve("home"))
promise.then null, (response) -> promise.then null, (response) ->
finish() response.finish()
$confirm.notify('error', response.data._error_message) $confirm.notify('error', response.data._error_message)
return { return {

View File

@ -500,6 +500,9 @@
"PAGE_TITLE": "Roles - {{projectName}}", "PAGE_TITLE": "Roles - {{projectName}}",
"WARNING_NO_ROLE": "Be careful, no role in your project will be able to estimate the point value for user stories", "WARNING_NO_ROLE": "Be careful, no role in your project will be able to estimate the point value for user stories",
"HELP_ROLE_ENABLED": "When enabled, members assigned to this role will be able to estimate the point value for user stories", "HELP_ROLE_ENABLED": "When enabled, members assigned to this role will be able to estimate the point value for user stories",
"DISABLE_COMPUTABLE_ALERT_TITLE": "Disable estimation for this role",
"DISABLE_COMPUTABLE_ALERT_SUBTITLE": "If you disable estimation permissions for role {{roleName}} all previous estimations made by this role will be removed",
"DISABLE_COMPUTABLE_ALERT_MESSAGE": "<strong>Are you sure you want to disable this role estimations?</strong>",
"COUNT_MEMBERS": "{{ role.members_count }} members with this role", "COUNT_MEMBERS": "{{ role.members_count }} members with this role",
"TITLE_DELETE_ROLE": "Delete Role", "TITLE_DELETE_ROLE": "Delete Role",
"REPLACEMENT_ROLE": "All the users with this role will be moved to", "REPLACEMENT_ROLE": "All the users with this role will be moved to",

View File

@ -33,7 +33,7 @@ div.wrapper.roles(ng-controller="RolesController as ctrl",
div.general-category div.general-category
span(translate="ADMIN.ROLES.HELP_ROLE_ENABLED") span(translate="ADMIN.ROLES.HELP_ROLE_ENABLED")
div.check div.check
input(type="checkbox", ng-model="role.computable", ng-change="ctrl.setComputable()") input(type="checkbox", ng-model="role.computable", ng-change="ctrl.toggleComputable()")
div div
span.check-text.check-yes(translate="COMMON.YES") span.check-text.check-yes(translate="COMMON.YES")
span.check-text.check-no(translate="COMMON.NO") span.check-text.check-no(translate="COMMON.NO")