From f6b1666cd7f349ad4c49486e8dcc7e5b619fbca3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Apr 2017 10:07:16 -0400 Subject: [PATCH] leave organization --- src/app/services/apiService.js | 1 + src/app/settings/settingsController.js | 26 +++++++++++++++++++++++++ src/app/settings/views/settings.html | 27 +++++++++++++++++++------- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index c902b9fc..979bfe42 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -44,6 +44,7 @@ putUpgrade: { url: _apiUri + '/organizations/:id/upgrade', method: 'POST', params: { id: '@id' } }, putCancel: { url: _apiUri + '/organizations/:id/cancel', method: 'POST', params: { id: '@id' } }, putReinstate: { url: _apiUri + '/organizations/:id/reinstate', method: 'POST', params: { id: '@id' } }, + postLeave: { url: _apiUri + '/organizations/:id/leave', method: 'POST', params: { id: '@id' } }, del: { url: _apiUri + '/organizations/:id/delete', method: 'POST', params: { id: '@id' } } }); diff --git a/src/app/settings/settingsController.js b/src/app/settings/settingsController.js index 279d88d8..474fb57c 100644 --- a/src/app/settings/settingsController.js +++ b/src/app/settings/settingsController.js @@ -76,6 +76,7 @@ $scope.viewOrganization = function (org) { if (org.type === 2) { // 2 = User + scrollToTop(); toastr.error('You cannot manage this organization.'); return; } @@ -83,6 +84,27 @@ $state.go('backend.org.dashboard', { orgId: org.id }); }; + $scope.leaveOrganization = function (org) { + if (!confirm('Are you sure you want to leave this organization (' + org.name + ')?')) { + return; + } + + apiService.organizations.postLeave({ id: org.id }, {}, function (response) { + authService.refreshAccessToken().then(function () { + var index = $scope.model.organizations.indexOf(org); + if (index > -1) { + $scope.model.organizations.splice(index, 1); + } + + toastr.success('You have left the organization.'); + scrollToTop(); + }); + }, function (error) { + toastr.error('Unable to leave this organization.'); + scrollToTop(); + }); + }; + $scope.twoFactor = function () { var twoFactorModal = $uibModal.open({ animation: true, @@ -114,4 +136,8 @@ controller: 'settingsDeleteController' }); }; + + function scrollToTop() { + $('html, body').animate({ scrollTop: 0 }, 200); + } }); diff --git a/src/app/settings/views/settings.html b/src/app/settings/views/settings.html index 7d874abb..0a0685fe 100644 --- a/src/app/settings/views/settings.html +++ b/src/app/settings/views/settings.html @@ -114,13 +114,26 @@ No organizations yet for your account.
- - - {{org.name}} - DISABLED - +