(function (angular) {
    angular
        .module('todoList')
        .controller('indexController', index);

    index.$inject = ['$rootScope', '$scope'];

    /* @ngInject */
    function index($rootScope, $scope) {
        /* jshint validthis: true */
        var vm = this;

        vm.activate = activate;
        vm.title = "Sample ToDo List";

        $rootScope.setTitle = setTitle;
        $rootScope.messages = {};
        $scope.setDirty = setDirty;

        activate();
        setTitle('Home');

        ////////////////

        function activate() { }

        function setTitle(title) {
            $rootScope.title = vm.title + " | " + title;
        }

        function setDirty(form) {
            angular.forEach(form.$error, function (errorType) {
                angular.forEach(errorType, function (item) {
                    item.$setDirty();
                });
            });
        }

    }
})(angular);