///<reference path="../../headers/common.d.ts" />
System.register(["app/core/config", "app/core/core_module"], function (exports_1, context_1) {
    "use strict";
    var __moduleName = context_1 && context_1.id;
    var config_1, core_module_1, OrgUsersCtrl;
    return {
        setters: [
            function (config_1_1) {
                config_1 = config_1_1;
            },
            function (core_module_1_1) {
                core_module_1 = core_module_1_1;
            }
        ],
        execute: function () {///<reference path="../../headers/common.d.ts" />
            OrgUsersCtrl = (function () {
                /** @ngInject */
                function OrgUsersCtrl($scope, $http, backendSrv) {
                    this.$scope = $scope;
                    this.$http = $http;
                    this.backendSrv = backendSrv;
                    this.user = {
                        loginOrEmail: '',
                        role: 'Viewer',
                    };
                    this.get();
                    this.editor = { index: 0 };
                    this.showInviteUI = config_1.default.disableLoginForm === false;
                }
                OrgUsersCtrl.prototype.get = function () {
                    var _this = this;
                    this.backendSrv.get('/api/org/users')
                        .then(function (users) {
                        _this.users = users;
                    });
                    this.backendSrv.get('/api/org/invites')
                        .then(function (pendingInvites) {
                        _this.pendingInvites = pendingInvites;
                    });
                };
                OrgUsersCtrl.prototype.updateOrgUser = function (user) {
                    this.backendSrv.patch('/api/org/users/' + user.userId, user);
                };
                OrgUsersCtrl.prototype.removeUser = function (user) {
                    var _this = this;
                    this.$scope.appEvent('confirm-modal', {
                        title: 'Delete',
                        text: 'Are you sure you want to delete user ' + user.login + '?',
                        yesText: "Delete",
                        icon: "fa-warning",
                        onConfirm: function () {
                            _this.removeUserConfirmed(user);
                        }
                    });
                };
                OrgUsersCtrl.prototype.removeUserConfirmed = function (user) {
                    this.backendSrv.delete('/api/org/users/' + user.userId)
                        .then(this.get.bind(this));
                };
                OrgUsersCtrl.prototype.revokeInvite = function (invite, evt) {
                    evt.stopPropagation();
                    this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke')
                        .then(this.get.bind(this));
                };
                OrgUsersCtrl.prototype.copyInviteToClipboard = function (evt) {
                    evt.stopPropagation();
                };
                OrgUsersCtrl.prototype.openInviteModal = function () {
                    var modalScope = this.$scope.$new();
                    modalScope.invitesSent = this.get.bind(this);
                    var src = this.showInviteUI
                        ? 'public/app/features/org/partials/invite.html'
                        : 'public/app/features/org/partials/add_user.html';
                    this.$scope.appEvent('show-modal', {
                        src: src,
                        modalClass: 'invite-modal',
                        scope: modalScope
                    });
                };
                return OrgUsersCtrl;
            }());
            exports_1("OrgUsersCtrl", OrgUsersCtrl);
            core_module_1.default.controller('OrgUsersCtrl', OrgUsersCtrl);
        }
    };
});
//# sourceMappingURL=org_users_ctrl.js.map