/*jshint -W100*/
/**
 * Each section of the site has its own module. It probably also has
 * submodules, though this boilerplate is too simple to demonstrate it. Within
 * `src/app/home`, however, could exist several additional folders representing
 * additional modules that would then be listed as dependencies of this one.
 * For example, a `note` section could have the submodules `note.create`,
 * `note.delete`, `note.edit`, etc.
 *
 * Regardless, so long as dependencies are managed correctly, the build process
 * will automatically take take of the rest.
 *
 * The dependencies block here is also where component dependencies should be
 * specified, as shown below.
 */
angular.module( 'ngBoilerplate.admin_users', [
  'ui.router',
  'plusOne',
  'ngBoilerplate.account',
  'ngBoilerplate.users',
  'ngBoilerplate.home',
  'ngBoilerplate.admin',
  'ngBoilerplate.admin_modify_db',
  'ngBoilerplate.admin_suggestions',
  'ngBoilerplate.admin_mail_list'
])

/**
 * Each section or module of the site can also have its own routes. AngularJS
 * will handle ensuring they are all available at run-time, but splitting it
 * this way makes each module more "self-contained".
 */
.config(function config( $stateProvider ) {
  $stateProvider.state( 'admin_users', {
    url: '/admin_users',
    views: {
       "header": {
        controller: 'Admin_Users_Ctrl',
        templateUrl: 'header/header.tpl.html'
      },
      "admin_header": {
        controller: 'Admin_Users_Ctrl',
        templateUrl: 'admin_header/admin_header.tpl.html'
      },
      "main": {
        controller: 'Admin_Users_Ctrl',
        templateUrl: 'admin_users/admin_users.tpl.html'
      },
      "footer": {
        controller: 'Admin_Users_Ctrl',
        templateUrl: 'footer/footer.tpl.html'
      }
    },
    data:{ pageTitle: 'Gestión de usuarios' },
    resolve:{
        accounts: function(accountService) {
            console.log("accounts");
            return accountService.getAllAccounts();
        }
    }
  });
})

/**
 * And of course we define a controller for our route.
 */
.controller( 'Admin_Users_Ctrl', function Admin_Users_Controller( $scope, sessionService, accounts, $state) {
    console.log("Admin_Users_Ctrl");
    $scope.accounts = accounts;
    $scope.isLoggedIn = sessionService.isLoggedIn;
    $scope.logout = function() {
        sessionService.logout();
        $state.go("home");
    };
    $scope.isAdmin = sessionService.isAdmin;
    $scope.isUser = sessionService.isUser;
    $scope.isTempUser = sessionService.isTempUser;
});

