|
14 | 14 | defaultState: '@'
|
15 | 15 | },
|
16 | 16 | controller: ['CONSTANTS', '$rootScope', '$scope', 'NotificationService', 'ProfileService', '$log', '$state', pageStateHeader],
|
17 |
| - controllerAs: "vm" |
| 17 | + controllerAs: 'vm' |
18 | 18 | };
|
19 | 19 | });
|
20 | 20 |
|
21 | 21 | function pageStateHeader(CONSTANTS, $rootScope, $scope, NotificationService, ProfileService, $log, $state) {
|
22 | 22 | var vm = this;
|
23 |
| - vm.handle = $scope.handle; |
24 |
| - vm.profile = null; |
25 |
| - vm.handleColor = null; |
26 |
| - vm.hideMoney = _.get($scope, 'hideMoney', true); |
27 |
| - vm.previousStateName = null; |
28 |
| - vm.previousStateLabel = null; |
29 |
| - vm.previousState = null; |
30 |
| - vm.showBackLink = _.get($scope, 'showBackLink', false); |
31 | 23 | vm.backHandler = backHandler;
|
| 24 | + |
32 | 25 | activate();
|
33 | 26 |
|
34 | 27 | // watch for profile update event in case handle/image are updated
|
|
37 | 30 | });
|
38 | 31 |
|
39 | 32 | function activate() {
|
| 33 | + vm.handle = $scope.handle; |
| 34 | + vm.profile = null; |
| 35 | + vm.handleColor = null; |
| 36 | + $scope.hideMoney = _.get($scope, 'hideMoney', true); |
| 37 | + vm.previousStateName = null; |
| 38 | + vm.previousStateLabel = null; |
| 39 | + vm.previousState = null; |
| 40 | + vm.showBackLink = _.get($scope, 'showBackLink', false); |
40 | 41 | vm.loading = true;
|
41 | 42 |
|
42 | 43 | // identifies the previous state
|
43 | 44 | if ($scope.$root.previousState && $scope.$root.previousState.name.length > 0) {
|
44 | 45 | vm.previousState = $scope.$root.previousState;
|
45 | 46 | vm.previousStateName = vm.previousState.name;
|
| 47 | + |
46 | 48 | } else if ($scope.defaultState) {
|
47 | 49 | vm.previousStateName = $scope.defaultState;
|
48 | 50 | }
|
|
51 | 53 | if (vm.previousStateName) {
|
52 | 54 | if (vm.previousStateName === 'dashboard') {
|
53 | 55 | vm.previousStateLabel = 'Dashboard';
|
| 56 | + |
54 | 57 | } else if (vm.previousStateName.indexOf('profile') > -1) {
|
55 | 58 | vm.previousStateLabel = 'Profile';
|
56 | 59 | }
|
|
60 | 63 | ProfileService.getUserProfile(vm.handle).then(function(profile) {
|
61 | 64 | vm.profile = profile;
|
62 | 65 | vm.handleColor = ProfileService.getUserHandleColor(vm.profile);
|
63 |
| - if (!vm.hideMoney) { |
| 66 | + |
| 67 | + if (!$scope.hideMoney) { |
64 | 68 | displayMoneyEarned(vm.handle);
|
65 | 69 | } else {
|
66 | 70 | vm.loading = false;
|
|
71 | 75 | function backHandler() {
|
72 | 76 | var _params = {};
|
73 | 77 | var _name = vm.previousStateName;
|
| 78 | + |
74 | 79 | switch (vm.previousStateName) {
|
75 | 80 | case 'profile.about':
|
76 | 81 | _params = {userHandle: vm.profile.handle};
|
|
80 | 85 | _name = 'dashboard';
|
81 | 86 | break;
|
82 | 87 | }
|
| 88 | + |
83 | 89 | $state.go(_name, _params);
|
84 | 90 | }
|
85 | 91 |
|
|
89 | 95 | vm.moneyEarned = _.sum(_.pluck(financials, 'amount'));
|
90 | 96 |
|
91 | 97 | if (!vm.moneyEarned) {
|
92 |
| - vm.hideMoney = true; |
| 98 | + $scope.hideMoney = true; |
93 | 99 | }
|
94 | 100 |
|
95 | 101 | vm.loading = false;
|
96 | 102 | })
|
97 | 103 | .catch(function(err) {
|
98 |
| - vm.hideMoney = true; |
| 104 | + $scope.hideMoney = true; |
99 | 105 | vm.loading = false;
|
100 | 106 | });
|
101 | 107 | }
|
|
0 commit comments