userInviteCtrl.js 1.1 KB

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