(function ()
    {
    var module = angular.module('profiles', []);

    module.controller('ProfilesController', ['$http', '$scope', '$rootScope', function ($http, $scope, $rootscope)
        {
        var profiles = this;
        profiles.http = $http;
        profiles.rootscope = $rootscope;

        this.isSelected = function(profile)
            {
            return profile === profiles.selected;
            };

        this.select = function(profile)
            {
            profiles.selected = profile;
            profiles.rootscope.$broadcast('profileSelected', profile);
            };

        this.reset = function()
            {
            profiles.selected = "";
            profiles.rootscope.$broadcast('profileSelected', "");
            profiles.http.get('/controller/profiles').success(function(result)
                {
                profiles.list = result;
                });
            };

        $scope.$on('repositoryLoaded', function (event, args)
            {
            profiles.reset();
            });
        }]);

    })();

	