Bootstrap AssignedUsersDirective
parent
c36ee218d2
commit
cea62718b3
|
@ -299,6 +299,108 @@ module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQueue
|
||||||
"$translate", WatchersDirective])
|
"$translate", WatchersDirective])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## Assigned Users directive
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
AssignedUsersDirective = ($rootscope, $confirm, $repo, $modelTransform, $template, $compile, $translate) ->
|
||||||
|
# You have to include a div with the tg-lb-assignedusers directive in the page
|
||||||
|
# where use this directive
|
||||||
|
|
||||||
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
isEditable = ->
|
||||||
|
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1
|
||||||
|
isAssigned = ->
|
||||||
|
return $scope.assignedUsers.length > 0
|
||||||
|
|
||||||
|
save = (assignedUsers) ->
|
||||||
|
transform = $modelTransform.save (item) ->
|
||||||
|
item.assignedUsers = assignedUsers
|
||||||
|
return item
|
||||||
|
|
||||||
|
transform.then ->
|
||||||
|
console.log(assignedUserId)
|
||||||
|
assignedUsers = _.map(assignedUsers, (assignedUserId) -> $scope.usersById[assignedUserId])
|
||||||
|
renderAssignedUsers(assignedUsers)
|
||||||
|
$rootscope.$broadcast("object:updated")
|
||||||
|
|
||||||
|
transform.then null, ->
|
||||||
|
$confirm.notify("error")
|
||||||
|
|
||||||
|
openAssignedUsers = ->
|
||||||
|
item = _.clone($model.$modelValue, false)
|
||||||
|
$rootscope.$broadcast("assignedUser:add", item)
|
||||||
|
|
||||||
|
deleteAssignedUser = (assignedUserIds) ->
|
||||||
|
transform = $modelTransform.save (item) ->
|
||||||
|
item.assignedUsers = assignedUserIds
|
||||||
|
|
||||||
|
return item
|
||||||
|
|
||||||
|
transform.then () ->
|
||||||
|
item = $modelTransform.getObj()
|
||||||
|
assignedUsers = _.map(item.assignedUsers, (assignedUserId) -> $scope.usersById[assignedUserId])
|
||||||
|
renderAssignedUsers(assignedUsers)
|
||||||
|
$rootscope.$broadcast("object:updated")
|
||||||
|
|
||||||
|
transform.then null, ->
|
||||||
|
item.revert()
|
||||||
|
$confirm.notify("error")
|
||||||
|
|
||||||
|
renderAssignedUsers = (assignedUsers) ->
|
||||||
|
$scope.assignedUsers = assignedUsers
|
||||||
|
$scope.isEditable = isEditable()
|
||||||
|
$scope.isAssigned = isAssigned()
|
||||||
|
$scope.openAssignedUsers = openAssignedUsers
|
||||||
|
console.log('rendering...')
|
||||||
|
|
||||||
|
$el.on "click", ".js-delete-watcher", (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
return if not isEditable()
|
||||||
|
target = angular.element(event.currentTarget)
|
||||||
|
watcherId = target.data("watcher-id")
|
||||||
|
|
||||||
|
title = $translate.instant("COMMON.WATCHERS.TITLE_LIGHTBOX_DELETE_WARTCHER")
|
||||||
|
message = $scope.usersById[watcherId].full_name_display
|
||||||
|
|
||||||
|
$confirm.askOnDelete(title, message).then (askResponse) =>
|
||||||
|
askResponse.finish()
|
||||||
|
|
||||||
|
watcherIds = _.clone($model.$modelValue.watchers, false)
|
||||||
|
watcherIds = _.pull(watcherIds, watcherId)
|
||||||
|
|
||||||
|
deleteWatcher(watcherIds)
|
||||||
|
|
||||||
|
$scope.$on "assignedUser:added", (ctx, assignedUserId) ->
|
||||||
|
|
||||||
|
assignedUsers = _.clone($model.$modelValue.assigned_users, false)
|
||||||
|
assignedUsers.push(assignedUserId)
|
||||||
|
assignedUsers = _.uniq(assignedUsers)
|
||||||
|
|
||||||
|
save(assignedUsers)
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (item) ->
|
||||||
|
return if not item?
|
||||||
|
assignedUsers = _.map(item.assigned_users, (assignedUserId) -> $scope.usersById[assignedUserId])
|
||||||
|
assignedUsers = _.filter assignedUsers, (it) -> return !!it
|
||||||
|
|
||||||
|
renderAssignedUsers(assignedUsers)
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
|
return {
|
||||||
|
scope: true,
|
||||||
|
templateUrl: "common/components/assigned-users.html",
|
||||||
|
link:link,
|
||||||
|
require:"ngModel"
|
||||||
|
}
|
||||||
|
|
||||||
|
module.directive("tgAssignedUsers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQueueModelTransformation", "$tgTemplate", "$compile",
|
||||||
|
"$translate", AssignedUsersDirective])
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Assigned to directive
|
## Assigned to directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
|
@ -693,10 +693,104 @@ AssignedToLightboxDirective = (lightboxService, lightboxKeyboardNavigationServic
|
||||||
link:link
|
link:link
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.directive("tgLbAssignedto", ["lightboxService", "lightboxKeyboardNavigationService", "$tgTemplate", "$compile", "tgAvatarService", AssignedToLightboxDirective])
|
module.directive("tgLbAssignedto", ["lightboxService", "lightboxKeyboardNavigationService", "$tgTemplate", "$compile", "tgAvatarService", AssignedToLightboxDirective])
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## Assigned Users Lightbox directive
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
AssignedUsersLightboxDirective = ($repo, lightboxService, lightboxKeyboardNavigationService, $template, $compile, avatarService) ->
|
||||||
|
link = ($scope, $el, $attrs) ->
|
||||||
|
selectedItem = null
|
||||||
|
usersTemplate = $template.get("common/lightbox/lightbox-assigned-to-users.html", true)
|
||||||
|
|
||||||
|
# Get prefiltered users by text
|
||||||
|
# and without now watched users.
|
||||||
|
getFilteredUsers = (text="") ->
|
||||||
|
_filterUsers = (text, user) ->
|
||||||
|
if selectedItem && _.find(selectedItem.assignedUsers, (x) -> x == user.id)
|
||||||
|
return false
|
||||||
|
|
||||||
|
username = user.full_name_display.toUpperCase()
|
||||||
|
text = text.toUpperCase()
|
||||||
|
return _.includes(username, text)
|
||||||
|
|
||||||
|
users = _.clone($scope.activeUsers, true)
|
||||||
|
users = _.filter(users, _.partial(_filterUsers, text))
|
||||||
|
return users
|
||||||
|
|
||||||
|
# Render the specific list of users.
|
||||||
|
render = (users) ->
|
||||||
|
visibleUsers = _.slice(users, 0, 5)
|
||||||
|
|
||||||
|
visibleUsers = _.map visibleUsers, (user) ->
|
||||||
|
user.avatar = avatarService.getAvatar(user)
|
||||||
|
|
||||||
|
return user
|
||||||
|
|
||||||
|
ctx = {
|
||||||
|
selected: false
|
||||||
|
users: visibleUsers
|
||||||
|
showMore: users.length > 5
|
||||||
|
}
|
||||||
|
|
||||||
|
html = usersTemplate(ctx)
|
||||||
|
html = $compile(html)($scope)
|
||||||
|
$el.find(".ticket-watchers").html(html)
|
||||||
|
|
||||||
|
closeLightbox = () ->
|
||||||
|
lightboxKeyboardNavigationService.stop()
|
||||||
|
lightboxService.close($el)
|
||||||
|
|
||||||
|
$scope.$on "assignedUser:add", (ctx, item) ->
|
||||||
|
console.log(item)
|
||||||
|
selectedItem = item
|
||||||
|
|
||||||
|
users = getFilteredUsers()
|
||||||
|
render(users)
|
||||||
|
|
||||||
|
lightboxService.open($el).then ->
|
||||||
|
$el.find("input").focus()
|
||||||
|
lightboxKeyboardNavigationService.init($el)
|
||||||
|
|
||||||
|
$scope.$watch "usersSearch", (searchingText) ->
|
||||||
|
if not searchingText?
|
||||||
|
return
|
||||||
|
|
||||||
|
users = getFilteredUsers(searchingText)
|
||||||
|
render(users)
|
||||||
|
$el.find("input").focus()
|
||||||
|
|
||||||
|
$el.on "click", ".user-list-single", debounce 200, (event) ->
|
||||||
|
closeLightbox()
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
target = angular.element(event.currentTarget)
|
||||||
|
|
||||||
|
$scope.$apply ->
|
||||||
|
$scope.usersSearch = null
|
||||||
|
$scope.$broadcast("assignedUser:added", target.data("user-id"))
|
||||||
|
|
||||||
|
$el.on "click", ".close", (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
closeLightbox()
|
||||||
|
|
||||||
|
$scope.$apply ->
|
||||||
|
$scope.usersSearch = null
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
|
return {
|
||||||
|
templateUrl: "common/lightbox/lightbox-users.html"
|
||||||
|
link:link
|
||||||
|
}
|
||||||
|
|
||||||
|
module.directive("tgLbAssignedUsers", ["$tgRepo", "lightboxService", "lightboxKeyboardNavigationService", "$tgTemplate", "$compile", "tgAvatarService", AssignedUsersLightboxDirective])
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Watchers Lightbox directive
|
## Watchers Lightbox directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
|
@ -101,6 +101,12 @@ div.wrapper(
|
||||||
required-perm="modify_us"
|
required-perm="modify_us"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
section.ticket-assigned-users(
|
||||||
|
tg-assigned-users
|
||||||
|
ng-model="us"
|
||||||
|
required-perm="modify_us"
|
||||||
|
)
|
||||||
|
|
||||||
section.ticket-watch-buttons
|
section.ticket-watch-buttons
|
||||||
div.ticket-watch(
|
div.ticket-watch(
|
||||||
tg-watch-button
|
tg-watch-button
|
||||||
|
@ -154,4 +160,5 @@ div.wrapper(
|
||||||
ng-model="us"
|
ng-model="us"
|
||||||
)
|
)
|
||||||
div.lightbox.lightbox-select-user(tg-lb-assignedto)
|
div.lightbox.lightbox-select-user(tg-lb-assignedto)
|
||||||
|
div.lightbox.lightbox-select-user(tg-lb-assigned-users)
|
||||||
div.lightbox.lightbox-select-user(tg-lb-watchers)
|
div.lightbox.lightbox-select-user(tg-lb-watchers)
|
||||||
|
|
Loading…
Reference in New Issue