user_invite_ctrl.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. export class UserInviteCtrl {
  4. /** @ngInject **/
  5. constructor($scope, backendSrv) {
  6. $scope.invites = [
  7. {name: '', email: '', role: 'Editor'},
  8. ];
  9. $scope.options = {skipEmails: false};
  10. $scope.init = function() { };
  11. $scope.addInvite = function() {
  12. $scope.invites.push({name: '', email: '', role: 'Editor'});
  13. };
  14. $scope.removeInvite = function(invite) {
  15. $scope.invites = _.without($scope.invites, invite);
  16. };
  17. $scope.sendInvites = function() {
  18. if (!$scope.inviteForm.$valid) { return; }
  19. $scope.sendSingleInvite(0);
  20. };
  21. $scope.sendSingleInvite = function(index) {
  22. var invite = $scope.invites[index];
  23. invite.skipEmails = $scope.options.skipEmails;
  24. return backendSrv.post('/api/org/invites', invite).finally(function() {
  25. index += 1;
  26. if (index === $scope.invites.length) {
  27. $scope.invitesSent();
  28. $scope.dismiss();
  29. } else {
  30. $scope.sendSingleInvite(index);
  31. }
  32. });
  33. };
  34. }
  35. }
  36. angular.module('grafana.controllers').controller('UserInviteCtrl', UserInviteCtrl);