diff --git a/app/coffee/modules/common/lightboxes.coffee b/app/coffee/modules/common/lightboxes.coffee index 5db4e843..00a1c86e 100644 --- a/app/coffee/modules/common/lightboxes.coffee +++ b/app/coffee/modules/common/lightboxes.coffee @@ -697,3 +697,15 @@ AttachmentPreviewLightboxDirective = (lightboxService, $template, $compile) -> } module.directive("tgLbAttachmentPreview", ["lightboxService", "$tgTemplate", "$compile", AttachmentPreviewLightboxDirective]) + +LightboxLeaveProjectWarningDirective = (lightboxService, $template, $compile) -> + link = ($scope, $el, attrs) -> + lightboxService.open($el) + + return { + templateUrl: 'common/lightbox/lightbox-leave-project-warning.html', + link: link, + scope: true + } + +module.directive("tgLightboxLeaveProjectWarning", ["lightboxService", LightboxLeaveProjectWarningDirective]) diff --git a/app/coffee/modules/team/main.coffee b/app/coffee/modules/team/main.coffee index b74006f4..68e3858d 100644 --- a/app/coffee/modules/team/main.coffee +++ b/app/coffee/modules/team/main.coffee @@ -184,7 +184,7 @@ TeamMemberCurrentUserDirective = () -> return { templateUrl: "team/team-member-current-user.html" scope: { - projectId: "=projectid", + project: "=project", currentUser: "=currentuser", stats: "=", issuesEnabled: "=issuesenabled", @@ -225,14 +225,14 @@ module.directive("tgTeamMembers", TeamMembersDirective) ## Leave project Directive ############################################################################# -LeaveProjectDirective = ($repo, $confirm, $location, $rs, $navurls, $translate) -> +LeaveProjectDirective = ($repo, $confirm, $location, $rs, $navurls, $translate, lightboxFactory, currentUserService) -> link = ($scope, $el, $attrs) -> - $scope.leave = () -> + leaveConfirm = () -> leave_project_text = $translate.instant("TEAM.ACTION_LEAVE_PROJECT") confirm_leave_project_text = $translate.instant("TEAM.CONFIRM_LEAVE_PROJECT") $confirm.ask(leave_project_text, confirm_leave_project_text).then (response) => - promise = $rs.projects.leave($attrs.projectid) + promise = $rs.projects.leave($scope.project.id) promise.then => response.finish() @@ -243,13 +243,29 @@ LeaveProjectDirective = ($repo, $confirm, $location, $rs, $navurls, $translate) response.finish() $confirm.notify('error', response.data._error_message) + $scope.leave = () -> + if $scope.project.owner.id == $scope.user.id + currentUser = currentUserService.getUser() + + lightboxFactory.create("tg-lightbox-leave-project-warning", { + class: "lightbox lightbox-leave-project-warning" + }, { + currentUser: true, + project: $scope.project + }) + else + leaveConfirm() + return { - scope: {}, + scope: { + user: "=", + project: "=" + }, templateUrl: "team/leave-project.html", link: link } -module.directive("tgLeaveProject", ["$tgRepo", "$tgConfirm", "$tgLocation", "$tgResources", "$tgNavUrls", "$translate", +module.directive("tgLeaveProject", ["$tgRepo", "$tgConfirm", "$tgLocation", "$tgResources", "$tgNavUrls", "$translate", "tgLightboxFactory", "tgCurrentUserService", LeaveProjectDirective]) diff --git a/app/locales/taiga/locale-en.json b/app/locales/taiga/locale-en.json index 06645a6b..8bd9721b 100644 --- a/app/locales/taiga/locale-en.json +++ b/app/locales/taiga/locale-en.json @@ -919,6 +919,17 @@ "CREATE_MEMBER": { "PLACEHOLDER_INVITATION_TEXT": "(Optional) Add a personalized text to the invitation. Tell something lovely to your new members ;-)", "PLACEHOLDER_TYPE_EMAIL": "Type an Email" + }, + "LEAVE_PROJECT_WARNING": { + "TITLE": "You can not leave the project without owner", + "CURRENT_USER_OWNER": { + "DESC": "You are the project owner before leaving it you must pass the property to someone else.", + "BUTTON": "Change the project owner" + }, + "OTHER_USER_OWNER": { + "DESC": "You can't delete the project owner, you must request a new owner before deleting the user.", + "BUTTON": "Request change project owner" + } } }, "US": { diff --git a/app/partials/common/lightbox/lightbox-leave-project-warning.jade b/app/partials/common/lightbox/lightbox-leave-project-warning.jade new file mode 100644 index 00000000..06ce8158 --- /dev/null +++ b/app/partials/common/lightbox/lightbox-leave-project-warning.jade @@ -0,0 +1,19 @@ +svg.close.icon.icon-close(href="", title="{{'COMMON.CLOSE' | translate}}") + use(xlink:href="#icon-close") +div.content + svg.icon.icon-exclamation + use(xlink:href="#icon-exclamation") + + h2.title {{'LIGHTBOX.LEAVE_PROJECT_WARNING.TITLE' | translate}} + + div(ng-if="currentUser") + p {{'LIGHTBOX.LEAVE_PROJECT_WARNING.CURRENT_USER_OWNER.DESC' | translate}} + + a.button-green(tg-nav="project-admin-home:project=project.slug", href="") + span(translate="LIGHTBOX.LEAVE_PROJECT_WARNING.CURRENT_USER_OWNER.BUTTON") + + div(ng-if="!currentUser") + p {{'LIGHTBOX.LEAVE_PROJECT_WARNING.OTHER_USER_OWNER.DESC' | translate}} + + a.button-green(tg-nav="project-admin-home:project=project.slug", href="") + span(translate="LIGHTBOX.LEAVE_PROJECT_WARNING.OTHER_USER_OWNER.BUTTON") \ No newline at end of file diff --git a/app/partials/includes/modules/team/team-table.jade b/app/partials/includes/modules/team/team-table.jade index 0f9ac475..b8500578 100644 --- a/app/partials/includes/modules/team/team-table.jade +++ b/app/partials/includes/modules/team/team-table.jade @@ -31,7 +31,7 @@ section.table-team.basic-table tg-team-current-user stats="stats" currentuser="currentUser" - projectid="projectId" + project="project" issuesEnabled="issuesEnabled" tasksenabled="tasksEnabled" wikienabled="wikiEnabled" diff --git a/app/partials/team/team-member-current-user.jade b/app/partials/team/team-member-current-user.jade index 623c936c..1c425a44 100644 --- a/app/partials/team/team-member-current-user.jade +++ b/app/partials/team/team-member-current-user.jade @@ -12,7 +12,7 @@ .position(tg-bo-bind="currentUser.role_name") - div(tg-leave-project="", projectid="{{projectId}}") + div(tg-leave-project="", project="project", user="currentUser") .member-stats( tg-team-member-stats diff --git a/app/styles/modules/common/lightbox.scss b/app/styles/modules/common/lightbox.scss index 994ce2a4..a3b0d9ac 100644 --- a/app/styles/modules/common/lightbox.scss +++ b/app/styles/modules/common/lightbox.scss @@ -552,3 +552,16 @@ height: 5rem; } } + +.lightbox-leave-project-warning { + text-align: center; + .icon { + fill: $gray-light; + height: 3rem; + margin-bottom: 1rem; + width: 3rem; + } + .content { + width: 500px; + } +}