2017-12-12 22:15:26 +03:00
|
|
|
import coreModule from 'app/core/core_module';
|
2017-11-23 17:04:50 +01:00
|
|
|
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 **/
|
2017-12-12 22:15:26 +03:00
|
|
|
constructor($scope, backendSrv, navModelSrv) {
|
|
|
|
|
$scope.navModel = navModelSrv.getNav('cfg', 'users', 0);
|
|
|
|
|
|
|
|
|
|
const defaultInvites = [
|
2015-07-16 12:38:49 +02:00
|
|
|
{name: '', email: '', role: 'Editor'},
|
|
|
|
|
];
|
|
|
|
|
|
2017-12-12 22:15:26 +03:00
|
|
|
$scope.invites = _.cloneDeep(defaultInvites);
|
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-12 22:15:26 +03:00
|
|
|
$scope.resetInvites = function() {
|
|
|
|
|
$scope.invites = _.cloneDeep(defaultInvites);
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-16 12:38:49 +02:00
|
|
|
$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
|
|
|
|
2017-12-12 22:15:26 +03:00
|
|
|
$scope.invitesSent = function() {
|
|
|
|
|
$scope.resetInvites();
|
|
|
|
|
};
|
|
|
|
|
|
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();
|
|
|
|
|
} else {
|
|
|
|
|
$scope.sendSingleInvite(index);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-07-16 12:38:49 +02:00
|
|
|
};
|
2017-11-23 17:04:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 22:15:26 +03:00
|
|
|
coreModule.controller('UserInviteCtrl', UserInviteCtrl);
|