diff --git a/app/coffee/modules/resources/projects.coffee b/app/coffee/modules/resources/projects.coffee
index ecffdd09..ab506262 100644
--- a/app/coffee/modules/resources/projects.coffee
+++ b/app/coffee/modules/resources/projects.coffee
@@ -22,7 +22,7 @@
taiga = @.taiga
-resourceProvider = ($repo) ->
+resourceProvider = ($repo, $http, $urls) ->
service = {}
service.get = (id) ->
@@ -46,7 +46,8 @@ resourceProvider = ($repo) ->
return $repo.queryOneRaw("projects", "#{projectId}/stats")
service.leave = (projectId) ->
- return $repo.queryOneRaw("projects", "#{projectId}/leave")
+ url = "#{$urls.resolve("projects")}/#{projectId}/leave"
+ return $http.post(url)
service.memberStats = (projectId) ->
return $repo.queryOneRaw("projects", "#{projectId}/member_stats")
@@ -59,4 +60,4 @@ resourceProvider = ($repo) ->
module = angular.module("taigaResources")
-module.factory("$tgProjectsResourcesProvider", ["$tgRepo", resourceProvider])
+module.factory("$tgProjectsResourcesProvider", ["$tgRepo", "$tgHttp", "$tgUrls", resourceProvider])
diff --git a/app/coffee/modules/team/main.coffee b/app/coffee/modules/team/main.coffee
index f5fdf26a..f91d6ec3 100644
--- a/app/coffee/modules/team/main.coffee
+++ b/app/coffee/modules/team/main.coffee
@@ -32,6 +32,7 @@ module = angular.module("taigaTeam")
class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
@.$inject = [
"$scope",
+ "$rootScope",
"$tgRepo",
"$tgResources",
"$routeParams",
@@ -41,7 +42,7 @@ class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgLoader"
]
- constructor: (@scope, @repo, @rs, @params, @q, @appTitle, @auth, tgLoader) ->
+ constructor: (@scope, @rootscope, @repo, @rs, @params, @q, @appTitle, @auth, tgLoader) ->
@scope.sectionName = "Team"
promise = @.loadInitialData()
@@ -55,6 +56,12 @@ class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
# On Error
promise.then null, @.onInitialDataError.bind(@)
+<<<<<<< HEAD
+=======
+ @scope.currentUser = @auth.getUser()
+ @scope.projectId = @rootscope.projectId
+
+>>>>>>> Allowing leave project
setRole: (role) ->
if role
@scope.filtersRole = role
@@ -190,7 +197,7 @@ TeamMemberCurrentUserDirective = () ->
-
+
@@ -200,6 +207,7 @@ TeamMemberCurrentUserDirective = () ->
return {
template: template
scope: {
+ projectId: "=projectid",
currentUser: "=currentuser",
stats: "="
}
@@ -242,22 +250,32 @@ module.directive("tgTeamMembers", TeamMembersDirective)
## Leave project Directive
#############################################################################
-LeaveProjectDirective = ($repo, $confirm, $location) ->
+LeaveProjectDirective = ($repo, $confirm, $location, $rs, $navurls) ->
template= """
Leave this project
""" #TODO: i18n
- link = ($scope) ->
+ link = ($scope, $el, $attrs) ->
$scope.leave = () ->
- $confirm.ask("Leave this project", "Are you sure you want to leave the project?")#TODO: i18n
- .then (finish) =>
- console.log "TODO"
+ #TODO: i18n
+ $confirm.ask("Leave this project", "Are you sure you want to leave the project?").then (finish) =>
+ promise = $rs.projects.leave($attrs.projectid)
+
+ promise.then =>
+ finish()
+ $confirm.notify("success")
+ $location.path($navurls.resolve("home"))
+
+ promise.then null, (response) ->
+ finish()
+ $confirm.notify('error', response.data._error_message)
+
return {
scope: {},
template: template,
link: link
}
-module.directive("tgLeaveProject", ["$tgRepo", "$tgConfirm", "$tgLocation", LeaveProjectDirective])
+module.directive("tgLeaveProject", ["$tgRepo", "$tgConfirm", "$tgLocation", "$tgResources", "$tgNavUrls", LeaveProjectDirective])
diff --git a/app/partials/views/modules/team/team-table.jade b/app/partials/views/modules/team/team-table.jade
index eb2bc4c5..e4494541 100644
--- a/app/partials/views/modules/team/team-table.jade
+++ b/app/partials/views/modules/team/team-table.jade
@@ -26,7 +26,7 @@ section.table-team.basic-table
div.popover.attribute-explanation
span How far did you go into this Taiga?
- div.hero(tg-team-current-user, stats="stats", currentuser="currentUser")
+ div.hero(tg-team-current-user, stats="stats", currentuser="currentUser", projectid="projectId")
h2
span Team >