'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.controller:SessionCtrl
 * @description
 * # SessionCtrl
 * Controller of the Pear2Pear
 */
angular.module('Pear2Pear')
  .config(['$routeProvider', function($routeProvider) {
    $routeProvider.
      when('/session/new', {
        templateUrl: 'views/session/new.html',
        controller:'SessionCtrl'
      })
    .when('/session/userdata',{
      templateUrl: 'views/session/userdata.html',
      controller:'SessionCtrl'
    });
  }])

  .controller('SessionCtrl', ['$scope', '$location', '$route', function($scope, $location, $route) {
    $scope.$parent.hideNavigation = true;
    $scope.session = {};

    $scope.create = function() {
      $scope.$parent.hideNavigation = false;
      // $location.path('/timeline');
      $location.path('/session/userdata');
    };

    $scope.userData = function () {
      // new random user id to track new visit
      _paq.push(['setUserId', Math.random().toString(36).substring(2)]);
      _paq.push(['setCustomVariable', 1, 'gender', $scope.user.gender, 'visit']);
      _paq.push(['setCustomVariable', 2, 'age', $scope.user.age, 'visit']);
      _paq.push(['setCustomVariable', 3, 'role', $scope.user.role, 'visit']);
      _paq.push(['setCustomVariable', 4, 'tech', $scope.user.tech, 'visit']);
      _paq.push(['setCustomVariable', 5, 'community', $scope.user.community, 'visit']);
      _paq.push(['trackPageView']);

      // tracker.storeCustomVariablesInCookie();
      _paq.push(['trackEvent', 'UserQuestionaire', 'answer']);
      _paq.push(['trackPageView']);

      if (!$route.current.params['redirect']) {
        $location.path('/timeline');
      }
      else {
        var redirect = $route.current.params['redirect'];
        $location.path(redirect);
      }
    };
    
  }]);

'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.controller:SessionCtrl
 * @description
 * # SessionCtrl
 * Controller of the Pear2Pear
 */
angular.module('Pear2Pear')
  .config(['$routeProvider', function($routeProvider) {
    $routeProvider.
      when('/session/new', {
        templateUrl: 'views/session/new.html',
        controller:'SessionCtrl'
      })
    .when('/session/userdata',{
      templateUrl: 'views/session/userdata.html',
      controller:'SessionCtrl'
    });
  }])

  .controller('SessionCtrl', ['$scope', '$location', '$route', function($scope, $location, $route) {
    $scope.$parent.hideNavigation = true;
    $scope.session = {};

    $scope.create = function() {
      $scope.$parent.hideNavigation = false;
      // $location.path('/timeline');
      $location.path('/session/userdata');
    };

    $scope.userData = function () {
      // new random user id to track new visit
      _paq.setUserId(Math.random().toString(36).substring(2));
      _paq.push(['setCustomVariable', 1, 'gender', $scope.user.gender, 'visit']);
      _paq.push(['setCustomVariable', 2, 'age', $scope.user.age, 'visit']);
      _paq.push(['setCustomVariable', 3, 'role', $scope.user.role, 'visit']);
      _paq.push(['setCustomVariable', 4, 'tech', $scope.user.tech, 'visit']);
      _paq.push(['setCustomVariable', 5, 'community', $scope.user.community, 'visit']);
      _paq.push(['trackPageView']);

      // tracker.storeCustomVariablesInCookie();
      _paq.push(['trackEvent', 'UserQuestionaire', 'answer']);
      _paq.push(['trackPageView']);

      if (!$route.current.params['redirect']) {
        $location.path('/timeline');
      }
      else {
        var redirect = $route.current.params['redirect'];
        $location.path(redirect);
      }
    };
    
  }]);

Revert "minor: fix a Piwik function call"