'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.controller:NavbarTopCtrl
 * @description
 * # NavbarTop Ctrl
 */

angular.module('Pear2Pear')
  .controller(
    'NavbarTopCtrl', [
      'SwellRTSession', '$scope',
      function(SwellRTSession, $scope){

        var getSharedMode = function(){
          if ($scope.project){
            return $scope.project.shareMode;
          }
          return null;
        };

        $scope.shareIcon = function shareIcon() {
          switch (getSharedMode()) {
            case 'link':
              return 'fa-link';
            case 'public':
              return 'fa-globe';
            default:
              return '';
          }
        };

        $scope.isShared = function(mode) {
          if ($scope.project){
            return getSharedMode() === mode;
          }
          return false;
        };

        $scope.setShared = function setShared(mode){
          $scope.project.setShareMode(mode);
        };

        $scope.timestampProjectAccess = function(){
          $scope.project.timestampProjectAccess();
        };
      }]);

'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.controller:NavbarTopCtrl
 * @description
 * # NavbarTop Ctrl
 */

angular.module('Pear2Pear')
  .controller(
    'NavbarTopCtrl', [
      'SwellRTSession', '$scope',
      function(SwellRTSession, $scope){

        var getSharedMode = function(){
          if ($scope.project){
            return $scope.project.shareMode;
          }
          return null;
        };

        $scope.$on('$locationChangeStart', function(event) {
          SwellRTSession.onLoad(function(){
            if ($route.current.params.id){
              pear.projects.find($route.current.params.id)
                .then(function(proxy) {
                  $scope.project = proxy;
                });
            }
          });
        });

        $scope.shareIcon = function shareIcon() {
          switch (getSharedMode()) {
            case 'link':
              return 'fa-link';
            case 'public':
              return 'fa-globe';
            default:
              return '';
          }
        };

        $scope.isShared = function(mode) {
          if ($scope.project){
            return getSharedMode() === mode;
          }
          return false;
        };

        $scope.setShared = function setShared(mode){
          $scope.project.setShareMode(mode);
        };

        $scope.timestampProjectAccess = function(){
          $scope.project.timestampProjectAccess();
        };
      }]);

Revert "avoid unnecesary call to onLoad"
Revert "avoid unnecesary call to onLoad"

This reverts commit 5a81300cb8a99c7428d9aeea26276d4415efcf64.
