2017-11-23 17:04:50 +01:00
|
|
|
import angular from 'angular';
|
|
|
|
|
import _ from 'lodash';
|
2015-07-16 12:38:49 +02:00
|
|
|
|
2017-11-23 17:04:50 +01:00
|
|
|
export class UserInviteCtrl {
|
2015-07-16 12:38:49 +02:00
|
|
|
|
2017-11-23 17:04:50 +01:00
|
|
|
/** @ngInject **/
|
|
|
|
|
constructor($scope, backendSrv) {
|
2015-07-16 12:38:49 +02:00
|
|
|
$scope.invites = [
|
|
|
|
|
{name: '', email: '', role: 'Editor'},
|
|
|
|
|
];
|
|
|
|
|
|
2015-07-20 10:57:39 +02:00
|
|
|
$scope.options = {skipEmails: false};
|
|
|
|
|
$scope.init = function() { };
|
2015-07-16 12:38:49 +02:00
|
|
|
|
|
|
|
|
$scope.addInvite = function() {
|
|
|
|
|
$scope.invites.push({name: '', email: '', role: 'Editor'});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.removeInvite = function(invite) {
|
|
|
|
|
$scope.invites = _.without($scope.invites, invite);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.sendInvites = function() {
|
|
|
|
|
if (!$scope.inviteForm.$valid) { return; }
|
2015-07-21 12:18:11 +02:00
|
|
|
$scope.sendSingleInvite(0);
|
|
|
|
|
};
|
2015-07-16 12:38:49 +02:00
|
|
|
|
2015-07-21 12:18:11 +02:00
|
|
|
$scope.sendSingleInvite = function(index) {
|
|
|
|
|
var invite = $scope.invites[index];
|
|
|
|
|
invite.skipEmails = $scope.options.skipEmails;
|
2015-07-17 14:42:49 +02:00
|
|
|
|
2015-07-21 12:18:11 +02:00
|
|
|
return backendSrv.post('/api/org/invites', invite).finally(function() {
|
|
|
|
|
index += 1;
|
2015-07-17 09:51:34 +02:00
|
|
|
|
2015-07-21 12:18:11 +02:00
|
|
|
if (index === $scope.invites.length) {
|
|
|
|
|
$scope.invitesSent();
|
|
|
|
|
$scope.dismiss();
|
|
|
|
|
} else {
|
|
|
|
|
$scope.sendSingleInvite(index);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-07-16 12:38:49 +02:00
|
|
|
};
|
2017-11-23 17:04:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
angular.module('grafana.controllers').controller('UserInviteCtrl', UserInviteCtrl);
|