user_invite_ctrl.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import coreModule from 'app/core/core_module';
  2. import _ from 'lodash';
  3. export class UserInviteCtrl {
  4. /** @ngInject **/
  5. constructor($scope, backendSrv, navModelSrv) {
  6. $scope.navModel = navModelSrv.getNav('cfg', 'users', 0);
  7. const defaultInvites = [
  8. {name: '', email: '', role: 'Editor'},
  9. ];
  10. $scope.invites = _.cloneDeep(defaultInvites);
  11. $scope.options = {skipEmails: false};
  12. $scope.init = function() { };
  13. $scope.addInvite = function() {
  14. $scope.invites.push({name: '', email: '', role: 'Editor'});
  15. };
  16. $scope.removeInvite = function(invite) {
  17. $scope.invites = _.without($scope.invites, invite);
  18. };
  19. $scope.resetInvites = function() {
  20. $scope.invites = _.cloneDeep(defaultInvites);
  21. };
  22. $scope.sendInvites = function() {
  23. if (!$scope.inviteForm.$valid) { return; }
  24. $scope.sendSingleInvite(0);
  25. };
  26. $scope.invitesSent = function() {
  27. $scope.resetInvites();
  28. };
  29. $scope.sendSingleInvite = function(index) {
  30. var invite = $scope.invites[index];
  31. invite.skipEmails = $scope.options.skipEmails;
  32. return backendSrv.post('/api/org/invites', invite).finally(function() {
  33. index += 1;
  34. if (index === $scope.invites.length) {
  35. $scope.invitesSent();
  36. } else {
  37. $scope.sendSingleInvite(index);
  38. }
  39. });
  40. };
  41. }
  42. }
  43. coreModule.controller('UserInviteCtrl', UserInviteCtrl);