diff --git a/app/coffee/modules/common.coffee b/app/coffee/modules/common.coffee index b9b31365..06e01a56 100644 --- a/app/coffee/modules/common.coffee +++ b/app/coffee/modules/common.coffee @@ -158,3 +158,32 @@ LimitLineLengthDirective = () -> return {link:link} module.directive("tgLimitLineLength", LimitLineLengthDirective) + +############################################################################# +## Queue Q promises +############################################################################# + +Qqueue = ($q) -> + deferred = $q.defer() + deferred.resolve() + + lastPromise = deferred.promise + + qqueue = { + bindAdd: (fn) => + return (args...) => + lastPromise = lastPromise.then () => fn.apply(@, args) + + return qqueue + add: (fn) => + if !lastPromise + lastPromise = fn() + else + lastPromise = lastPromise.then(fn) + + return qqueue + } + + return qqueue + +module.factory("$tgQqueue", ["$q", Qqueue]) diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index f4a4b419..a0591462 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -161,7 +161,7 @@ module.directive("tgCreatedByDisplay", CreatedByDisplayDirective) ## Watchers directive ############################################################################# -WatchersDirective = ($rootscope, $confirm, $repo) -> +WatchersDirective = ($rootscope, $confirm, $repo, $qqueue) -> # You have to include a div with the tg-lb-watchers directive in the page # where use this directive # @@ -204,17 +204,37 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> isEditable = -> return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 - save = (model) -> + save = $qqueue.bindAdd (watchers) => + item = $model.$modelValue.clone() + item.watchers = watchers + $model.$setViewValue(item) + promise = $repo.save($model.$modelValue) promise.then -> $confirm.notify("success") - watchers = _.map(model.watchers, (watcherId) -> $scope.usersById[watcherId]) + watchers = _.map(watchers, (watcherId) -> $scope.usersById[watcherId]) + renderWatchers(watchers) + $rootscope.$broadcast("history:reload") + + promise.then null, -> + $model.$modelValue.revert() + + deleteWatcher = $qqueue.bindAdd (watcherIds) => + item = $model.$modelValue.clone() + item.watchers = watcherIds + $model.$setViewValue(item) + + promise = $repo.save($model.$modelValue) + promise.then -> + $confirm.notify("success") + watchers = _.map(item.watchers, (watcherId) -> $scope.usersById[watcherId]) renderWatchers(watchers) $rootscope.$broadcast("history:reload") promise.then null, -> - model.revert() + item.revert() $confirm.notify("error") + renderWatchers = (watchers) -> ctx = { watchers: watchers @@ -239,13 +259,11 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> $confirm.askOnDelete(title, message).then (finish) => finish() + watcherIds = _.clone($model.$modelValue.watchers, false) watcherIds = _.pull(watcherIds, watcherId) - item = $model.$modelValue.clone() - item.watchers = watcherIds - $model.$setViewValue(item) - save(item) + deleteWatcher(watcherIds) $el.on "click", ".add-watcher", (event) -> event.preventDefault() @@ -258,10 +276,7 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> watchers.push(watcherId) watchers = _.uniq(watchers) - item = $model.$modelValue.clone() - item.watchers = watchers - $model.$setViewValue(item) - save(item) + save(watchers) $scope.$watch $attrs.ngModel, (item) -> return if not item? @@ -273,14 +288,14 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> return {link:link, require:"ngModel"} -module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", WatchersDirective]) +module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQqueue", WatchersDirective]) ############################################################################# ## Assigned to directive ############################################################################# -AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> +AssignedToDirective = ($rootscope, $confirm, $repo, $loading, $qqueue) -> # You have to include a div with the tg-lb-assignedto directive in the page # where use this directive # @@ -315,20 +330,24 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> isEditable = -> return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 - save = (model) -> + save = $qqueue.bindAdd (userId) => + $model.$modelValue.assigned_to = userId + $loading.start($el) promise = $repo.save($model.$modelValue) promise.then -> $loading.finish($el) $confirm.notify("success") - renderAssignedTo(model) + renderAssignedTo($model.$modelValue) $rootscope.$broadcast("history:reload") promise.then null, -> - model.revert() + $model.$modelValue.revert() $confirm.notify("error") $loading.finish($el) + return promise + renderAssignedTo = (issue) -> assignedToId = issue?.assigned_to assignedTo = if assignedToId? then $scope.usersById[assignedToId] else null @@ -354,12 +373,12 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> $confirm.ask(title).then (finish) => finish() $model.$modelValue.assigned_to = null - save($model.$modelValue) + save(null) $scope.$on "assigned-to:added", (ctx, userId, item) -> return if item.id != $model.$modelValue.id - $model.$modelValue.assigned_to = userId - save($model.$modelValue) + + save(userId) $scope.$watch $attrs.ngModel, (instance) -> renderAssignedTo(instance) @@ -372,7 +391,7 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> require:"ngModel" } -module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", AssignedToDirective]) +module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", "$tgQqueue", AssignedToDirective]) ############################################################################# @@ -473,7 +492,7 @@ module.directive("tgDeleteButton", ["$log", "$tgRepo", "$tgConfirm", "$tgLocatio ## Editable subject directive ############################################################################# -EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) -> +EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading, $qqueue) -> template = """
{{ item.subject }} @@ -492,9 +511,11 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) -> isEditable = -> return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 - save = -> - $model.$modelValue.subject = $scope.item.subject + save = $qqueue.bindAdd (subject) => + $model.$modelValue.subject = subject + $loading.start($el.find('.save-container')) + promise = $repo.save($model.$modelValue) promise.then -> $confirm.notify("success") @@ -506,6 +527,8 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) -> promise.finally -> $loading.finish($el.find('.save-container')) + return promise + $el.click -> return if not isEditable() $el.find('.edit-subject').show() @@ -513,11 +536,13 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) -> $el.find('input').focus() $el.on "click", ".save", -> - save() + subject = $scope.item.subject + save(subject) $el.on "keyup", "input", (event) -> if event.keyCode == 13 - save() + subject = $scope.item.subject + save(subject) else if event.keyCode == 27 $model.$modelValue.revert() $el.find('div.edit-subject').hide() @@ -545,7 +570,7 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) -> template: template } -module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", +module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", EditableSubjectDirective]) @@ -553,7 +578,7 @@ module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$ ## Editable subject directive ############################################################################# -EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText) -> +EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText, $qqueue) -> template = """
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 + save = $qqueue.bindAdd (description) => + $model.$modelValue.description = description + + $loading.start($el.find('.save-container')) + promise = $repo.save($model.$modelValue) + promise.then -> + $confirm.notify("success") + $rootscope.$broadcast("history:reload") + $el.find('.edit-description').hide() + $el.find('.view-description').show() + promise.then null, -> + $confirm.notify("error") + promise.finally -> + $loading.finish($el.find('.save-container')) + $el.on "mouseup", ".view-description", (event) -> # We want to dettect the a inside the div so we use the target and # not the currentTarget @@ -606,19 +646,8 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $el.find('textarea').focus() $el.on "click", ".save", -> - $model.$modelValue.description = $scope.item.description - - $loading.start($el.find('.save-container')) - promise = $repo.save($model.$modelValue) - promise.then -> - $confirm.notify("success") - $rootscope.$broadcast("history:reload") - $el.find('.edit-description').hide() - $el.find('.view-description').show() - promise.then null, -> - $confirm.notify("error") - promise.finally -> - $loading.finish($el.find('.save-container')) + description = $scope.item.description + save(description) $el.on "keyup", "textarea", (event) -> if event.keyCode == 27 @@ -648,7 +677,7 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, } module.directive("tgEditableDescription", ["$rootScope", "$tgRepo", "$tgConfirm", - "$compile", "$tgLoading", "$selectedText", EditableDescriptionDirective]) + "$compile", "$tgLoading", "$selectedText", "$tgQqueue", EditableDescriptionDirective]) ############################################################################# diff --git a/app/coffee/modules/common/estimation.coffee b/app/coffee/modules/common/estimation.coffee index 6449fe5e..ac81e19a 100644 --- a/app/coffee/modules/common/estimation.coffee +++ b/app/coffee/modules/common/estimation.coffee @@ -165,7 +165,7 @@ module.directive("tgLbUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", LbU ## User story estimation directive ############################################################################# -UsEstimationDirective = ($rootScope, $repo, $confirm) -> +UsEstimationDirective = ($rootScope, $repo, $confirm, $qqueue) -> # Display the points of a US and you can edit it. # # Example: @@ -264,6 +264,29 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) -> return _.reduce(notNullValues, (acc, num) -> acc + num) + save = $qqueue.bindAdd (roleId, pointId) => + $el.find(".popover").popover().close() + + # Hell starts here + us = angular.copy($model.$modelValue) + points = _.clone($model.$modelValue.points, true) + points[roleId] = pointId + us.setAttr('points', points) + us.points = points + us.total_points = calculateTotalPoints(us) + $model.$setViewValue(us) + # Hell ends here + + onSuccess = -> + $confirm.notify("success") + $rootScope.$broadcast("history:reload") + onError = -> + $confirm.notify("error") + us.revert() + $model.$setViewValue(us) + + $repo.save($model.$modelValue).then(onSuccess, onError) + $el.on "click", ".total.clickable", (event) -> event.preventDefault() event.stopPropagation() @@ -287,26 +310,7 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) -> roleId = target.data("role-id") pointId = target.data("point-id") - $el.find(".popover").popover().close() - - # Hell starts here - us = angular.copy($model.$modelValue) - points = _.clone($model.$modelValue.points, true) - points[roleId] = pointId - us.setAttr('points', points) - us.points = points - us.total_points = calculateTotalPoints(us) - $model.$setViewValue(us) - # Hell ends here - - onSuccess = -> - $confirm.notify("success") - $rootScope.$broadcast("history:reload") - onError = -> - $confirm.notify("error") - us.revert() - $model.$setViewValue(us) - $repo.save($model.$modelValue).then(onSuccess, onError) + save(roleId, pointId) $scope.$watch $attrs.ngModel, (us) -> render(us) if us @@ -320,4 +324,4 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) -> require: "ngModel" } -module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", UsEstimationDirective]) +module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgQqueue", UsEstimationDirective]) diff --git a/app/coffee/modules/common/history.coffee b/app/coffee/modules/common/history.coffee index e9987d09..679b9d90 100644 --- a/app/coffee/modules/common/history.coffee +++ b/app/coffee/modules/common/history.coffee @@ -61,7 +61,7 @@ class HistoryController extends taiga.Controller return @rs.history.undeleteComment(type, objectId, activityId).then => @.loadHistory(type, objectId) -HistoryDirective = ($log, $loading) -> +HistoryDirective = ($log, $loading, $qqueue) -> templateChangeDiff = _.template("""
@@ -436,6 +436,24 @@ HistoryDirective = ($log, $loading) -> html = renderHistory(changes, totalChanges) $el.find(".changes-list").html(html) + save = $qqueue.bindAdd (target) => + $scope.$broadcast("markdown-editor:submit") + + $el.find(".comment-list").addClass("activeanimation") + + onSuccess = -> + $ctrl.loadHistory(type, objectId).finally -> + $loading.finish(target) + + onError = -> + $loading.finish(target) + $confirm.notify("error") + + model = $scope.$eval($attrs.ngModel) + $loading.start(target) + + $ctrl.repo.save(model).then(onSuccess, onError) + # Watchers $scope.$watch("comments", renderComments) @@ -447,22 +465,10 @@ HistoryDirective = ($log, $loading) -> $el.on "click", ".add-comment a.button-green", debounce 2000, (event) -> event.preventDefault() - $scope.$broadcast("markdown-editor:submit") target = angular.element(event.currentTarget) - $el.find(".comment-list").addClass("activeanimation") - onSuccess = -> - $ctrl.loadHistory(type, objectId).finally -> - $loading.finish(target) - - onError = -> - $loading.finish(target) - $confirm.notify("error") - - model = $scope.$eval($attrs.ngModel) - $loading.start(target) - $ctrl.repo.save(model).then(onSuccess, onError) + save(target) $el.on "click", ".show-more", (event) -> event.preventDefault() @@ -526,4 +532,4 @@ HistoryDirective = ($log, $loading) -> } -module.directive("tgHistory", ["$log", "$tgLoading", HistoryDirective]) +module.directive("tgHistory", ["$log", "$tgLoading", "$tgQqueue", HistoryDirective]) diff --git a/app/coffee/modules/common/lightboxes.coffee b/app/coffee/modules/common/lightboxes.coffee index fd07cb7a..685a0c91 100644 --- a/app/coffee/modules/common/lightboxes.coffee +++ b/app/coffee/modules/common/lightboxes.coffee @@ -126,19 +126,11 @@ module.directive("lightbox", ["lightboxService", LightboxDirective]) # Issue/Userstory blocking message lightbox directive. -BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading) -> +BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading, $qqueue) -> link = ($scope, $el, $attrs, $model) -> $el.find("h2.title").text($attrs.title) - $scope.$on "block", -> - $el.find(".reason").val($model.$modelValue.blocked_note) - lightboxService.open($el) - - $scope.$on "unblock", (event, model, finishCallback) -> - item = $model.$modelValue.clone() - item.is_blocked = false - item.blocked_note = "" - + unblock = $qqueue.bindAdd (item, finishCallback) => promise = $tgrepo.save(item) promise.then -> $confirm.notify("success") @@ -154,15 +146,9 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi promise.finally -> finishCallback() - $scope.$on "$destroy", -> - $el.off() + return promise - $el.on "click", ".button-green", (event) -> - event.preventDefault() - - item = $model.$modelValue.clone() - item.is_blocked = true - item.blocked_note = $el.find(".reason").val() + block = $qqueue.bindAdd (item) => $model.$setViewValue(item) $loading.start($el.find(".button-green")) @@ -181,13 +167,36 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi $loading.finish($el.find(".button-green")) lightboxService.close($el) + $scope.$on "block", -> + $el.find(".reason").val($model.$modelValue.blocked_note) + lightboxService.open($el) + + $scope.$on "unblock", (event, model, finishCallback) => + item = $model.$modelValue.clone() + item.is_blocked = false + item.blocked_note = "" + + unblock(item, finishCallback) + + $scope.$on "$destroy", -> + $el.off() + + $el.on "click", ".button-green", (event) -> + event.preventDefault() + + item = $model.$modelValue.clone() + item.is_blocked = true + item.blocked_note = $el.find(".reason").val() + + block(item) + return { templateUrl: "/partials/views/modules/lightbox-block.html" link: link require: "ngModel" } -module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", BlockLightboxDirective]) +module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", "$tgQqueue", BlockLightboxDirective]) ############################################################################# diff --git a/app/coffee/modules/common/tags.coffee b/app/coffee/modules/common/tags.coffee index 3e910882..3a8e7fbf 100644 --- a/app/coffee/modules/common/tags.coffee +++ b/app/coffee/modules/common/tags.coffee @@ -228,7 +228,7 @@ module.directive("tgLbTagLine", ["$tgResources", LbTagLineDirective]) ## TagLine Directive (for detail pages) ############################################################################# -TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> +TagLineDirective = ($rootScope, $repo, $rs, $confirm, $qqueue) -> ENTER_KEY = 13 ESC_KEY = 27 @@ -288,7 +288,7 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> $el.find("input").autocomplete("close") ## Aux methods - addValue = (value) -> + addValue = $qqueue.bindAdd (value) -> value = trim(value.toLowerCase()) return if value.length == 0 @@ -308,7 +308,7 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> $model.$setViewValue(model) $repo.save(model).then(onSuccess, onError) - deleteValue = (value) -> + deleteValue = $qqueue.bindAdd (value) -> value = trim(value.toLowerCase()) return if value.length == 0 @@ -325,7 +325,8 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> $confirm.notify("error") model.revert() $model.$setViewValue(model) - $repo.save(model).then(onSuccess, onError) + + return $repo.save(model).then(onSuccess, onError) saveInputTag = () -> value = $el.find("input").val() @@ -369,6 +370,7 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> target = angular.element(event.currentTarget) value = target.siblings(".tag-name").text() + deleteValue(value) bindOnce $scope, "project", (project) -> @@ -415,4 +417,4 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> template: template } -module.directive("tgTagLine", ["$rootScope", "$tgRepo", "$tgResources", "$tgConfirm", TagLineDirective]) +module.directive("tgTagLine", ["$rootScope", "$tgRepo", "$tgResources", "$tgConfirm", "$tgQqueue", TagLineDirective]) diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index cb5f7aa4..ff9f2456 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -195,7 +195,7 @@ module.directive("tgIssueStatusDisplay", IssueStatusDisplayDirective) ## Issue status button directive ############################################################################# -IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> +IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue) -> # Display the status of Issue and you can edit it. # # Example: @@ -236,6 +236,21 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> }) $el.html(html) + save = $qqueue.bindAdd (value, issue) => + onSuccess = -> + $confirm.notify("success") + $rootScope.$broadcast("history:reload") + $loading.finish($el.find(".level-name")) + onError = -> + $confirm.notify("error") + issue.revert() + $model.$setViewValue(issue) + $loading.finish($el.find(".level-name")) + + $loading.start($el.find(".level-name")) + + $repo.save(value).then(onSuccess, onError) + $el.on "click", ".status-data", (event) -> event.preventDefault() event.stopPropagation() @@ -256,20 +271,7 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> issue.status = target.data("status-id") $model.$setViewValue(issue) - $scope.$apply() - - onSuccess = -> - $confirm.notify("success") - $rootScope.$broadcast("history:reload") - $loading.finish($el.find(".level-name")) - onError = -> - $confirm.notify("error") - issue.revert() - $model.$setViewValue(issue) - $loading.finish($el.find(".level-name")) - - $loading.start($el.find(".level-name")) - $repo.save($model.$modelValue).then(onSuccess, onError) + save($model.$modelValue, issue) $scope.$watch $attrs.ngModel, (issue) -> render(issue) if issue @@ -283,13 +285,13 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> require: "ngModel" } -module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssueStatusButtonDirective]) +module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssueStatusButtonDirective]) ############################################################################# ## Issue type button directive ############################################################################# -IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) -> +IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue) -> # Display the type of Issue and you can edit it. # # Example: @@ -330,6 +332,26 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) -> }) $el.html(html) + save = $qqueue.bindAdd (type) => + $.fn.popover().closeAll() + issue = $model.$modelValue.clone() + issue.type = type + + $model.$setViewValue(issue) + + onSuccess = -> + $confirm.notify("success") + $rootScope.$broadcast("history:reload") + $loading.finish($el.find(".level-name")) + onError = -> + $confirm.notify("error") + issue.revert() + $model.$setViewValue(issue) + $loading.finish($el.find(".level-name")) + $loading.start($el.find(".level-name")) + + $repo.save($model.$modelValue).then(onSuccess, onError) + $el.on "click", ".type-data", (event) -> event.preventDefault() event.stopPropagation() @@ -343,26 +365,8 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) -> return if not isEditable() target = angular.element(event.currentTarget) - - $.fn.popover().closeAll() - - issue = $model.$modelValue.clone() - issue.type = target.data("type-id") - $model.$setViewValue(issue) - - $scope.$apply() - - onSuccess = -> - $confirm.notify("success") - $rootScope.$broadcast("history:reload") - $loading.finish($el.find(".level-name")) - onError = -> - $confirm.notify("error") - issue.revert() - $model.$setViewValue(issue) - $loading.finish($el.find(".level-name")) - $loading.start($el.find(".level-name")) - $repo.save($model.$modelValue).then(onSuccess, onError) + type = target.data("type-id") + save(type) $scope.$watch $attrs.ngModel, (issue) -> render(issue) if issue @@ -376,14 +380,14 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) -> require: "ngModel" } -module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssueTypeButtonDirective]) +module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssueTypeButtonDirective]) ############################################################################# ## Issue severity button directive ############################################################################# -IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> +IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue) -> # Display the severity of Issue and you can edit it. # # Example: @@ -424,6 +428,26 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> }) $el.html(html) + save = $qqueue.bindAdd (severity) => + $.fn.popover().closeAll() + + issue = $model.$modelValue.clone() + issue.severity = severity + $model.$setViewValue(issue) + + onSuccess = -> + $confirm.notify("success") + $rootScope.$broadcast("history:reload") + $loading.finish($el.find(".level-name")) + onError = -> + $confirm.notify("error") + issue.revert() + $model.$setViewValue(issue) + $loading.finish($el.find(".level-name")) + $loading.start($el.find(".level-name")) + + $repo.save($model.$modelValue).then(onSuccess, onError) + $el.on "click", ".severity-data", (event) -> event.preventDefault() event.stopPropagation() @@ -437,26 +461,9 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> return if not isEditable() target = angular.element(event.currentTarget) + severity = target.data("severity-id") - $.fn.popover().closeAll() - - issue = $model.$modelValue.clone() - issue.severity = target.data("severity-id") - $model.$setViewValue(issue) - - $scope.$apply() - - onSuccess = -> - $confirm.notify("success") - $rootScope.$broadcast("history:reload") - $loading.finish($el.find(".level-name")) - onError = -> - $confirm.notify("error") - issue.revert() - $model.$setViewValue(issue) - $loading.finish($el.find(".level-name")) - $loading.start($el.find(".level-name")) - $repo.save($model.$modelValue).then(onSuccess, onError) + save(severity) $scope.$watch $attrs.ngModel, (issue) -> render(issue) if issue @@ -470,14 +477,14 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> require: "ngModel" } -module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssueSeverityButtonDirective]) +module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssueSeverityButtonDirective]) ############################################################################# ## Issue priority button directive ############################################################################# -IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> +IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue) -> # Display the priority of Issue and you can edit it. # # Example: @@ -518,6 +525,26 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> }) $el.html(html) + save = $qqueue.bindAdd (priority) => + $.fn.popover().closeAll() + + issue = $model.$modelValue.clone() + issue.priority = priority + $model.$setViewValue(issue) + + onSuccess = -> + $confirm.notify("success") + $rootScope.$broadcast("history:reload") + $loading.finish($el.find(".level-name")) + onError = -> + $confirm.notify("error") + issue.revert() + $model.$setViewValue(issue) + $loading.finish($el.find(".level-name")) + $loading.start($el.find(".level-name")) + + $repo.save($model.$modelValue).then(onSuccess, onError) + $el.on "click", ".priority-data", (event) -> event.preventDefault() event.stopPropagation() @@ -531,26 +558,9 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> return if not isEditable() target = angular.element(event.currentTarget) + priority = target.data("priority-id") - $.fn.popover().closeAll() - - issue = $model.$modelValue.clone() - issue.priority = target.data("priority-id") - $model.$setViewValue(issue) - - $scope.$apply() - - onSuccess = -> - $confirm.notify("success") - $rootScope.$broadcast("history:reload") - $loading.finish($el.find(".level-name")) - onError = -> - $confirm.notify("error") - issue.revert() - $model.$setViewValue(issue) - $loading.finish($el.find(".level-name")) - $loading.start($el.find(".level-name")) - $repo.save($model.$modelValue).then(onSuccess, onError) + save(priority) $scope.$watch $attrs.ngModel, (issue) -> render(issue) if issue @@ -564,14 +574,14 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) -> require: "ngModel" } -module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssuePriorityButtonDirective]) +module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssuePriorityButtonDirective]) ############################################################################# ## Promote Issue to US button directive ############################################################################# -PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) -> +PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue) -> template = _.template(""" Promote to User Story @@ -579,6 +589,30 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) -> """) # TODO: i18n link = ($scope, $el, $attrs, $model) -> + + save = $qqueue.bindAdd (issue, finish) => + data = { + generated_from_issue: issue.id + project: issue.project, + subject: issue.subject + description: issue.description + tags: issue.tags + is_blocked: issue.is_blocked + blocked_note: issue.blocked_note + } + + onSuccess = -> + finish() + $confirm.notify("success") + $rootScope.$broadcast("promote-issue-to-us:success") + + onError = -> + finish(false) + $confirm.notify("error") + + $repo.create("userstories", data).then(onSuccess, onError) + + $el.on "click", "a", (event) -> event.preventDefault() issue = $model.$modelValue @@ -588,26 +622,8 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) -> subtitle = issue.subject $confirm.ask(title, subtitle, message).then (finish) => - data = { - generated_from_issue: issue.id - project: issue.project, - subject: issue.subject - description: issue.description - tags: issue.tags - is_blocked: issue.is_blocked - blocked_note: issue.blocked_note - } + save(issue, finish) - onSuccess = -> - finish() - $confirm.notify("success") - $rootScope.$broadcast("promote-issue-to-us:success") - - onError = -> - finish(false) - $confirm.notify("error") - - $repo.create("userstories", data).then(onSuccess, onError) $scope.$on "$destroy", -> $el.off() @@ -619,5 +635,5 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) -> link: link } -module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", +module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgQqueue", PromoteIssueToUsButtonDirective]) diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee index 0dfef32a..0bbe2730 100644 --- a/app/coffee/modules/tasks/detail.coffee +++ b/app/coffee/modules/tasks/detail.coffee @@ -199,7 +199,7 @@ module.directive("tgTaskStatusDisplay", TaskStatusDisplayDirective) ## Task status button directive ############################################################################# -TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> +TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue) -> # Display the status of Task and you can edit it. # # Example: @@ -240,6 +240,26 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> }) $el.html(html) + save = $qqueue.bindAdd (status) => + task = $model.$modelValue.clone() + task.status = status + + $model.$setViewValue(task) + + onSuccess = -> + $confirm.notify("success") + $rootScope.$broadcast("history:reload") + $loading.finish($el.find(".level-name")) + + onError = -> + $confirm.notify("error") + task.revert() + $model.$setViewValue(task) + $loading.finish($el.find(".level-name")) + + $loading.start($el.find(".level-name")) + $repo.save($model.$modelValue).then(onSuccess, onError) + $el.on "click", ".status-data", (event) -> event.preventDefault() event.stopPropagation() @@ -256,25 +276,7 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> $.fn.popover().closeAll() - task = $model.$modelValue.clone() - task.status = target.data("status-id") - $model.$setViewValue(task) - - $scope.$apply() - - onSuccess = -> - $confirm.notify("success") - $rootScope.$broadcast("history:reload") - $loading.finish($el.find(".level-name")) - - onError = -> - $confirm.notify("error") - task.revert() - $model.$setViewValue(task) - $loading.finish($el.find(".level-name")) - - $loading.start($el.find(".level-name")) - $repo.save($model.$modelValue).then(onSuccess, onError) + save(target.data("status-id")) $scope.$watch $attrs.ngModel, (task) -> render(task) if task @@ -288,11 +290,11 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> require: "ngModel" } -module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", +module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", TaskStatusButtonDirective]) -TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -> +TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue) -> template = _.template("""