/*! grafana - v4.5.1 - 2017-09-19
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["app/core/config","app/core/core"],function(a,b){"use strict";var c,d,e;b&&b.id;return{setters:[function(a){c=a},function(a){d=a}],execute:function(){e=function(){function a(a,b,d,e){this.backendSrv=a,this.contextSrv=b,this.$location=d,this.orgs=[],this.showOrgsList=!1,this.readonlyLoginFields=c.default.disableLoginForm,this.getUser(),this.getUserOrgs(),this.navModel=e.getProfileNav()}return a.$inject=["backendSrv","contextSrv","$location","navModelSrv"],a.prototype.getUser=function(){var a=this;this.backendSrv.get("/api/user").then(function(b){a.user=b,a.user.theme=b.theme||"dark"})},a.prototype.getUserOrgs=function(){var a=this;this.backendSrv.get("/api/user/orgs").then(function(b){a.orgs=b,a.showOrgsList=b.length>1})},a.prototype.setUsingOrg=function(a){this.backendSrv.post("/api/user/using/"+a.orgId).then(function(){window.location.href=c.default.appSubUrl+"/profile"})},a.prototype.update=function(){var a=this;this.userForm.$valid&&this.backendSrv.put("/api/user/",this.user).then(function(){a.contextSrv.user.name=a.user.name||a.user.login,a.old_theme!==a.user.theme&&(window.location.href=c.default.appSubUrl+a.$location.path())})},a}(),a("ProfileCtrl",e),d.coreModule.controller("ProfileCtrl",e)}}});