2015-01-19 11:57:25 -06:00
|
|
|
define([
|
|
|
|
'angular',
|
|
|
|
],
|
|
|
|
function (angular) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
|
|
|
|
|
module.controller('ProfileCtrl', function($scope, $http, backendSrv) {
|
|
|
|
|
2015-01-20 09:29:19 -06:00
|
|
|
$scope.newAccount = {name: ''};
|
|
|
|
|
2015-01-19 11:57:25 -06:00
|
|
|
$scope.init = function() {
|
|
|
|
$scope.getUser();
|
|
|
|
$scope.getUserAccounts();
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getUser = function() {
|
|
|
|
backendSrv.get('/api/user').then(function(user) {
|
|
|
|
$scope.user = user;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getUserAccounts = function() {
|
|
|
|
backendSrv.get('/api/user/accounts').then(function(accounts) {
|
|
|
|
$scope.accounts = accounts;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setUsingAccount = function(account) {
|
2015-01-20 09:29:19 -06:00
|
|
|
backendSrv.post('/api/user/using/' + account.accountId).then($scope.getUserAccounts);
|
2015-01-19 11:57:25 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.update = function() {
|
|
|
|
if (!$scope.userForm.$valid) { return; }
|
2015-01-26 05:57:44 -06:00
|
|
|
backendSrv.put('/api/user/', $scope.user);
|
2015-01-19 11:57:25 -06:00
|
|
|
};
|
|
|
|
|
2015-01-20 09:29:19 -06:00
|
|
|
$scope.createAccount = function() {
|
2015-01-26 05:57:44 -06:00
|
|
|
backendSrv.post('/api/account/', $scope.newAccount).then($scope.getUserAccounts);
|
2015-01-20 09:29:19 -06:00
|
|
|
};
|
|
|
|
|
2015-01-19 11:57:25 -06:00
|
|
|
$scope.init();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|