org_users_ctrl.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. import coreModule from '../../core/core_module';
  5. export class OrgUsersCtrl {
  6. user: any;
  7. users: any;
  8. pendingInvites: any;
  9. editor: any;
  10. /** @ngInject */
  11. constructor(private $scope, private $http, private backendSrv) {
  12. this.user = {
  13. loginOrEmail: '',
  14. role: 'Viewer',
  15. };
  16. this.get();
  17. this.editor = { index: 0 };
  18. }
  19. get() {
  20. this.backendSrv.get('/api/org/users')
  21. .then((users) => {
  22. this.users = users;
  23. });
  24. this.backendSrv.get('/api/org/invites')
  25. .then((pendingInvites) => {
  26. this.pendingInvites = pendingInvites;
  27. });
  28. }
  29. updateOrgUser(user) {
  30. this.backendSrv.patch('/api/org/users/' + user.userId, user);
  31. }
  32. removeUser(user) {
  33. this.$scope.appEvent('confirm-modal', {
  34. title: 'Delete',
  35. text: 'Are you sure you want to delete user ' + user.login + '?',
  36. yesText: "Delete",
  37. icon: "fa-warning",
  38. onConfirm: () => {
  39. this.removeUserConfirmed(user);
  40. }
  41. });
  42. }
  43. removeUserConfirmed(user) {
  44. this.backendSrv.delete('/api/org/users/' + user.userId)
  45. .then(() => {
  46. this.get();
  47. });
  48. }
  49. revokeInvite(invite, evt) {
  50. evt.stopPropagation();
  51. this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke')
  52. .then(() => {
  53. this.get();
  54. });
  55. }
  56. copyInviteToClipboard(evt) {
  57. evt.stopPropagation();
  58. }
  59. openInviteModal() {
  60. var modalScope = this.$scope.$new();
  61. modalScope.invitesSent = function() {
  62. this.get();
  63. };
  64. this.$scope.appEvent('show-modal', {
  65. src: 'public/app/features/org/partials/invite.html',
  66. modalClass: 'invite-modal',
  67. scope: modalScope
  68. });
  69. }
  70. }
  71. coreModule.controller('OrgUsersCtrl', OrgUsersCtrl);