queue q promises

stable
Juanfran 2014-12-04 11:54:47 +01:00
parent a8caf6dae0
commit d6b7843875
10 changed files with 409 additions and 283 deletions

View File

@ -158,3 +158,32 @@ LimitLineLengthDirective = () ->
return {link:link} return {link:link}
module.directive("tgLimitLineLength", LimitLineLengthDirective) 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])

View File

@ -161,7 +161,7 @@ module.directive("tgCreatedByDisplay", CreatedByDisplayDirective)
## Watchers directive ## 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 # You have to include a div with the tg-lb-watchers directive in the page
# where use this directive # where use this directive
# #
@ -204,17 +204,37 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
isEditable = -> isEditable = ->
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 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 = $repo.save($model.$modelValue)
promise.then -> promise.then ->
$confirm.notify("success") $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) renderWatchers(watchers)
$rootscope.$broadcast("history:reload") $rootscope.$broadcast("history:reload")
promise.then null, -> promise.then null, ->
model.revert() item.revert()
$confirm.notify("error") $confirm.notify("error")
renderWatchers = (watchers) -> renderWatchers = (watchers) ->
ctx = { ctx = {
watchers: watchers watchers: watchers
@ -239,13 +259,11 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
$confirm.askOnDelete(title, message).then (finish) => $confirm.askOnDelete(title, message).then (finish) =>
finish() finish()
watcherIds = _.clone($model.$modelValue.watchers, false) watcherIds = _.clone($model.$modelValue.watchers, false)
watcherIds = _.pull(watcherIds, watcherId) watcherIds = _.pull(watcherIds, watcherId)
item = $model.$modelValue.clone() deleteWatcher(watcherIds)
item.watchers = watcherIds
$model.$setViewValue(item)
save(item)
$el.on "click", ".add-watcher", (event) -> $el.on "click", ".add-watcher", (event) ->
event.preventDefault() event.preventDefault()
@ -258,10 +276,7 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
watchers.push(watcherId) watchers.push(watcherId)
watchers = _.uniq(watchers) watchers = _.uniq(watchers)
item = $model.$modelValue.clone() save(watchers)
item.watchers = watchers
$model.$setViewValue(item)
save(item)
$scope.$watch $attrs.ngModel, (item) -> $scope.$watch $attrs.ngModel, (item) ->
return if not item? return if not item?
@ -273,14 +288,14 @@ WatchersDirective = ($rootscope, $confirm, $repo) ->
return {link:link, require:"ngModel"} return {link:link, require:"ngModel"}
module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", WatchersDirective]) module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQqueue", WatchersDirective])
############################################################################# #############################################################################
## Assigned to directive ## 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 # You have to include a div with the tg-lb-assignedto directive in the page
# where use this directive # where use this directive
# #
@ -315,20 +330,24 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
isEditable = -> isEditable = ->
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1
save = (model) -> save = $qqueue.bindAdd (userId) =>
$model.$modelValue.assigned_to = userId
$loading.start($el) $loading.start($el)
promise = $repo.save($model.$modelValue) promise = $repo.save($model.$modelValue)
promise.then -> promise.then ->
$loading.finish($el) $loading.finish($el)
$confirm.notify("success") $confirm.notify("success")
renderAssignedTo(model) renderAssignedTo($model.$modelValue)
$rootscope.$broadcast("history:reload") $rootscope.$broadcast("history:reload")
promise.then null, -> promise.then null, ->
model.revert() $model.$modelValue.revert()
$confirm.notify("error") $confirm.notify("error")
$loading.finish($el) $loading.finish($el)
return promise
renderAssignedTo = (issue) -> renderAssignedTo = (issue) ->
assignedToId = issue?.assigned_to assignedToId = issue?.assigned_to
assignedTo = if assignedToId? then $scope.usersById[assignedToId] else null assignedTo = if assignedToId? then $scope.usersById[assignedToId] else null
@ -354,12 +373,12 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
$confirm.ask(title).then (finish) => $confirm.ask(title).then (finish) =>
finish() finish()
$model.$modelValue.assigned_to = null $model.$modelValue.assigned_to = null
save($model.$modelValue) save(null)
$scope.$on "assigned-to:added", (ctx, userId, item) -> $scope.$on "assigned-to:added", (ctx, userId, item) ->
return if item.id != $model.$modelValue.id return if item.id != $model.$modelValue.id
$model.$modelValue.assigned_to = userId
save($model.$modelValue) save(userId)
$scope.$watch $attrs.ngModel, (instance) -> $scope.$watch $attrs.ngModel, (instance) ->
renderAssignedTo(instance) renderAssignedTo(instance)
@ -372,7 +391,7 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
require:"ngModel" 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 ## Editable subject directive
############################################################################# #############################################################################
EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) -> EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading, $qqueue) ->
template = """ template = """
<div class="view-subject"> <div class="view-subject">
{{ item.subject }} {{ item.subject }}
@ -492,9 +511,11 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) ->
isEditable = -> isEditable = ->
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1
save = -> save = $qqueue.bindAdd (subject) =>
$model.$modelValue.subject = $scope.item.subject $model.$modelValue.subject = subject
$loading.start($el.find('.save-container')) $loading.start($el.find('.save-container'))
promise = $repo.save($model.$modelValue) promise = $repo.save($model.$modelValue)
promise.then -> promise.then ->
$confirm.notify("success") $confirm.notify("success")
@ -506,6 +527,8 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) ->
promise.finally -> promise.finally ->
$loading.finish($el.find('.save-container')) $loading.finish($el.find('.save-container'))
return promise
$el.click -> $el.click ->
return if not isEditable() return if not isEditable()
$el.find('.edit-subject').show() $el.find('.edit-subject').show()
@ -513,11 +536,13 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) ->
$el.find('input').focus() $el.find('input').focus()
$el.on "click", ".save", -> $el.on "click", ".save", ->
save() subject = $scope.item.subject
save(subject)
$el.on "keyup", "input", (event) -> $el.on "keyup", "input", (event) ->
if event.keyCode == 13 if event.keyCode == 13
save() subject = $scope.item.subject
save(subject)
else if event.keyCode == 27 else if event.keyCode == 27
$model.$modelValue.revert() $model.$modelValue.revert()
$el.find('div.edit-subject').hide() $el.find('div.edit-subject').hide()
@ -545,7 +570,7 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading) ->
template: template template: template
} }
module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue",
EditableSubjectDirective]) EditableSubjectDirective])
@ -553,7 +578,7 @@ module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$
## Editable subject directive ## Editable subject directive
############################################################################# #############################################################################
EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText) -> EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText, $qqueue) ->
template = """ template = """
<div class="view-description"> <div class="view-description">
<section class="us-content wysiwyg" <section class="us-content wysiwyg"
@ -593,6 +618,21 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading,
isEditable = -> isEditable = ->
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 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) -> $el.on "mouseup", ".view-description", (event) ->
# We want to dettect the a inside the div so we use the target and # We want to dettect the a inside the div so we use the target and
# not the currentTarget # not the currentTarget
@ -606,19 +646,8 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading,
$el.find('textarea').focus() $el.find('textarea').focus()
$el.on "click", ".save", -> $el.on "click", ".save", ->
$model.$modelValue.description = $scope.item.description description = $scope.item.description
save(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 "keyup", "textarea", (event) -> $el.on "keyup", "textarea", (event) ->
if event.keyCode == 27 if event.keyCode == 27
@ -648,7 +677,7 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading,
} }
module.directive("tgEditableDescription", ["$rootScope", "$tgRepo", "$tgConfirm", module.directive("tgEditableDescription", ["$rootScope", "$tgRepo", "$tgConfirm",
"$compile", "$tgLoading", "$selectedText", EditableDescriptionDirective]) "$compile", "$tgLoading", "$selectedText", "$tgQqueue", EditableDescriptionDirective])
############################################################################# #############################################################################

View File

@ -165,7 +165,7 @@ module.directive("tgLbUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", LbU
## User story estimation directive ## User story estimation directive
############################################################################# #############################################################################
UsEstimationDirective = ($rootScope, $repo, $confirm) -> UsEstimationDirective = ($rootScope, $repo, $confirm, $qqueue) ->
# Display the points of a US and you can edit it. # Display the points of a US and you can edit it.
# #
# Example: # Example:
@ -264,6 +264,29 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
return _.reduce(notNullValues, (acc, num) -> acc + num) 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) -> $el.on "click", ".total.clickable", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -287,26 +310,7 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
roleId = target.data("role-id") roleId = target.data("role-id")
pointId = target.data("point-id") pointId = target.data("point-id")
$el.find(".popover").popover().close() save(roleId, pointId)
# 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)
$scope.$watch $attrs.ngModel, (us) -> $scope.$watch $attrs.ngModel, (us) ->
render(us) if us render(us) if us
@ -320,4 +324,4 @@ UsEstimationDirective = ($rootScope, $repo, $confirm) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", UsEstimationDirective]) module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgQqueue", UsEstimationDirective])

View File

@ -61,7 +61,7 @@ class HistoryController extends taiga.Controller
return @rs.history.undeleteComment(type, objectId, activityId).then => @.loadHistory(type, objectId) return @rs.history.undeleteComment(type, objectId, activityId).then => @.loadHistory(type, objectId)
HistoryDirective = ($log, $loading) -> HistoryDirective = ($log, $loading, $qqueue) ->
templateChangeDiff = _.template(""" templateChangeDiff = _.template("""
<div class="change-entry"> <div class="change-entry">
<div class="activity-changed"> <div class="activity-changed">
@ -436,6 +436,24 @@ HistoryDirective = ($log, $loading) ->
html = renderHistory(changes, totalChanges) html = renderHistory(changes, totalChanges)
$el.find(".changes-list").html(html) $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 # Watchers
$scope.$watch("comments", renderComments) $scope.$watch("comments", renderComments)
@ -447,22 +465,10 @@ HistoryDirective = ($log, $loading) ->
$el.on "click", ".add-comment a.button-green", debounce 2000, (event) -> $el.on "click", ".add-comment a.button-green", debounce 2000, (event) ->
event.preventDefault() event.preventDefault()
$scope.$broadcast("markdown-editor:submit")
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
$el.find(".comment-list").addClass("activeanimation") save(target)
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)
$el.on "click", ".show-more", (event) -> $el.on "click", ".show-more", (event) ->
event.preventDefault() event.preventDefault()
@ -526,4 +532,4 @@ HistoryDirective = ($log, $loading) ->
} }
module.directive("tgHistory", ["$log", "$tgLoading", HistoryDirective]) module.directive("tgHistory", ["$log", "$tgLoading", "$tgQqueue", HistoryDirective])

View File

@ -126,19 +126,11 @@ module.directive("lightbox", ["lightboxService", LightboxDirective])
# Issue/Userstory blocking message lightbox directive. # Issue/Userstory blocking message lightbox directive.
BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading) -> BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading, $qqueue) ->
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
$el.find("h2.title").text($attrs.title) $el.find("h2.title").text($attrs.title)
$scope.$on "block", -> unblock = $qqueue.bindAdd (item, finishCallback) =>
$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 = ""
promise = $tgrepo.save(item) promise = $tgrepo.save(item)
promise.then -> promise.then ->
$confirm.notify("success") $confirm.notify("success")
@ -154,15 +146,9 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi
promise.finally -> promise.finally ->
finishCallback() finishCallback()
$scope.$on "$destroy", -> return promise
$el.off()
$el.on "click", ".button-green", (event) -> block = $qqueue.bindAdd (item) =>
event.preventDefault()
item = $model.$modelValue.clone()
item.is_blocked = true
item.blocked_note = $el.find(".reason").val()
$model.$setViewValue(item) $model.$setViewValue(item)
$loading.start($el.find(".button-green")) $loading.start($el.find(".button-green"))
@ -181,13 +167,36 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi
$loading.finish($el.find(".button-green")) $loading.finish($el.find(".button-green"))
lightboxService.close($el) 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 { return {
templateUrl: "/partials/views/modules/lightbox-block.html" templateUrl: "/partials/views/modules/lightbox-block.html"
link: link link: link
require: "ngModel" require: "ngModel"
} }
module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", BlockLightboxDirective]) module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", "$tgQqueue", BlockLightboxDirective])
############################################################################# #############################################################################

View File

@ -228,7 +228,7 @@ module.directive("tgLbTagLine", ["$tgResources", LbTagLineDirective])
## TagLine Directive (for detail pages) ## TagLine Directive (for detail pages)
############################################################################# #############################################################################
TagLineDirective = ($rootScope, $repo, $rs, $confirm) -> TagLineDirective = ($rootScope, $repo, $rs, $confirm, $qqueue) ->
ENTER_KEY = 13 ENTER_KEY = 13
ESC_KEY = 27 ESC_KEY = 27
@ -288,7 +288,7 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) ->
$el.find("input").autocomplete("close") $el.find("input").autocomplete("close")
## Aux methods ## Aux methods
addValue = (value) -> addValue = $qqueue.bindAdd (value) ->
value = trim(value.toLowerCase()) value = trim(value.toLowerCase())
return if value.length == 0 return if value.length == 0
@ -308,7 +308,7 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) ->
$model.$setViewValue(model) $model.$setViewValue(model)
$repo.save(model).then(onSuccess, onError) $repo.save(model).then(onSuccess, onError)
deleteValue = (value) -> deleteValue = $qqueue.bindAdd (value) ->
value = trim(value.toLowerCase()) value = trim(value.toLowerCase())
return if value.length == 0 return if value.length == 0
@ -325,7 +325,8 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) ->
$confirm.notify("error") $confirm.notify("error")
model.revert() model.revert()
$model.$setViewValue(model) $model.$setViewValue(model)
$repo.save(model).then(onSuccess, onError)
return $repo.save(model).then(onSuccess, onError)
saveInputTag = () -> saveInputTag = () ->
value = $el.find("input").val() value = $el.find("input").val()
@ -369,6 +370,7 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) ->
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
value = target.siblings(".tag-name").text() value = target.siblings(".tag-name").text()
deleteValue(value) deleteValue(value)
bindOnce $scope, "project", (project) -> bindOnce $scope, "project", (project) ->
@ -415,4 +417,4 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm) ->
template: template template: template
} }
module.directive("tgTagLine", ["$rootScope", "$tgRepo", "$tgResources", "$tgConfirm", TagLineDirective]) module.directive("tgTagLine", ["$rootScope", "$tgRepo", "$tgResources", "$tgConfirm", "$tgQqueue", TagLineDirective])

View File

@ -195,7 +195,7 @@ module.directive("tgIssueStatusDisplay", IssueStatusDisplayDirective)
## Issue status button directive ## 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. # Display the status of Issue and you can edit it.
# #
# Example: # Example:
@ -236,6 +236,21 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
}) })
$el.html(html) $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) -> $el.on "click", ".status-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -256,20 +271,7 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
issue.status = target.data("status-id") issue.status = target.data("status-id")
$model.$setViewValue(issue) $model.$setViewValue(issue)
$scope.$apply() save($model.$modelValue, 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)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -283,13 +285,13 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssueStatusButtonDirective]) module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssueStatusButtonDirective])
############################################################################# #############################################################################
## Issue type button directive ## 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. # Display the type of Issue and you can edit it.
# #
# Example: # Example:
@ -330,6 +332,26 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
}) })
$el.html(html) $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) -> $el.on "click", ".type-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -343,26 +365,8 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
return if not isEditable() return if not isEditable()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
type = target.data("type-id")
$.fn.popover().closeAll() save(type)
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)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -376,14 +380,14 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssueTypeButtonDirective]) module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssueTypeButtonDirective])
############################################################################# #############################################################################
## Issue severity button directive ## 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. # Display the severity of Issue and you can edit it.
# #
# Example: # Example:
@ -424,6 +428,26 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
}) })
$el.html(html) $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) -> $el.on "click", ".severity-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -437,26 +461,9 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
return if not isEditable() return if not isEditable()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
severity = target.data("severity-id")
$.fn.popover().closeAll() save(severity)
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)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -470,14 +477,14 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", IssueSeverityButtonDirective]) module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", IssueSeverityButtonDirective])
############################################################################# #############################################################################
## Issue priority button directive ## 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. # Display the priority of Issue and you can edit it.
# #
# Example: # Example:
@ -518,6 +525,26 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
}) })
$el.html(html) $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) -> $el.on "click", ".priority-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -531,26 +558,9 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
return if not isEditable() return if not isEditable()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
priority = target.data("priority-id")
$.fn.popover().closeAll() save(priority)
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)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -564,14 +574,14 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
require: "ngModel" 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 ## Promote Issue to US button directive
############################################################################# #############################################################################
PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) -> PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue) ->
template = _.template(""" template = _.template("""
<a class="button button-gray editable" tg-check-permission="add_us"> <a class="button button-gray editable" tg-check-permission="add_us">
Promote to User Story Promote to User Story
@ -579,6 +589,30 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) ->
""") # TODO: i18n """) # TODO: i18n
link = ($scope, $el, $attrs, $model) -> 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) -> $el.on "click", "a", (event) ->
event.preventDefault() event.preventDefault()
issue = $model.$modelValue issue = $model.$modelValue
@ -588,26 +622,8 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) ->
subtitle = issue.subject subtitle = issue.subject
$confirm.ask(title, subtitle, message).then (finish) => $confirm.ask(title, subtitle, message).then (finish) =>
data = { save(issue, finish)
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)
$scope.$on "$destroy", -> $scope.$on "$destroy", ->
$el.off() $el.off()
@ -619,5 +635,5 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) ->
link: link link: link
} }
module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgQqueue",
PromoteIssueToUsButtonDirective]) PromoteIssueToUsButtonDirective])

View File

@ -199,7 +199,7 @@ module.directive("tgTaskStatusDisplay", TaskStatusDisplayDirective)
## Task status button directive ## 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. # Display the status of Task and you can edit it.
# #
# Example: # Example:
@ -240,6 +240,26 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
}) })
$el.html(html) $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) -> $el.on "click", ".status-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
@ -256,25 +276,7 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
$.fn.popover().closeAll() $.fn.popover().closeAll()
task = $model.$modelValue.clone() save(target.data("status-id"))
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)
$scope.$watch $attrs.ngModel, (task) -> $scope.$watch $attrs.ngModel, (task) ->
render(task) if task render(task) if task
@ -288,11 +290,11 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue",
TaskStatusButtonDirective]) TaskStatusButtonDirective])
TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -> TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue) ->
template = _.template(""" template = _.template("""
<fieldset title="Feeling a bit overwhelmed by a task? Make sure others know about it by clicking on Iocaine when editing a task. It's possible to become immune to this (fictional) deadly poison by consuming small amounts over time just as it's possible to get better at what you do by occasionally taking on extra challenges!"> <fieldset title="Feeling a bit overwhelmed by a task? Make sure others know about it by clicking on Iocaine when editing a task. It's possible to become immune to this (fictional) deadly poison by consuming small amounts over time just as it's possible to get better at what you do by occasionally taking on extra challenges!">
<label for="is-iocaine" <label for="is-iocaine"
@ -319,15 +321,15 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
html = template(ctx) html = template(ctx)
$el.html(html) $el.html(html)
$el.on "click", ".is-iocaine", (event) -> save = $qqueue.bindAdd (is_iocaine) =>
return if not isEditable()
task = $model.$modelValue.clone() task = $model.$modelValue.clone()
task.is_iocaine = not task.is_iocaine task.is_iocaine = is_iocaine
$model.$setViewValue(task) $model.$setViewValue(task)
$loading.start($el.find('label')) $loading.start($el.find('label'))
promise = $tgrepo.save($model.$modelValue) promise = $tgrepo.save(task)
promise.then -> promise.then ->
$confirm.notify("success") $confirm.notify("success")
$rootscope.$broadcast("history:reload") $rootscope.$broadcast("history:reload")
@ -340,6 +342,12 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
promise.finally -> promise.finally ->
$loading.finish($el.find('label')) $loading.finish($el.find('label'))
$el.on "click", ".is-iocaine", (event) ->
return if not isEditable()
is_iocaine = not $model.$modelValue.is_iocaine
save(is_iocaine)
$scope.$watch $attrs.ngModel, (task) -> $scope.$watch $attrs.ngModel, (task) ->
render(task) if task render(task) if task
@ -352,4 +360,4 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", TaskIsIocaineButtonDirective]) module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", TaskIsIocaineButtonDirective])

View File

@ -259,7 +259,7 @@ module.directive("tgUsTasksProgressDisplay", UsTasksProgressDisplayDirective)
## User story status button directive ## User story status button directive
############################################################################# #############################################################################
UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) -> UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue) ->
# Display the status of a US and you can edit it. # Display the status of a US and you can edit it.
# #
# Example: # Example:
@ -300,28 +300,15 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
}) })
$el.html(html) $el.html(html)
$el.on "click", ".status-data", (event) ->
event.preventDefault()
event.stopPropagation()
return if not isEditable()
$el.find(".pop-status").popover().open() save = $qqueue.bindAdd (status) =>
us = $model.$modelValue.clone()
$el.on "click", ".status", (event) -> us.status = status
event.preventDefault()
event.stopPropagation()
return if not isEditable()
target = angular.element(event.currentTarget)
$.fn.popover().closeAll() $.fn.popover().closeAll()
us = $model.$modelValue.clone()
us.status = target.data("status-id")
$model.$setViewValue(us) $model.$setViewValue(us)
$scope.$apply()
onSuccess = -> onSuccess = ->
$confirm.notify("success") $confirm.notify("success")
$rootScope.$broadcast("history:reload") $rootScope.$broadcast("history:reload")
@ -334,8 +321,26 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
$loading.finish($el.find(".level-name")) $loading.finish($el.find(".level-name"))
$loading.start($el.find(".level-name")) $loading.start($el.find(".level-name"))
$repo.save($model.$modelValue).then(onSuccess, onError) $repo.save($model.$modelValue).then(onSuccess, onError)
$el.on "click", ".status-data", (event) ->
event.preventDefault()
event.stopPropagation()
return if not isEditable()
$el.find(".pop-status").popover().open()
$el.on "click", ".status", (event) ->
event.preventDefault()
event.stopPropagation()
return if not isEditable()
target = angular.element(event.currentTarget)
status = target.data("status-id")
save(status)
$scope.$watch $attrs.ngModel, (us) -> $scope.$watch $attrs.ngModel, (us) ->
render(us) if us render(us) if us
@ -348,7 +353,7 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading","$tgQqueue",
UsStatusButtonDirective]) UsStatusButtonDirective])
@ -356,7 +361,7 @@ module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$t
## User story team requirements button directive ## User story team requirements button directive
############################################################################# #############################################################################
UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -> UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue) ->
template = _.template(""" template = _.template("""
<label for="team-requirement" <label for="team-requirement"
class="button button-gray team-requirement <% if(canEdit){ %>editable<% }; %> <% if(isRequired){ %>active<% }; %>"> class="button button-gray team-requirement <% if(canEdit){ %>editable<% }; %> <% if(isRequired){ %>active<% }; %>">
@ -381,24 +386,32 @@ UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
html = template(ctx) html = template(ctx)
$el.html(html) $el.html(html)
$el.on "click", ".team-requirement", (event) -> save = $qqueue.bindAdd (team_requirement) =>
return if not canEdit()
us = $model.$modelValue.clone() us = $model.$modelValue.clone()
us.team_requirement = not us.team_requirement us.team_requirement = team_requirement
$model.$setViewValue(us) $model.$setViewValue(us)
$loading.start($el.find("label")) $loading.start($el.find("label"))
promise = $tgrepo.save($model.$modelValue) promise = $tgrepo.save($model.$modelValue)
promise.then => promise.then =>
$loading.finish($el.find("label")) $loading.finish($el.find("label"))
$rootscope.$broadcast("history:reload") $rootscope.$broadcast("history:reload")
promise.then null, -> promise.then null, ->
$loading.finish($el.find("label")) $loading.finish($el.find("label"))
$confirm.notify("error") $confirm.notify("error")
us.revert() us.revert()
$model.$setViewValue(us) $model.$setViewValue(us)
$el.on "click", ".team-requirement", (event) ->
return if not canEdit()
team_requirement = not $model.$modelValue.team_requirement
save(team_requirement)
$scope.$watch $attrs.ngModel, (us) -> $scope.$watch $attrs.ngModel, (us) ->
render(us) if us render(us) if us
@ -411,13 +424,13 @@ UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgUsTeamRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", UsTeamRequirementButtonDirective]) module.directive("tgUsTeamRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", UsTeamRequirementButtonDirective])
############################################################################# #############################################################################
## User story client requirements button directive ## User story client requirements button directive
############################################################################# #############################################################################
UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -> UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue) ->
template = _.template(""" template = _.template("""
<label for="client-requirement" <label for="client-requirement"
class="button button-gray client-requirement <% if(canEdit){ %>editable<% }; %> <% if(isRequired){ %>active<% }; %>"> class="button button-gray client-requirement <% if(canEdit){ %>editable<% }; %> <% if(isRequired){ %>active<% }; %>">
@ -442,11 +455,10 @@ UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -
html = template(ctx) html = template(ctx)
$el.html(html) $el.html(html)
$el.on "click", ".client-requirement", (event) -> save = $qqueue.bindAdd (client_requirement) =>
return if not canEdit()
us = $model.$modelValue.clone() us = $model.$modelValue.clone()
us.client_requirement = not us.client_requirement us.client_requirement = client_requirement
$model.$setViewValue(us) $model.$setViewValue(us)
$loading.start($el.find("label")) $loading.start($el.find("label"))
@ -460,6 +472,12 @@ UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -
us.revert() us.revert()
$model.$setViewValue(us) $model.$setViewValue(us)
$el.on "click", ".client-requirement", (event) ->
return if not canEdit()
client_requirement = not $model.$modelValue.client_requirement
save(client_requirement)
$scope.$watch $attrs.ngModel, (us) -> $scope.$watch $attrs.ngModel, (us) ->
render(us) if us render(us) if us
@ -472,5 +490,5 @@ UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -
require: "ngModel" require: "ngModel"
} }
module.directive("tgUsClientRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", module.directive("tgUsClientRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue",
UsClientRequirementButtonDirective]) UsClientRequirementButtonDirective])

View File

@ -212,7 +212,7 @@ module.directive("tgWikiSummary", ["$log", WikiSummaryDirective])
############################################################################# #############################################################################
EditableWikiContentDirective = ($window, $document, $repo, $confirm, $loading, $location, $navUrls, EditableWikiContentDirective = ($window, $document, $repo, $confirm, $loading, $location, $navUrls,
$analytics) -> $analytics, $qqueue) ->
template = """ template = """
<div class="view-wiki-content"> <div class="view-wiki-content">
<section class="wysiwyg" tg-bind-html="wiki.html"></section> <section class="wysiwyg" tg-bind-html="wiki.html"></section>
@ -265,6 +265,29 @@ EditableWikiContentDirective = ($window, $document, $repo, $confirm, $loading, $
return $document.selection.createRange().text return $document.selection.createRange().text
return null return null
save = $qqueue.bindAdd (wiki) ->
onSuccess = (wikiPage) ->
if not wiki.id?
$analytics.trackEvent("wikipage", "create", "create wiki page", 1)
$scope.wiki = wikiPage
$model.setModelValue = wiki
$confirm.notify("success")
switchToReadMode()
onError = ->
$confirm.notify("error")
$loading.start($el.find('.save-container'))
if wiki.id?
promise = $repo.save(wiki).then(onSuccess, onError)
else
promise = $repo.create("wiki", wiki).then(onSuccess, onError)
promise.finally ->
$loading.finish($el.find('.save-container'))
$el.on "mouseup", ".view-wiki-content", (event) -> $el.on "mouseup", ".view-wiki-content", (event) ->
# We want to dettect the a inside the div so we use the target and # We want to dettect the a inside the div so we use the target and
# not the currentTarget # not the currentTarget
@ -275,25 +298,7 @@ EditableWikiContentDirective = ($window, $document, $repo, $confirm, $loading, $
switchToEditMode() switchToEditMode()
$el.on "click", ".save", debounce 2000, -> $el.on "click", ".save", debounce 2000, ->
onSuccess = (wikiPage) -> save($scope.wiki)
if not $scope.wiki.id?
$analytics.trackEvent("wikipage", "create", "create wiki page", 1)
$scope.wiki = wikiPage
$model.setModelValue = $scope.wiki
$confirm.notify("success")
switchToReadMode()
onError = ->
$confirm.notify("error")
$loading.start($el.find('.save-container'))
if $scope.wiki.id?
promise = $repo.save($scope.wiki).then(onSuccess, onError)
else
promise = $repo.create("wiki", $scope.wiki).then(onSuccess, onError)
promise.finally ->
$loading.finish($el.find('.save-container'))
$el.on "click", ".cancel", -> $el.on "click", ".cancel", ->
cancelEdition() cancelEdition()
@ -324,5 +329,5 @@ EditableWikiContentDirective = ($window, $document, $repo, $confirm, $loading, $
} }
module.directive("tgEditableWikiContent", ["$window", "$document", "$tgRepo", "$tgConfirm", "$tgLoading", module.directive("tgEditableWikiContent", ["$window", "$document", "$tgRepo", "$tgConfirm", "$tgLoading",
"$tgLocation", "$tgNavUrls", "$tgAnalytics", "$tgLocation", "$tgNavUrls", "$tgAnalytics", "$tgQqueue",
EditableWikiContentDirective]) EditableWikiContentDirective])