PageSourceSearch

https://www.investagrams.com/Javascript/AngularApp/Controller/Snip…erNavSnippetController.js?i_1.68.9760.35196

js investagrams.com collected 2026-09-24 08:46:50 UTC 99,078 bytes, 2,465 lines download raw bytes

1investagramsAngularApp.controller('userNavSnippetController',
2    function ($scope, $rootScope, $filter, $window, $timeout, ngCopy, userApiService, userAccessApiService, walletApiService, userPlatformTourApiService, userSubscriptionApiService, userSavedPostApiService) {
3
4
5        $scope.UserNav = {
6            IsLoading: false,
7            ActivePanel: null,
8            ActivePage: null,
9            AuthenticatedUserId: gaAuthenticatedUserId,
10            IsUserLoggedOn: gaIsUserLoggedOn,
11            AuthenticatedUserProfile: null,
12            IsShowVerifyEmailNav: true,
13
14            IsShowMainNav: true,
15            IsShowSubNav: true,
16            IsShowFooter: true,
17            IsShowingLargePopper: false,
18
19            UserHeaderStyle: {
20                "background": "linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.6)), url('') center"
21            },
22
23
24            Menu: {
25                //The name of the master page (without the extension).
26                Type: "MainSite"
27            },
28
29
30            isShowMobileNav: function () {
31                return $window.innerWidth <= 991;
32            },
33
34
35            Wallet: {
36                PrimaryWallet: null,
37                Subscription: null,
38                IsLoading: false
39
40
41
42            },
43
44            UserPrivateStats: {
45                UnreadSavedPostCount: 0
46            },
47
48            SavedPost: {
49                ShowNudge: false,
50
51                setShowNudge: function () {
52                    $scope.UserNav.IsLoading = true;
53
54                    showHeaderLoader();
55
56                    var savedPostSettings = LocalStorageCache.SavedPostNudge.Get();
57
58                    if (savedPostSettings != null) {
59                        if (savedPostSettings.ShowNudge) {
60                            var dayDiff = (new Date()).getDaysDifference(new Date(savedPostSettings.CreatedDate));
61
62                            if (dayDiff >= 1) {
63                                $scope.UserNav.SavedPost.ShowNudge = false;
64
65                                var cacheContent = {
66                                    ShowNudge: false,
67                                    CreatedDate: new Date()
68                                };
69
70                                LocalStorageCache.SavedPostNudge.Set(cacheContent);
71                            }
72                        }
73
74                        $scope.UserNav.SavedPost.ShowNudge = savedPostSettings.ShowNudge;
75                        $scope.UserNav.IsLoading = false;
76                        hideHeaderLoader();
77                    }
78                    else {
79                        userSavedPostApiService.getOldestUnreadSavedPostByUserId().then(function (result) {
80                            $scope.UserNav.SavedPost.ShowNudge = false;
81
82                            if (result.data != null) {
83                                var dayDiff = (new Date()).getDaysDifference(new Date(result.data.CreatedDate));
84
85                                if (dayDiff >= 7) {
86                                    $scope.UserNav.SavedPost.ShowNudge = true;
87                                }
88                            }
89                            var cacheContent = {
90                                ShowNudge: $scope.UserNav.SavedPost.ShowNudge,
91                                CreatedDate: new Date()
92                            }
93
94                            LocalStorageCache.SavedPostNudge.Set(cacheContent);
95
96                            hideHeaderLoader();
97                            $scope.UserNav.IsLoading = false;
98
99                        }, function (error) {
100                            $scope.UserNav.IsLoading = false;
101                            hideHeaderLoader();
102                            showErrorResponse(error);
103                        });
104                    }
105                }
106
107            },
108
109
110            UserAccess: {
111                Data: null,
112
113                isInitialLoad: false,
114
115                currentSubscriptionItemType: 0,
116
117                hasPrimeAccess: false,
118
119                hasPrimePlusAccess: false,
120
121                hasEliteAccess: false,
122
123                hasProAccess: false,
124
125                hasPSElvl1Access: false,
126
127                hasPSElvl2Access: false,
128
129                hasPSElvl1Orlvl2Access: false,
130
131                hasPremiumAccess: false,
132
133                isShowGoInvestaPrime: false,
134
135                isShowUpgradeToPrime: false,
136
137                isShowInvestaPrimeAds: true,
138
139                isPageAllowToShowShowman: true,
140
141                isShowUpgradeToAnnual: false,
142
143                AccessTypeString: "Guest",
144
145                //isShowInvestaPrimeAds: function () {
146
147                //    if ($scope.UserNav.UserAccess.Data) {
148
149                //        if ($scope.UserNav.UserAccess.hasPrimeAccess) {
150                //            return false;
151                //        }
152                //        //else {
153
154                //        //    if ($scope.UserNav.AuthenticatedUserProfile) {
155
156                //        //        var userCreatedTime = new Date($scope.UserNav.AuthenticatedUserProfile.UserInfo.CreateTime);
157
158                //        //        if (userCreatedTime.hasPassedNDays(2)) {
159                //        //            return true;
160                //        //        }
161                //        //        else {
162                //        //            return false;
163                //        //        }
164                //        //    }
165                //        //}
166                //    }
167
168                //    return true;
169
170                //},
171
172
173
174                isShowPSEPlanToPrimeUpgrade: false,
175
176
177                isShowLaunchPrime: false,
178
179                isExpiredPremiumAccessPassedDays: false,
180
181                isShowUpgradeToInvestaPrime: false,
182
183                isUserSelectedBadgePioneer: function (badgeType) {
184                    return isSelectedBadge(badgeType);
185                },
186
187                getUserAccess: function () {
188
189                    LocalStorageCache.AuthenticatedUserAccess.Remove();
190
191                    if ($scope.UserNav.AuthenticatedUserId > 0) {
192
193                        showHeaderLoader();
194
195                        userAccessApiService.getUserAccess().then(function (result) {
196
197                            if (result.data != null) {
198                                $scope.UserNav.UserAccess.Data = result.data;
199
200                                LocalStorageCache.AuthenticatedUserAccess.Set($scope.UserNav.UserAccess.Data);
201
202                                $scope.UserNav.UserAccess.postProcessingAfterRetreivingUserAccess(false);
203                            }
204
205                            hideHeaderLoader();
206
207                        }, function (error) {
208                            hideHeaderLoader();
209                            showErrorResponse(error);
210                        });
211                    }
212
213                },
214
215                // 20250113 - Create generic function to check if user has Annual Subscription active
216                hasAnnualPrimeSubscription: function () {
217
218                    if ($scope.UserNav.UserAccess.Data &&
219                        $scope.UserNav.UserAccess.hasEliteAccess ||
220                        $scope.UserNav.UserAccess.hasPrimePlusAccess ||
221                        $scope.UserNav.UserAccess.hasPrimeAccess) {
222
223                        var isEligible = false;
224
225                        var subSession = LocalStorageCache.SubscriptionSession.Get();
226                        if (subSession && subSession.MainSubscription) {
227                            var mainSub = subSession.MainSubscription;
228                            switch (mainSub.ItemType) {
229                                case 61:
230                                case 62:
231                                case 64:
232                                    isEligible = mainSub.IntervalType == 2;
233                                    break;
234                                case 66: // Lifetime Elite
235                                    isEligible = true;
236                                    break;
237                            }
238                        }
239
240                        // 20250114 - Also consider lifetime users
241                        if (!isEligible) {
242                            var futureDate = new Date(new Date().setFullYear(new Date().getFullYear() + 2));
243
244                            isEligible =
245                                new Date($scope.UserNav.UserAccess.Data.InvestaPrimeEliteExpiration) >= futureDate ||
246                                new Date($scope.UserNav.UserAccess.Data.InvestaPrimePlusExpiration) >= futureDate ||
247                                new Date($scope.UserNav.UserAccess.Data.InvestaPrimeExpiration) >= futureDate;
248                        }
249
250                        return isEligible;
251                    }
252
253                    return false;
254                },
255
256                getUserIsRealtimeCurrentStatus: function (exchangeType) {
257                    if ((exchangeType != null && exchangeType != 1) || $scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access || $scope.UserNav.UserAccess.hasPrimeAccess) {
258                        return 'a';
259                    }
260                    return 'b';
261                },
262
263                isUserEligibleForPSERealtimeByExchangeType: function (exchangeType) {
264                    if (exchangeType != null) {
265                        return exchangeType != 1
266                            || $scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access
267                            || $scope.UserNav.UserAccess.hasPrimeAccess
268                            || !isMarketOpen(exchangeType);
269                    }
270                    return false;
271                },
272
273                postProcessingAfterRetreivingUserAccess: function (isCameFromLocalStorage) {
274
275                    if ($scope.UserNav.UserAccess.Data) {
276
277
278                        if ($scope.UserNav.UserAccess.Data.IsInvestaPrimeNotExpired) {
279                            $scope.UserNav.UserAccess.Data.IsInvestaPrimeNotExpired =
280                                new Date($scope.UserNav.UserAccess.Data.InvestaPrimeExpiration).isNotExpired();
281                        }
282
283                        if ($scope.UserNav.UserAccess.Data.IsInvestaPrimePlusNotExpired) {
284                            $scope.UserNav.UserAccess.Data.IsInvestaPrimePlusNotExpired =
285                                new Date($scope.UserNav.UserAccess.Data.InvestaPrimePlusExpiration).isNotExpired();
286                        }
287
288
289                        if ($scope.UserNav.UserAccess.Data.IsInvestaProNotExpired) {
290                            $scope.UserNav.UserAccess.Data.IsInvestaProNotExpired =
291                                new Date($scope.UserNav.UserAccess.Data.InvestaProExpiration).isNotExpired();
292                        }
293
294
295                        if ($scope.UserNav.UserAccess.Data.IsPSElvl1NotExpired) {
296                            $scope.UserNav.UserAccess.Data.IsPSElvl1NotExpired =
297                                new Date($scope.UserNav.UserAccess.Data.PSElvl1Expiration).isNotExpired();
298                        }
299
300                        if ($scope.UserNav.UserAccess.Data.IsPSElvl2NotExpired) {
301                            $scope.UserNav.UserAccess.Data.IsPSElvl2NotExpired =
302                                new Date($scope.UserNav.UserAccess.Data.PSElvl2Expiration).isNotExpired();
303                        }
304
305
306
307                        $scope.UserNav.UserAccess.hasPSElvl1Access = $scope.UserNav.UserAccess.Data.IsPSElvl1NotExpired;
308                        $scope.UserNav.UserAccess.hasPSElvl2Access = $scope.UserNav.UserAccess.Data.IsPSElvl2NotExpired;
309
310                        if ($scope.UserNav.UserAccess.hasPSElvl1Access ||
311                            $scope.UserNav.UserAccess.hasPSElvl2Access ||
312                            ($scope.UserNav.AuthenticatedUserProfile && $scope.UserNav.AuthenticatedUserProfile.IsEmailValidated && !new Date($scope.UserNav.AuthenticatedUserProfile.UserInfo.CreateTime).hasPassedNDays(30))) {
313                            $scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access = true;
314                        }
315
316
317                        $scope.UserNav.UserAccess.hasEliteAccess = $scope.UserNav.UserAccess.Data.IsInvestaPrimeEliteNotExpired;
318                        $scope.UserNav.UserAccess.hasPrimePlusAccess = $scope.UserNav.UserAccess.Data.IsInvestaPrimePlusNotExpired || $scope.UserNav.UserAccess.hasEliteAccess;
319                        $scope.UserNav.UserAccess.hasPrimeAccess = $scope.UserNav.UserAccess.Data.IsInvestaPrimeNotExpired || $scope.UserNav.UserAccess.hasPrimePlusAccess;
320                        $scope.UserNav.UserAccess.hasProAccess = $scope.UserNav.UserAccess.Data.IsInvestaProNotExpired || $scope.UserNav.UserAccess.hasEliteAccess;
321                        $scope.UserNav.UserAccess.hasPremiumAccess = $scope.UserNav.UserAccess.hasPrimeAccess || $scope.UserNav.UserAccess.hasProAccess;
322
323
324                        //If user has prime access, force to set all pse plan related field to true
325                        if ($scope.UserNav.UserAccess.hasPremiumAccess) {
326                            //$scope.UserNav.UserAccess.hasPSElvl2Access = true;
327                            $scope.UserNav.UserAccess.hasPSElvl1Access = true;
328                            $scope.UserNav.UserAccess.Data.IsPSElvl1NotExpired = true;
329                            //$scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access = true;
330                        }
331
332                        if (!$scope.UserNav.UserAccess.hasPremiumAccess) {
333
334                            $scope.primeExpiryDate = new Date($scope.UserNav.UserAccess.Data.InvestaPrimeExpiration);
335                            $scope.primePlusExpiryDate = new Date($scope.UserNav.UserAccess.Data.InvestaPrimePlusExpiration);
336                            $scope.primeEliteExpiryDate = new Date($scope.UserNav.UserAccess.Data.InvestaPrimeEliteExpiration);
337                            $scope.proExpiryDate = new Date($scope.UserNav.UserAccess.Data.InvestaProExpiration);
338
339                            var diffDaysPrimeElite = new Date().getDaysDifference($scope.primeEliteExpiryDate);
340                            var diffDaysPrimePlus = new Date().getDaysDifference($scope.primePlusExpiryDate);
341                            var diffDaysPrime = new Date().getDaysDifference($scope.primeExpiryDate);
342                            var diffDaysPro = new Date().getDaysDifference($scope.proExpiryDate);
343
344                            if (diffDaysPrimeElite <= 15) {
345                                $scope.UserNav.UserAccess.currentSubscriptionItemType = 64;
346                                $scope.UserNav.UserAccess.isExpiredPremiumAccessPassedDays = false;
347                            }
348                            if (diffDaysPrimePlus <= 15) {
349                                $scope.UserNav.UserAccess.currentSubscriptionItemType = 62;
350                                $scope.UserNav.UserAccess.isExpiredPremiumAccessPassedDays = false;
351                            }
352                            else if (diffDaysPrime <= 15) {
353                                $scope.UserNav.UserAccess.currentSubscriptionItemType = 61;
354                                $scope.UserNav.UserAccess.isExpiredPremiumAccessPassedDays = false;
355                            }
356                            else if (diffDaysPro <= 15) {
357                                $scope.UserNav.UserAccess.currentSubscriptionItemType = 63;
358                                $scope.UserNav.UserAccess.isExpiredPremiumAccessPassedDays = false;
359                            }
360                            else {
361                                $scope.UserNav.UserAccess.isExpiredPremiumAccessPassedDays = true;
362                            }
363                        }
364
365
366                        if ($scope.UserNav.UserAccess.hasPremiumAccess ||
367                            !$scope.UserNav.UserAccess.isExpiredPremiumAccessPassedDays) {
368
369                            $scope.UserNav.UserAccess.isShowLaunchPrime = true;
370                        }
371
372
373
374                        $scope.UserNav.UserAccess.isShowGoInvestaPrime = !$scope.UserNav.UserAccess.isShowLaunchPrime && !$scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access;
375                        $scope.UserNav.UserAccess.isShowUpgradeToPrime = !$scope.UserNav.UserAccess.isShowLaunchPrime && !$scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial;
376                        $scope.UserNav.UserAccess.isShowInvestaPrimeAds = !$scope.UserNav.UserAccess.hasPrimeAccess;
377
378                        if ($scope.UserNav.UserAccess.Data && !$scope.UserNav.UserAccess.isShowInvestaPrimeAds && !$scope.UserNav.UserAccess.isShowLaunchPrime) {
379
380                            if ($scope.UserNav.UserAccess.Data.IsInvestaPrimeNotExpired ||
381                                $scope.UserNav.UserAccess.Data.IsInvestaPrimePlusNotExpired) {
382
383                                $scope.UserNav.UserAccess.isShowUpgradeToInvestaPrime = false;
384                            }
385                        }
386
387
388
389                        if ($scope.UserNav.UserAccess.Data && $scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access && !$scope.UserNav.UserAccess.hasPrimeAccess) {
390
391
392                            var endDate = $scope.UserNav.UserAccess.Data.IsPSElvl2NotExpired ? $scope.UserNav.UserAccess.Data.PSElvl2Expiration : $scope.UserNav.UserAccess.Data.PSElvl1Expiration;
393
394                            endDate = new Date(endDate).getTime();
395
396                            if (!isNaN(endDate)) {
397                                var startDate = new Date();
398                                startDate = startDate.getTime();
399
400                                var timeRemaining = parseInt((endDate - startDate) / 1000);
401
402                                if (timeRemaining >= 0) {
403                                    days = parseInt(timeRemaining / 86400);
404
405                                    var remainingDays = parseInt(days, 10);
406
407                                    if (remainingDays > 5) {
408                                        $scope.UserNav.UserAccess.isShowPSEPlanToPrimeUpgrade = true;
409                                    }
410                                }
411                            }
412                        }
413
414
415
416
417                        //Set Subscription related details that has dependent un UserAccess data to prevent race condition issue
418                        $scope.UserNav.UserSubscription.setMainSubscriptionUpgradeDetails();
419
420                        //Set AccessTypeString for matomo TrackingPurposes
421                        if ($scope.UserNav.UserAccess.hasEliteAccess) {
422                            $scope.UserNav.UserAccess.AccessTypeString = "PrimeElite User";
423                        }
424                        else if ($scope.UserNav.UserAccess.hasPrimePlusAccess) {
425                            $scope.UserNav.UserAccess.AccessTypeString = "PrimePlus User";
426                        }
427                        else if ($scope.UserNav.UserAccess.hasPrimeAccess) {
428                            $scope.UserNav.UserAccess.AccessTypeString = "Prime User";
429                        }
430                        else if ($scope.UserNav.UserAccess.hasPSElvl2Access) {
431                            $scope.UserNav.UserAccess.AccessTypeString = "PSE Lvl2 User";
432                        }
433                        else if ($scope.UserNav.UserAccess.hasPSElvl1Access) {
434                            $scope.UserNav.UserAccess.AccessTypeString = "PSE Lvl1 User";
435                        }
436                        else {
437                            $scope.UserNav.UserAccess.AccessTypeString = "Free User";
438                        }
439
440                        LocalStorageCache.UserAccessTypeString.Set($scope.UserNav.UserAccess.AccessTypeString);
441                    }
442
443
444                    if (!$scope.UserNav.UserAccess.hasPrimeAccess) {
445                        $scope.GlobalNav.ButtonCTA.init();
446                    }
447
448                    //Set here after all user access related field are properly pre-filled
449                    $scope.UserNav.UserAccess.isInitialLoad = true;
450
451                    $scope.Showman.renderEligibleUserGoogleShowman();
452
453                    $rootScope.$broadcast("getAuthenticatedUserAccess", $scope.UserNav.UserAccess.Data, isCameFromLocalStorage);
454                },
455
456
457                initUserAccess: function () {
458
459                    const pageAccessedByReload = (
460                        (window.performance.navigation && window.performance.navigation.type === 1) ||
461                        window.performance
462                            .getEntriesByType('navigation')
463                            .map((nav) => nav.type)
464                            .includes('reload')
465                    );
466
467
468
469                    if ($scope.UserNav.AuthenticatedUserId > 0 && !$scope.UserNav.UserAccess.isInitialLoad) {
470
471                        var authenticatedUserAccessTemp = LocalStorageCache.AuthenticatedUserAccess.Get();
472
473                        if (!pageAccessedByReload &&
474                            authenticatedUserAccessTemp != null &&
475                            authenticatedUserAccessTemp.UserId == $scope.UserNav.AuthenticatedUserId &&
476                            authenticatedUserAccessTemp.PSElvl1Expiration != null) {
477
478                            $scope.UserNav.UserAccess.Data = authenticatedUserAccessTemp;
479
480
481                            $scope.UserNav.UserAccess.postProcessingAfterRetreivingUserAccess(true);
482                        }
483                        else {
484                            $scope.UserNav.UserAccess.getUserAccess();
485                        }
486
487                    }
488
489                    //Temporary only, for invetigation purposes in PROD environment
490                    console.log("Is Page Refreshed: " + pageAccessedByReload);
491                }
492            },
493
494
495            UserFreeTrial: {
496                IsEligibleForPrimeFreeTrial: null,
497                ctaLabel: "",
498                ctaSubLabel: "",
499                hasLessRemainingDay: false
500                //getIsEligibleForPrimeFreeTrial: function () {
501
502                //    LocalStorageCache.IsEligibleForPrimeFreeTrial.Remove();
503
504                //    if ($scope.UserNav.AuthenticatedUserId > 0) {
505
506                //        showHeaderLoader();
507
508                //        userAccessApiService.isEligibleForPrimeFreeTrial().then(function (result) {
509
510                //            if (result.data != null) {
511                //                $scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial = result.data;
512
513                //                var cacheSecs = Constant.TimeDurationConstant.Seconds.DAYS_3;
514
515                //                if ($scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial) {
516                //                    cacheSecs = Constant.TimeDurationConstant.Seconds.HOURS_12;
517                //                }
518
519                //                LocalStorageCache.IsEligibleForPrimeFreeTrial.Set($scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial, cacheSecs);
520
521                //            }
522
523                //            hideHeaderLoader();
524
525                //        }, function (error) {
526                //            hideHeaderLoader();
527                //            showErrorResponse(error);
528                //        });
529                //    }
530                //},
531
532
533            },
534
535            Gems: {
536
537                IsClaimedLogInReward: false,
538                GemsBalance: 0,
539                displayDailyRewardsModal: function (activeTabRequest) {
540
541                    if (!$scope.UserNav.IsUserLoggedOn) {
542                        $scope.LoginPrompt.togglePrompt(true);
543                    }
544                    else {
545                        $rootScope.$broadcast("proceedDisplayGemsDailyRewardsModal", activeTabRequest);
546                    }
547                }
548            },
549
550
551            PortfolioV2: {
552                HasPaperGain: false
553            },
554
555            //GiftTrial: {
556
557            //    IntervalCountdown: null,
558
559            //    remainingDays: 0,
560            //    remainingHours: 0,
561            //    remainingMinutes: 0,
562            //    remainingSeconds: 0,
563
564            //    GiftModalStatusTypes: {
565            //        None: 1,
566            //        Ready: 2,
567            //        Opened: 3
568            //    },
569
570
571            //    IsGiftModalOpened: false,
572
573            //    displayMysteryGiftModal: function (isShow) {
574            //        var modalAction = isShow ? 'show' : 'hide';
575
576            //        $('#mysteryGiftModal').modal(modalAction);
577            //    },
578
579            //    displayTrialUpgradePromoReminderModal: function (isShow) {
580            //        if (isShow) {
581            //            $scope.UserNav.GiftTrial.startCountdown($scope.UserNav.UserSubscription.SubscriptionSession.MainSubscription.IsSubscribeUntilDate);
582            //            LocalStorageCache.GiftTrialPromoReminderIsAlreadyShowToday.Set(true);
583            //        }
584
585            //        var modalAction = isShow ? 'show' : 'hide';
586
587            //        $('#trialUpgradePromoReminderModal').modal(modalAction);
588            //    },
589
590            //    openMysteryGiftModal: function () {
591
592            //        var giftTrial = $scope.UserNav.GiftTrial;
593
594            //        giftTrial.updateMysteryGiftModalStatus(giftTrial.GiftModalStatusTypes.Opened);
595            //    },
596
597            //    updateMysteryGiftModalStatus: function (modalStatus) {
598
599            //        $scope.UserNav.IsLoading = true;
600            //        showHeaderLoader();
601
602            //        userSubscriptionApiService.updateMysteryGiftModalStatus(modalStatus).then(function (result) {
603            //            //Update status in SubscriptionSession in UI
604            //            if ($scope.UserNav.UserSubscription && $scope.UserNav.UserSubscription.SubscriptionSession) {
605            //                $scope.UserNav.UserSubscription.SubscriptionSession.MysteryGiftModalStatus = modalStatus;
606            //                LocalStorageCache.SubscriptionSession.Set($scope.UserNav.UserSubscription.SubscriptionSession);
607
608            //                $scope.UserNav.GiftTrial.IsGiftModalOpened = true;
609            //            }
610            //        }, function (error) {
611            //            showErrorResponse(error);
612            //        }).finally(function () {
613            //            $scope.UserNav.IsLoading = false;
614            //            hideHeaderLoader();
615            //        });
616            //    },
617
618            //    startCountdown: function (endDate) {
619            //        endDate = new Date(endDate).getTime();
620
621            //        if (isNaN(endDate)) {
622            //            return;
623            //        }
624
625            //        $scope.UserNav.GiftTrial.IntervalCountdown = setInterval(function () {
626            //            $scope.UserNav.GiftTrial.calculateTimeRemaining(endDate);
627            //            $scope.$digest();
628
629            //        }, 1000);
630            //    },
631
632            //    stopCountdown: function () {
633            //        clearInterval($scope.UserNav.GiftTrial.IntervalCountdown);
634            //    },
635
636            //    calculateTimeRemaining: function (endDate) {
637            //        var startDate = new Date();
638            //        startDate = startDate.getTime();
639
640            //        var timeRemaining = parseInt((endDate - startDate) / 1000);
641
642            //        if (timeRemaining >= 0) {
643            //            days = parseInt(timeRemaining / 86400);
644            //            timeRemaining = (timeRemaining % 86400);
645
646            //            hours = parseInt(timeRemaining / 3600);
647            //            timeRemaining = (timeRemaining % 3600);
648
649            //            minutes = parseInt(timeRemaining / 60);
650            //            timeRemaining = (timeRemaining % 60);
651
652            //            seconds = parseInt(timeRemaining);
653
654            //            var subs = $scope.UserNav.GiftTrial;
655
656            //            subs.remainingDays = parseInt(days, 10);
657            //            subs.remainingHours = ("0" + hours).slice(-2);
658            //            subs.remainingMinutes = ("0" + minutes).slice(-2);
659            //            subs.remainingSeconds = ("0" + seconds).slice(-2);
660            //        }
661            //        else {
662            //            return;
663            //        }
664            //    }
665            //},
666
667
668            UserSubscription: {
669                RemainingDays: 0,
670                RemainingHours: 0,
671                RemainingMinutes: 0,
672                RemainingSeconds: 0,
673
674                IsEligibleForMainSubscriptionUpgrade: false,
675
676                SubscriptionSession: null,
677
678                getSubscriptionSession: function () {
679                    showHeaderLoader();
680
681                    LocalStorageCache.SubscriptionSession.Remove();
682
683                    userSubscriptionApiService.getSubscriptionSession().then(function (result) {
684
685                        $scope.UserNav.UserSubscription.SubscriptionSession = result.data;
686                        $scope.UserNav.UserSubscription.setMainSubscriptionOtherDetails();
687                        LocalStorageCache.SubscriptionSession.Set(result.data);
688
689                    }, function (error) {
690
691                        showErrorResponse(error);
692                    }).finally(function () { hideHeaderLoader(); });
693                },
694
695                setMainSubscriptionOtherDetails: function () {
696                    var us = $scope.UserNav.UserSubscription;
697
698                    us.MainSubscriptionAccessTypeTrafficSource = us.SubscriptionSession.AccessTypeTrafficSource;
699                    $scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial = us.SubscriptionSession.TrialDetails.IsEligibleForPrime || us.SubscriptionSession.TrialDetails.IsEligibleForPrimePlus || us.SubscriptionSession.TrialDetails.IsEligibleForPrimeElite;
700
701                    $scope.UserNav.UserSubscription.setMainSubscriptionUpgradeDetails();
702
703                    //2 - Ready Gift Modal Status
704                    //if (us.SubscriptionSession.MysteryGiftModalStatus == 2) {
705
706                    //setTimeout(function () {
707                    //    $scope.GlobalNav.checkIfThereAreOngoingModalOrPlatformTour(function () {
708                    //        $scope.UserNav.GiftTrial.displayMysteryGiftModal(true);
709                    //    });
710                    //}, 1500);
711                    //}
712
713                    //if (us.SubscriptionSession.MainSubscription) {
714                    //var remainingDays = us.SubscriptionSession.MainSubscription.RemainingDaysBeforeExpired;
715
716
717                    //var days = remainingDays == 1 ? 'day' : 'days'
718
719                    //if (remainingDays > 5) {
720                    //    $scope.UserNav.UserFreeTrial.ctaLabel = "Elite Free Trial";
721
722
723                    //    $scope.UserNav.UserFreeTrial.ctaSublabel = remainingDays + " " + days + " remaining";
724                    //    $scope.UserNav.UserFreeTrial.hasLessRemainingDay = false;
725                    //}
726                    //else {
727                    //    $scope.UserNav.UserFreeTrial.ctaLabel = "Elite Free Trial - " + remainingDays + " " + days + " Left";
728
729
730                    //    if (remainingDays <= 1) {
731                    //        $scope.UserNav.UserFreeTrial.ctaSublabel = "UPGRADE NOW AND GET  ₱100 OFF";
732                    //    }
733                    //    else if (remainingDays <= 2) {
734                    //        $scope.UserNav.UserFreeTrial.ctaSublabel = "UPGRADE NOW AND GET  ₱300 OFF";
735                    //    }
736                    //    else {
737                    //        $scope.UserNav.UserFreeTrial.ctaSublabel = "UPGRADE NOW AND GET  ₱500 OFF";
738                    //    }
739
740                    //    $scope.UserNav.UserFreeTrial.hasLessRemainingDay = true;
741                    //}
742
743
744                    //if (us.SubscriptionSession.IsEligibleForPSEPlanEliteUpgrade && remainingDays <= 5) {
745
746                    //    var isGiftTrialPromoReminderAlreadyDisplay = LocalStorageCache.GiftTrialPromoReminderIsAlreadyShowToday.Get();
747
748                    //    if (isGiftTrialPromoReminderAlreadyDisplay == null || !isGiftTrialPromoReminderAlreadyDisplay) {
749                    //        //var modalCurrentlyOpened = $('.modal.show').length;
750
751                    //        $scope.GlobalNav.checkIfThereAreOngoingModalOrPlatformTour(function () {
752                    //            $scope.UserNav.GiftTrial.displayTrialUpgradePromoReminderModal(true);
753                    //        });
754                    //    }
755                    //}
756                    //}
757                },
758
759
760                setMainSubscriptionUpgradeDetails: function () {
761
762                    var us = $scope.UserNav.UserSubscription;
763
764                    if (us.SubscriptionSession && us.SubscriptionSession.MainSubscription) {
765
766                        var ua = $scope.UserNav.UserAccess.Data;
767
768                        if (ua) {
769                            switch (us.SubscriptionSession.MainSubscription.ItemType) {
770                                case 61:
771                                    us.IsEligibleForMainSubscriptionUpgrade = ua.IsInvestaPrimeNotExpired;
772                                    break;
773
774                                case 62:
775                                    us.IsEligibleForMainSubscriptionUpgrade = ua.IsInvestaPrimePlusNotExpired;
776                                    break;
777
778                                case 64:
779                                    us.IsEligibleForMainSubscriptionUpgrade = us.SubscriptionSession.MainSubscription.IntervalType != 2; //annual
780                                    break;
781                                default:
782                                    us.IsEligibleForMainSubscriptionUpgrade = false;
783                                    break;
784                            }
785                        }
786
787                        if (us.SubscriptionSession.MainSubscription.RemainingDaysBeforeExpired > 0) {
788                            $scope.UserNav.UserAccess.isShowUpgradeToAnnual = us.SubscriptionSession.MainSubscription.IntervalType == 1;
789                        }
790                    }
791                },
792
793
794                MainSubscriptionAccessTypeTrafficSource: null,
795
796                ////EligibleInternalPromo: null,
797                //IntervalCountdown: null,
798
799                //getMainSubscriptionAccessTypeTrafficSource: function () {
800                //    showHeaderLoader();
801                //    LocalStorageCache.MainSubscriptionAccessTypeTrafficSource.Remove();
802
803                //    userSubscriptionApiService.getMainSubscriptionAccessTypeTrafficSource().then(function (result) {
804
805                //        $scope.UserNav.UserSubscription.MainSubscriptionAccessTypeTrafficSource = result.data;
806                //        LocalStorageCache.MainSubscriptionAccessTypeTrafficSource.Set(result.data);
807
808                //        hideHeaderLoader();
809                //    },
810                //        function (error) {
811                //            hideHeaderLoader();
812                //            showErrorResponse(error);
813                //        });
814                //},
815
816                //isEligibleForInternalPromo: function () {
817                //    return $scope.UserNav.UserSubscription.EligibleInternalPromo != null && $scope.UserNav.UserSubscription.EligibleInternalPromo.IsEligible;
818                //},
819
820
821                //getEligibleInternalPromo: function () {
822                //    showHeaderLoader();
823                //    LocalStorageCache.EligibleInternalPromo.Remove();
824
825                //    userSubscriptionApiService.getUserEligibleForMainSubsInternalPromo().then(function (result) {
826                //        $scope.UserNav.UserSubscription.EligibleInternalPromo = result.data;
827                //        LocalStorageCache.EligibleInternalPromo.Set(result.data);
828                //        hideHeaderLoader();
829
830                //        $scope.UserNav.UserSubscription.getSubscriptionRemainingDaysForEligiblePromoPeriod();
831
832                //    },
833                //        function (error) {
834                //            hideHeaderLoader();
835                //            showErrorResponse(error);
836                //        });
837                //},
838
839                //getSubscriptionRemainingDaysForEligiblePromoPeriod: function () {
840                //    if ($scope.UserNav.UserSubscription.isEligibleForInternalPromo()) {
841                //        $scope.UserNav.UserSubscription.getRemainingDays();
842
843                //        $rootScope.$broadcast("DoProcessForEligibleUserForInternalPromo");
844                //    }
845                //},
846
847                //getRemainingDays: function () {
848
849                //    var userSubs = $scope.UserNav.UserSubscription;
850
851                //    if (userSubs) {
852                //        userSubs.RemainingDays = new Date(userSubs.EligibleInternalPromo.ExpirationDate).getDaysDifference(new Date());
853
854                //        if (userSubs.RemainingDays > 1) {
855                //            userSubs.RemainingDaysMessage = "Offer ends in " + userSubs.RemainingDays + " days";
856                //        }
857                //        else if (userSubs.RemainingDays == 1) {
858                //            userSubs.RemainingDaysMessage = "Offer ends in 1 day";
859                //        }
860                //        else if (userSubs.RemainingDays == 0) {
861                //            userSubs.RemainingDaysMessage = "Offer ends until today";
862                //        }
863                //        else {
864                //            userSubs.ExpirationDate = null;
865                //            LocalStorageCache.EligibleInternalPromo.Remove();
866                //        }
867                //    }
868                //},
869
870                //startCountdown: function (endDate) {
871                //    endDate = new Date(endDate).getTime();
872
873                //    if (isNaN(endDate)) {
874                //        return;
875                //    }
876
877                //    $scope.UserNav.UserSubscription.IntervalCountdown = setInterval(function () {
878                //        $scope.UserNav.UserSubscription.calculateTimeRemaining(endDate);
879                //        $scope.$digest();
880
881                //    }, 1000);
882                //},
883
884                //stopCountdown: function () {
885                //    clearInterval($scope.UserNav.UserSubscription.IntervalCountdown);
886                //},
887
888                //calculateTimeRemaining: function (endDate) {
889                //    var startDate = new Date();
890                //    startDate = startDate.getTime();
891
892                //    var timeRemaining = parseInt((endDate - startDate) / 1000);
893
894                //    if (timeRemaining >= 0) {
895                //        days = parseInt(timeRemaining / 86400);
896                //        timeRemaining = (timeRemaining % 86400);
897
898                //        hours = parseInt(timeRemaining / 3600);
899                //        timeRemaining = (timeRemaining % 3600);
900
901                //        minutes = parseInt(timeRemaining / 60);
902                //        timeRemaining = (timeRemaining % 60);
903
904                //        seconds = parseInt(timeRemaining);
905
906                //        var subs = $scope.UserNav.UserSubscription;
907
908                //        subs.RemainingDays = parseInt(days, 10);
909                //        subs.RemainingHours = ("0" + hours).slice(-2);
910                //        subs.RemainingMinutes = ("0" + minutes).slice(-2);
911                //        subs.RemainingSeconds = ("0" + seconds).slice(-2);
912                //    }
913                //    else {
914                //        return;
915                //    }
916                //}
917
918            },
919
920
921
922
923            //checkUserOnboarding: function () {
924
925            //    $scope.$on("getAuthenticatedUserProfile", function (event, data) {
926
927            //        if ($scope.UserNav.AuthenticatedUserProfile &&
928            //            !$scope.UserNav.AuthenticatedUserProfile.IsDoneInitialOnboarding) {
929
930            //            PageUrlConstant.Onboarding.ExecuteOriginalUrl();
931            //        }
932
933            //    });
934
935            //},
936
937            signOutUser: function () {
938
939                $scope.UserNav.IsLoading = true;
940
941                showHeaderLoader();
942
943
944                var request = {
945                    DeviceId: "",
946                    RequestComingFromType: 3
947                };
948
949                userApiService.signOutUser(request).then(function (result) {
950
951                    LocalStorageCache.AuthenticatedUserProfile.Remove();
952                    LocalStorageCache.AuthenticatedUserPrimaryWallet.Remove();
953                    //LocalStorageCache.AuthenticatedUserSubscription.Remove();
954                    LocalStorageCache.AuthenticatedUserJournalAccount.Remove();
955
956                    LocalStorageCache.AuthenticatedUserPlatformTour.Remove();
957
958                    LocalStorageCache.AuthenticatedUserAccess.Remove();
959                    LocalStorageCache.IsEligibleForPrimeFreeTrial.Remove();
960
961                    LocalStorageCache.NotifSettings.Remove();
962
963                    LocalStorageCache.IntrusiveShowman.Remove();
964
965                    //LocalStorageCache.GlobalBrokerPartnerVirtualTradeShowman.Remove();
966                    //LocalStorageCache.GlobalBrokerPartnerWatcherShowman.Remove();
967
968
969                    LocalStorageCache.PendingCashInDateLastDisplay.Remove();
970                    LocalStorageCache.WalletPendingCashInOverview.Remove();
971
972
973                    LocalStorageCache.TradeCompetitionLeaderboardHomePage.Remove();
974                    //LocalStorageCache.EligibleInternalPromo.Remove();
975                    //LocalStorageCache.MainSubscriptionAccessTypeTrafficSource.Remove();
976                    LocalStorageCache.UserAccessTypeString.Remove();
977                    LocalStorageCache.TaskFromHomeWithDestinationPage.Remove();
978
979                    LocalStorageCache.SubscriptionSession.Remove();
980                    LocalStorageCache.DiscountReminderLastDisplayDate.Remove();
981                    LocalStorageCache.GemsIsClaimedLogInRewardOfTheDay.Remove();
982
983                    LocalStorageCache.UserSettingsQuickAccess.Remove();
984                    LocalStorageCache.UserTwitterIntegration.Remove();
985
986                    LocalStorageCache.MarketTrackerExchangeType.Remove();
987                    LocalStorageCache.MarketHealthTimeRangeType.Remove();
988                    LocalStorageCache.MarketSignalTimeRangeType.Remove();
989                    LocalStorageCache.MarketSignalType.Remove();
990
991                    LocalStorageCache.HomeScreenerSideTabState.Remove();
992                    LocalStorageCache.OpenInvestaSelectedCategory.Remove();
993                    LocalStorageCache.SocialPostMostMentionedStockBannerData.Remove();
994
995                    LocalStorageCache.PortfolioHoldingsByGuestUser.Remove();
996                    LocalStorageCache.UserPortfolioTypeSelected.Remove();
997                    // PageUrlConstant.RedirectToLoginPage("");
998                    // Redirect to host url for now (Open Investa)
999                    window.location = window.host;
1000
1001                    hideHeaderLoader();
1002                    $scope.UserNav.IsLoading = false;
1003
1004                }, function (error) {
1005                    hideHeaderLoader();
1006                    $scope.UserNav.IsLoading = false;
1007                    showErrorResponse(error);
1008                });
1009            },
1010
1011
1012            updateUserDefaultExchange: function (exchangeType, resultGroup, callbackSuccess, callbackError) {
1013
1014                $scope.UserNav.IsLoading = true;
1015                showHeaderLoader();
1016
1017                userApiService.updateUserDefaultExchange(exchangeType).then(function (result) {
1018
1019                    if (result.data) {
1020
1021                        if (resultGroup != null && typeof resultGroup != 'undefined') {
1022                            //Specific for caller with intended data to dispay (chart page)
1023                            $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultResultGroup = resultGroup;
1024                        }
1025
1026                        //overal settings by selected exchange 
1027                        $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultExchange = exchangeType;
1028                        $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultRegion = result.data;
1029
1030                    }
1031
1032                    LocalStorageCache.AuthenticatedUserProfile.Set($scope.UserNav.AuthenticatedUserProfile);
1033
1034                    $scope.UserNav.IsLoading = false;
1035                    hideHeaderLoader();
1036
1037                    callbackSuccess();
1038
1039                }, function (error) {
1040                    $scope.UserNav.IsLoading = false;
1041                    hideHeaderLoader();
1042                    showErrorResponse(error);
1043                    callbackError();
1044                });
1045
1046            },
1047
1048            updateIsDonePortfoliov2Onboarding: function () {
1049
1050                var authenticatedUserProfileTemp = LocalStorageCache.AuthenticatedUserProfile.Get();
1051
1052                authenticatedUserProfileTemp.IsDonePortfoliov2Onboarding = true;
1053
1054                LocalStorageCache.AuthenticatedUserProfile.Set(authenticatedUserProfileTemp);
1055            },
1056
1057            updateIsDonePortfoliov2HomeOnboarding: function () {
1058
1059                var authenticatedUserProfileTemp = LocalStorageCache.AuthenticatedUserProfile.Get();
1060
1061                authenticatedUserProfileTemp.IsDonePortfoliov2HomeOnboarding = true;
1062
1063                LocalStorageCache.AuthenticatedUserProfile.Set(authenticatedUserProfileTemp);
1064            },
1065
1066
1067            getUserSessionProfile: function () {
1068
1069                if (!$scope.UserNav.GetUserSessionProfileIsLoading && $scope.UserNav.AuthenticatedUserId > 0) {
1070                    $scope.UserNav.GetUserSessionProfileIsLoading = true;
1071
1072                    showHeaderLoader();
1073
1074                    userApiService.getUserSessionProfile().then(function (result) {
1075
1076
1077                        if (result.data != null) {
1078
1079                            $scope.UserNav.AuthenticatedUserProfile = result.data;
1080                            $rootScope.AuthenticatedUserProfile = $scope.UserNav.AuthenticatedUserProfile;
1081
1082                            LocalStorageCache.AuthenticatedUserProfile.Set($scope.UserNav.AuthenticatedUserProfile);
1083
1084                            $scope.UserNav.postProcessingAfterRetreivingUserProfile(false);
1085                        }
1086
1087
1088                        $scope.UserNav.GetUserSessionProfileIsLoading = false;
1089                        hideHeaderLoader();
1090
1091
1092                    }, function (error) {
1093                        $scope.UserNav.GetUserSessionProfileIsLoading = false;
1094                        hideHeaderLoader();
1095                        showErrorResponse(error);
1096                    });
1097
1098
1099                }
1100            },
1101
1102
1103            getOwnPrimaryWallet: function (callback) {
1104
1105                LocalStorageCache.AuthenticatedUserPrimaryWallet.Remove();
1106
1107                if ($scope.UserNav.AuthenticatedUserId > 0) {
1108
1109                    $scope.UserNav.Wallet.IsLoading = true;
1110                    showHeaderLoader();
1111
1112                    walletApiService.getOwnPrimaryWallet().then(function (result) {
1113
1114                        $scope.UserNav.Wallet.PrimaryWallet = result.data;
1115
1116                        LocalStorageCache.AuthenticatedUserPrimaryWallet.Set($scope.UserNav.Wallet.PrimaryWallet);
1117
1118                        $scope.UserNav.postProcessingAfterRetreivingUserPrimaryWallet(true);
1119
1120                        if (callback)
1121                            callback(result.data);
1122
1123                        hideHeaderLoader();
1124                        $scope.UserNav.Wallet.IsLoading = false;
1125
1126
1127                    }, function (error) {
1128                        hideHeaderLoader();
1129                        $scope.UserNav.Wallet.IsLoading = false;
1130                        showErrorResponse(error);
1131
1132                    });
1133
1134                }
1135
1136
1137            },
1138
1139            postProcessingAfterRetreivingUserPrimaryWallet: function (isCameFromLocalStorage) {
1140                $rootScope.$broadcast("getUserPrimaryWallet", $scope.UserNav.Wallet.PrimaryWallet, isCameFromLocalStorage);
1141            },
1142
1143
1144
1145
1146
1147            navigateToUserProfile: function () {
1148                PageUrlConstant.Profile.ExecuteOriginalUrl(false, $scope.UserNav.AuthenticatedUserProfile.SocialProfileInfo.Username);
1149            },
1150
1151            navigateToPortfolioV2: function () {
1152
1153                if ($scope.UserNav.ActivePanel != "Portfolio V2") {
1154                    PageUrlConstant.PortfolioV2.ExecuteOriginalUrl();
1155                }
1156            },
1157
1158
1159            navigateAndTrackToMultiCharts: function (isWebView) {
1160
1161                var feature = isWebView ? "NavBar Journey: Multicharts Mobile" : "NavBar Journey: Multicharts";
1162                $rootScope.$broadcast("startTrackActionStepsAndFeature", feature, "Login", "Click Multicharts from Main NavBar");
1163                $rootScope.$broadcast("setUserJourneyDataForLoginPage");
1164                PageUrlConstant.ChartMultiple.ExecuteOriginalUrl(true);
1165            },
1166
1167            navigateAndTrackToPortfolioV2: function (isWebView, action) {
1168
1169                if (!$scope.UserNav.IsUserLoggedOn) {
1170                    var feature = isWebView ? "NavBar Journey: PortfolioV2 Mobile" : "NavBar Journey: PortfolioV2";
1171                    $rootScope.$broadcast("startTrackActionStepsAndFeature", feature, "Login", action);
1172                    $rootScope.$broadcast("setUserJourneyDataForLoginPage");
1173
1174                    PageUrlConstant.PortfolioV2.ExecuteOriginalUrl(true);
1175                }
1176                else if ($scope.UserNav.ActivePanel != "Portfolio V2") {
1177                    PageUrlConstant.PortfolioV2.ExecuteOriginalUrl();
1178                }
1179
1180
1181            },
1182
1183            navigateAndTrackToPortfolioV2Dashboard: function (isWebView, action) {
1184                if (!$scope.UserNav.IsUserLoggedOn) {
1185                    var feature = isWebView ? "NavBar Journey: PortfolioV2 Dashboard Mobile" : "NavBar Journey: PortfolioV2 Dashboard";
1186                    $rootScope.$broadcast("startTrackActionStepsAndFeature", feature, "Login", action);
1187                    $rootScope.$broadcast("setUserJourneyDataForLoginPage");
1188
1189                    PageUrlConstant.PortfolioV2Dashboard.ExecuteOriginalUrl(true);
1190                }
1191                else if ($scope.UserNav.ActivePanel != "PortfolioV2 Dashboard") {
1192                    PageUrlConstant.PortfolioV2Dashboard.ExecuteOriginalUrl();
1193                }
1194            },
1195
1196
1197
1198            navigateToPrimeLandingPage: function (trafficSource, trackerName, displayModal, fold) {
1199
1200                if (!trafficSource) {
1201
1202                    if ($scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial) {
1203                        trafficSource = Constant.TrafficSource.TRY_FREE_TRIAL;
1204                    }
1205                    else {
1206                        trafficSource = Constant.TrafficSource.UPGRADE_PRIME;
1207                    }
1208                }
1209
1210                if (!trackerName) {
1211                    trackerName = Constant.TrackerName.NAV;
1212                }
1213
1214
1215                var invsrc = generateFullWebTrackingSource(trafficSource, trackerName, displayModal);
1216
1217                PageUrlConstant.InvestaPrime.ExecuteOriginalUrl(invsrc, null, fold, true);
1218            },
1219
1220            navigateToPrimeUpgradePage: function (trafficSource, trackerName, displayModal) {
1221                var invsrc = generateFullWebTrackingSource(trafficSource, trackerName, displayModal);
1222                PageUrlConstant.PrimeUpgrade.ExecuteOriginalUrl(invsrc);
1223            },
1224
1225            navigateToHelp: function (openNewTab) {
1226                if (openNewTab) {
1227                    window.open("https://help.investagrams.com/");
1228                } else {
1229                    window.location = "https://help.investagrams.com/";
1230                }
1231            },
1232
1233            navigateToPrimeHighlights: function () {
1234
1235                if ($scope.UserNav.ActivePanel == 'OpenInvesta') {
1236                    //user is currently in Home page
1237                    $rootScope.$broadcast("setOpenInvestaCategory", 9);
1238                }
1239                else {
1240                    //Go to Home page > Prime category
1241                    return PageUrlConstant.Home.ExecuteOriginalUrl(true, "prime");
1242                }
1243            },
1244
1245            getInvestaTradeLink: function (customParam) {
1246                if (customParam) {
1247                    return PageUrlConstant.InvestaTradeSessionHandover.Url + "?ret=" + encodeURIComponent(getInvestaTradeUrl() + "?" + customParam)
1248                }
1249
1250                return PageUrlConstant.InvestaTradeSessionHandover.Url;
1251            },
1252
1253            getInvestaFundsLink: function (customParam) {
1254                if (customParam) {
1255                    return PageUrlConstant.InvestaFundsSessionHandover.Url + "?ret=" + encodeURIComponent(getInvestaFundsUrl() + "?" + customParam)
1256                }
1257
1258                return PageUrlConstant.InvestaFundsSessionHandover.Url;
1259            },
1260
1261            navigateContactUs: function (openNewTab) {
1262                if (openNewTab) {
1263                    window.open(PageUrlConstant.ContactUs.Url);
1264                }
1265                else {
1266                    window.location = PageUrlConstant.ContactUs.Url;
1267                }
1268            },
1269
1270            navigateToUpgradePlanPage: function (trafficSource, trackerName, displayModal) {
1271                var invsrc = generateFullWebTrackingSource(trafficSource, trackerName, displayModal);
1272                PageUrlConstant.Upgrade.ExecuteOriginalUrl(invsrc);
1273            },
1274
1275            navigateToPSEPlanPage: function (trafficSource, trackerName, displayModal) {
1276                var invsrc = generateFullWebTrackingSource(trafficSource, trackerName, displayModal);
1277
1278                PageUrlConstant.PSEPlan.ExecuteOriginalUrl(invsrc, true);
1279            },
1280
1281            navigateToFreeTrial: function (trafficSource, trackerName, displayModal) {
1282
1283                if (trafficSource == null || trafficSource == undefined) {
1284                    trafficSource = Constant.TrafficSource.TRY_FREE_TRIAL;
1285                }
1286
1287                if (trackerName == null || trackerName == undefined) {
1288                    trackerName = Constant.TrackerName.NAV;
1289                }
1290
1291                var invsrc = generateFullWebTrackingSource(trafficSource, trackerName, displayModal);
1292
1293                PageUrlConstant.Freetrial.ExecuteOriginalUrl(170, "free", invsrc, true);
1294            },
1295
1296            navigatePrimeUpgrade: function (invId) {
1297
1298                var subSession = $scope.UserNav.UserSubscription.SubscriptionSession;
1299
1300                if (subSession && subSession.MainSubscription && subSession.MainSubscription.RemainingDaysBeforeExpired > 0) {
1301                    var invsrc = generateFullWebTrackingSource(Constant.TrafficSource.NAV, Constant.TrackerName.UPGRADE_ANNUAL_ELITE);
1302
1303                    PageUrlConstant.Checkout.ExecuteUrlWithAdditionalParameterLink(invId, invsrc, true);
1304                }
1305                else {
1306                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.NAV, Constant.TrackerName.UPGRADE_TO_PRIME, null, 'pricing');
1307                }
1308            },
1309
1310            //navigateToEliteOnboarding: function () {
1311            //    PageUrlConstant.EliteOnboarding.ExecuteOriginalUrl(true);
1312
1313            //},
1314
1315
1316            //cTA for userNav and social
1317            ctaPrimeUpgrade: function (isfromProfile) {
1318
1319                var trafficSource = Constant.TrafficSource.UPGRADE_PRIME;
1320
1321                if ($scope.UserNav.UserAccess.isShowUpgradeToPrime) {
1322                    trafficSource = Constant.TrafficSource.UPGRADE_NOW;
1323                }
1324
1325                var trackerName = (isfromProfile) ? Constant.TrackerName.PROFILE : Constant.TrackerName.NAV;
1326                $scope.UserNav.navigateToPrimeLandingPage(trafficSource, trackerName);
1327            },
1328
1329            ctaPrimeRenew: function (isfromProfile) {
1330                var trafficSource = Constant.TrafficSource.RENEW_PLAN;
1331                var trackerName = (isfromProfile) ? Constant.TrackerName.PROFILE : Constant.TrackerName.NAV;
1332                $scope.UserNav.navigateToPrimeLandingPage(trafficSource, trackerName);
1333            },
1334
1335            ctaPrimeTrial: function () {
1336
1337                if ($scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial) {
1338                    $scope.UserNav.navigateToFreeTrial();
1339                }
1340                else {
1341                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.RENEW_PLAN, Constant.TrackerName.NAV, "Page");
1342                }
1343            },
1344
1345            postProcessingAfterRetreivingUserProfile: function (isCameFromLocalStorage) {
1346
1347                if (!$scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultExc
1347hange) {
1348                    $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultExchange = 1;
1349                }
1350
1351                if (!$scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultRegion) {
1352                    $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultRegion = "PH";
1353                }
1354
1355                if (!$scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultResultGroup) {
1356                    $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultResultGroup = { V: "Default", T: "All PH Stocks" };
1357                }
1358
1359                $scope.UserNav.UserHeaderStyle = {
1360                    "background": "linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.6)), url('" + $scope.UserNav.AuthenticatedUserProfile.SocialProfileInfo.HeaderPhotoUrl + "') center",
1361                    "background-size": "cover"
1362                };
1363
1364
1365                $scope.UserNav.UserAccess.initUserAccess();
1366
1367
1368                $rootScope.$broadcast("getAuthenticatedUserProfile", $scope.UserNav.AuthenticatedUserProfile, isCameFromLocalStorage);
1369
1370                //$timeout(function () {
1371                //    $rootScope.$broadcast("getAuthenticatedUserProfile", $scope.UserNav.AuthenticatedUserProfile, isCameFromLocalStorage);
1372                //}, 100);
1373
1374
1375                setTimeout(function () { tryNotifRequestPermissionViaClickEvent(); }, 800);
1376
1377
1378            },
1379
1380            requestNotificationPermission: function () {
1381
1382                tryNotifRequestPermissionViaClickEvent();
1383            },
1384
1385
1386            getDeviceId: function () {
1387
1388                var resultDeviceId = LocalStorageCache.InvestaGeneratedDeviceId.Get();
1389
1390                if (!resultDeviceId) {
1391
1392                    var unixtimestamp = Math.round((new Date()).getTime() / 1000);
1393
1394                    var gaClientIdTemp = "0000";
1395
1396                    try {
1397
1398                        gaClientIdTemp = gaClientId;
1399
1400                        if (!gaClientIdTemp) {
1401                            gaClientIdTemp = "0000";
1402                        }
1403
1404                        var guid = createGuid();
1405
1406
1407                        resultDeviceId = unixtimestamp + "-" + guid + "-" + gaClientIdTemp;
1408                    }
1409                    catch (ex) {
1410                        console.error(ex);
1411
1412                        resultDeviceId = unixtimestamp + "-" + gaClientIdTemp;
1413                    }
1414
1415                    LocalStorageCache.InvestaGeneratedDeviceId.Set(resultDeviceId);
1416                }
1417
1418                return resultDeviceId;
1419            },
1420
1421            getUserPrivateStats: function () {
1422
1423                if ($scope.UserNav.AuthenticatedUserId > 0) {
1424                    $scope.UserNav.IsLoading = true;
1425
1426                    showHeaderLoader();
1427
1428                    userApiService.getUserPrivateStats().then(function (result) {
1429                        if (result.data != null) {
1430                            $scope.UserNav.UserPrivateStats = result.data;
1431                            LocalStorageCache.UserPrivateStats.Set($scope.UserNav.UserPrivateStats);
1432                        }
1433
1434                        $scope.UserNav.IsLoading = false;
1435                        hideHeaderLoader();
1436
1437
1438                    }, function (error) {
1439                        $scope.UserNav.IsLoading = false;
1440                        hideHeaderLoader();
1441                        showErrorResponse(error);
1442                    });
1443
1444
1445                }
1446            },
1447
1448            getDefaultExchangeWithChecking: function () {
1449
1450                if ($scope.UserNav.AuthenticatedUserProfile && $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultExchange)
1451                    return $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultExchange;
1452                else
1453                    return Enum.StockExchangeEnum.PSE;
1454            },
1455
1456
1457            getDefaultResultGroupChecking: function () {
1458
1459                if ($scope.UserNav.AuthenticatedUserProfile && $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultResultGroup)
1460                    return $scope.UserNav.AuthenticatedUserProfile.UserInfo.DefaultResultGroup;
1461                else
1462                    return { V: "Default", T: "All PH Stocks" }
1463            },
1464
1465            initValue: function () {
1466
1467                if ($scope.UserNav.AuthenticatedUserId > 0) {
1468
1469                    $scope.UserNav.IsLoading = true;
1470
1471                    var authenticatedUserProfileTemp = LocalStorageCache.AuthenticatedUserProfile.Get();
1472
1473                    if (authenticatedUserProfileTemp != null &&
1474                        authenticatedUserProfileTemp.UserInfo != null &&
1475                        authenticatedUserProfileTemp.SocialProfileInfo.Username != '' &&
1476                        authenticatedUserProfileTemp.UserInfo.UserId == $scope.UserNav.AuthenticatedUserId) {
1477
1478                        $scope.UserNav.AuthenticatedUserProfile = authenticatedUserProfileTemp;
1479                        $rootScope.AuthenticatedUserProfile = $scope.UserNav.AuthenticatedUserProfile;
1480
1481                        $scope.UserNav.postProcessingAfterRetreivingUserProfile(true);
1482                    }
1483                    else {
1484                        LocalStorageCache.AuthenticatedUserProfile.Remove();
1485
1486                        $scope.UserNav.getUserSessionProfile();
1487                    }
1488
1489
1490                    $scope.UserNav.Wallet.PrimaryWallet = LocalStorageCache.AuthenticatedUserPrimaryWallet.Get();
1491
1492                    if ($scope.UserNav.Wallet.PrimaryWallet != null &&
1493                        $scope.UserNav.Wallet.PrimaryWallet.UserId == $scope.UserNav.AuthenticatedUserId) {
1494
1495                        $scope.UserNav.postProcessingAfterRetreivingUserPrimaryWallet(false);
1496
1497                    }
1498                    else {
1499                        $scope.UserNav.getOwnPrimaryWallet();
1500                    }
1501
1502                    ////TODO: for replacement
1503                    //$scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial = LocalStorageCache.IsEligibleForPrimeFreeTrial.Get();
1504
1505                    //if ($scope.UserNav.UserFreeTrial.IsEligibleForPrimeFreeTrial == null) {
1506
1507                    //    $scope.UserNav.UserFreeTrial.getIsEligibleForPrimeFreeTrial();
1508                    //}
1509
1510                    //$scope.UserNav.UserSubscription.EligibleInternalPromo = LocalStorageCache.EligibleInternalPromo.Get();
1511
1512                    //if ($scope.UserNav.UserSubscription.EligibleInternalPromo == null) {
1513                    //    $scope.UserNav.UserSubscription.getEligibleInternalPromo();
1514                    //}
1515                    //else {
1516                    //    $scope.UserNav.UserSubscription.getSubscriptionRemainingDaysForEligiblePromoPeriod();
1517                    //}
1518
1519                    ////TODO: for replacement
1520                    //$scope.UserNav.UserSubscription.MainSubscriptionAccessTypeTrafficSource = LocalStorageCache.MainSubscriptionAccessTypeTrafficSource.Get();
1521
1522                    //if ($scope.UserNav.UserSubscription.MainSubscriptionAccessTypeTrafficSource == null) {
1523                    //    $scope.UserNav.UserSubscription.getMainSubscriptionAccessTypeTrafficSource();
1524                    //}
1525
1526
1527                    $scope.UserNav.UserSubscription.SubscriptionSession = LocalStorageCache.SubscriptionSession.Get();
1528
1529                    if ($scope.UserNav.UserSubscription.SubscriptionSession == null) {
1530                        $scope.UserNav.UserSubscription.getSubscriptionSession();
1531                    }
1532                    else {
1533                        $scope.UserNav.UserSubscription.setMainSubscriptionOtherDetails();
1534                    }
1535
1536
1537                    var privateStats = LocalStorageCache.UserPrivateStats.Get();
1538
1539                    if (privateStats != null) {
1540                        $scope.UserNav.UserPrivateStats = privateStats;
1541                    }
1542                    else {
1543                        $scope.UserNav.getUserPrivateStats();
1544                    }
1545
1546                    $scope.UserNav.SavedPost.setShowNudge();
1547                }
1548                else {
1549                    $scope.GlobalNav.ButtonCTA.init();
1550                    $rootScope.$broadcast("doneInitUnregisteredUser", true);
1551
1552                    $scope.Showman.renderEligibleUserGoogleShowman();
1553                }
1554
1555
1556                $rootScope.$broadcast("initUserJourneyEvent");
1557            }
1558
1559
1560        };
1561
1562
1563
1564        $scope.Showman = {
1565
1566            RandomNumber: generateRandomInt(0, 100),
1567
1568            IsPopupShowmanActive: false,
1569            IsIntrusiveAlreadyDisplay: false,
1570            IsPopupOnDisplay: false,
1571
1572            isShowByChances: function (fromPercentage, toPercentage) {
1573
1574                //console.log("Showman Random Number: " + $scope.Showman.RandomNumber);
1575
1576                if ($scope.Showman.RandomNumber >= fromPercentage &&
1577                    $scope.Showman.RandomNumber <= toPercentage) {
1578                    return true;
1579                }
1580
1581                return false;
1582
1583            },
1584
1585
1586            viewGenericSubscribePrimePlusDialog: function () {
1587                $('#GenericSubscribePrimePlusDialog').modal('show');
1588            },
1589
1590            refreshUserAccess: function () {
1591                $('#GenericSubscribePrimePlusDialog').modal('hide');
1592                $scope.UserNav.UserAccess.getUserAccess();
1593
1594            },
1595
1596            renderEligibleUserGoogleShowman: function () {
1597
1598                setTimeout(function () {
1599
1600                    if ($scope.UserNav.UserAccess.isShowInvestaPrimeAds && $scope.UserNav.UserAccess.isPageAllowToShowShowman) {
1601                        setTimeout(function () {
1602                            loadGoogleShowmanScript();
1603                        }, 1000);
1604                    }
1605                    else {
1606                        hideAllGoogleShowmanDisplay();
1607                    }
1608
1609                }, 10);
1610
1611            },
1612
1613            //IsLowerLeftVisible: false,
1614
1615            //setLowerLeftCache: function () {
1616            //    var currentDate = new Date();
1617            //    currentDate.setHours(0, 0, 0, 0);
1618
1619            //    var lowerLeftCache = {
1620            //        UserId: $scope.UserNav.AuthenticatedUserId,
1621            //        Date: new Date().setHours(0, 0, 0, 0)
1622            //    };
1623
1624            //    LocalStorageCache.TimelineLowerLeftShowman.Set(lowerLeftCache);
1625            //},
1626
1627            //viewLowerLeft: function () {
1628            //    // Check if user should be shown ads
1629            //    var maxDate = new Date(2022, 04, 19);
1630
1631            //    var currentDate = new Date();
1632            //    currentDate.setHours(0, 0, 0, 0);
1633
1634            //    if (currentDate <= maxDate) {
1635            //        var lastCache = LocalStorageCache.TimelineLowerLeftShowman.Get();
1636
1637            //        // Check if user is not shown ads for today
1638            //        if (!lastCache || lastCache.UserId != $scope.UserNav.AuthenticatedUserId || new Date(lastCache.Date) < currentDate) {
1639
1640            //            var callback = function (wallet) {
1641            //                if (wallet) {
1642            //                    if (wallet.Credits >= 500) {
1643            //                        $scope.Showman.IsLowerLeftVisible = true;
1644            //                    } else {
1645            //                        // Set to cache to avoid retrieve for today since user has no credit
1646            //                        $scope.Showman.setLowerLeftCache();
1647            //                    }
1648            //                }
1649            //            };
1650
1651            //            $scope.UserNav.getOwnPrimaryWallet(callback);
1652            //        }
1653            //    }
1654            //},
1655
1656            //closeLowerLeft: function () {
1657            //    $scope.Showman.IsLowerLeftVisible = false;
1658            //    // Set cache closed today
1659            //    $scope.Showman.setLowerLeftCache();
1660            //},
1661
1662            initValue: function () {
1663
1664
1665            }
1666
1667        };
1668
1669
1670        //Platform Tour Related Global
1671        $scope.PlatformTourNav = {
1672
1673            IsLoading: false,
1674
1675            UserPlatformTour: null,
1676
1677            IsPlatformTourOngoing: false,
1678
1679
1680            getUserPlatformTour: function (forceRetrieveFromServer, callbackFunc) {
1681
1682                $scope.PlatformTourNav.UserPlatformTour = LocalStorageCache.AuthenticatedUserPlatformTour.Get();
1683
1684                if (gaAuthenticatedUserId > 0 && (!$scope.PlatformTourNav.UserPlatformTour || forceRetrieveFromServer)) {
1685
1686                    LocalStorageCache.AuthenticatedUserPlatformTour.Remove();
1687
1688                    $scope.PlatformTourNav.IsLoading = true;
1689
1690                    userPlatformTourApiService.getUserPlatformTourByUserId().then(function (result) {
1691
1692                        $scope.PlatformTourNav.UserPlatformTour = result.data;
1693
1694                        LocalStorageCache.AuthenticatedUserPlatformTour.Set($scope.PlatformTourNav.UserPlatformTour);
1695
1696                        $scope.PlatformTourNav.IsLoading = false;
1697
1698                        if (callbackFunc)
1699                            callbackFunc(result.data);
1700
1701                    }, function (error) {
1702                        $scope.PlatformTourNav.IsLoading = false;
1703                        showErrorResponse(error);
1704                    });
1705                }
1706                else {
1707                    callbackFunc();
1708                }
1709            },
1710
1711
1712
1713            updateIsWebHomeDone: function (value) {
1714
1715                $scope.PlatformTourNav.IsLoading = true;
1716                showHeaderLoader();
1717
1718                userPlatformTourApiService.updateIsWebHomeDone(value).then(function (result) {
1719
1720                    $scope.PlatformTourNav.IsLoading = false;
1721                    hideHeaderLoader();
1722
1723                    if ($scope.PlatformTourNav.UserPlatformTour) {
1724                        $scope.PlatformTourNav.UserPlatformTour.IsWebHomeDone = value;
1725
1726                        LocalStorageCache.AuthenticatedUserPlatformTour.Set($scope.PlatformTourNav.UserPlatformTour);
1727
1728                    }
1729
1730
1731                }, function (error) {
1732                    $scope.PlatformTourNav.IsLoading = false;
1733                    hideHeaderLoader();
1734                    showErrorResponse(error);
1735                });
1736
1737            },
1738
1739            updateIsWebPortfolioSyncDone: function (value) {
1740
1741                $scope.PlatformTourNav.IsLoading = true;
1742                showHeaderLoader();
1743
1744                userPlatformTourApiService.updateIsWebPortfolioSyncDone(value).then(function (result) {
1745
1746                    $scope.PlatformTourNav.IsLoading = false;
1747                    hideHeaderLoader();
1748
1749                    if ($scope.PlatformTourNav.UserPlatformTour) {
1750                        $scope.PlatformTourNav.UserPlatformTour.IsWebPortfolioSyncDone = value;
1751
1752                        LocalStorageCache.AuthenticatedUserPlatformTour.Set($scope.PlatformTourNav.UserPlatformTour);
1753
1754                    }
1755
1756
1757                }, function (error) {
1758                    $scope.PlatformTourNav.IsLoading = false;
1759                    hideHeaderLoader();
1760                    showErrorResponse(error);
1761                });
1762
1763            },
1764
1765            updateIsWebPortfolioManualDone: function (value) {
1766
1767                $scope.PlatformTourNav.IsLoading = true;
1768                showHeaderLoader();
1769
1770                userPlatformTourApiService.updateIsWebPortfolioManualDone(value).then(function (result) {
1771
1772                    $scope.PlatformTourNav.IsLoading = false;
1773                    hideHeaderLoader();
1774
1775                    if ($scope.PlatformTourNav.UserPlatformTour) {
1776                        $scope.PlatformTourNav.UserPlatformTour.IsWebPortfolioManualDone = value;
1777
1778                        LocalStorageCache.AuthenticatedUserPlatformTour.Set($scope.PlatformTourNav.UserPlatformTour);
1779                    }
1780
1781
1782                }, function (error) {
1783                    $scope.PlatformTourNav.IsLoading = false;
1784                    hideHeaderLoader();
1785                    showErrorResponse(error);
1786                });
1787            }
1788        };
1789
1790        $scope.PlatformNotice = {
1791            Data: {},
1792            click: function () {
1793                if ($scope.PlatformNotice.Data && $scope.PlatformNotice.Data.LinkUrl)
1794                    window.location = $scope.PlatformNotice.Data.LinkUrl;
1795            },
1796            DelayedDisplayFunction: null,
1797            DonePostProcessPlatformTutorial: false,
1798            DonePostProcessGenericPage: false,
1799            DisplayNotice: false
1800        };
1801
1802
1803        //Angular version of the openLinkWindow JS
1804        $scope.openLinkWindow = function (url) {
1805            openLinkWindow(url);
1806        };
1807
1808
1809        $scope.DarkMode = {
1810            Controller: null,
1811            IsActive: false,
1812
1813            initDarkMode: function () {
1814                if (typeof Darkmode === "undefined" || !Darkmode)
1815                    return;
1816
1817
1818                if (!DarkmodeObject) {
1819                    DarkmodeObject = new Darkmode(ConstantStyle.DarkmodeOptions);
1820                }
1821
1822                var theme = getParameterByName("theme");
1823                var defaultDarkMode = null;
1824
1825                if (theme) {
1826                    switch (theme.toLocaleLowerCase()) {
1827                        case 'dark':
1828                            defaultDarkMode = true;
1829                            break;
1830                        case 'light':
1831                            defaultDarkMode = false;
1832                            break;
1833                    }
1834                }
1835
1836                if (defaultDarkMode != null) {
1837                    if ((defaultDarkMode && !DarkmodeObject.isActivated()) ||
1838                        (!defaultDarkMode && DarkmodeObject.isActivated()))
1839                        DarkmodeObject.toggle();
1840                }
1841
1842                $scope.DarkMode.Controller = DarkmodeObject;
1843                $scope.DarkMode.IsActive = $scope.DarkMode.Controller.isActivated();
1844                $rootScope.$broadcast("doneToggleDarkMode", $scope.DarkMode.IsActive);
1845            },
1846
1847            toggle: function () {
1848                if (headerLoaderCount <= 0) {
1849                    $scope.DarkMode.Controller.toggle();
1850                    $scope.DarkMode.IsActive = $scope.DarkMode.Controller.isActivated();
1851                    $rootScope.$broadcast("doneToggleDarkMode", $scope.DarkMode.IsActive);
1852                }
1853            }
1854        };
1855
1856
1857        $scope.LoginPrompt = {
1858            IsForceDisplay: false,
1859            IsOpLoginForm: true,
1860
1861            ShowPrompt: false,
1862            TargetUrl: null,
1863            togglePrompt: function (show, trackEventAction) {
1864                $scope.LoginPrompt.ShowPrompt = show;
1865
1866                if (show) {
1867                    $scope.LoginPrompt.IsOpLoginForm = true;//always set this everytime LoginPrompt show
1868
1869                    if (trackEventAction) {
1870                        $rootScope.$broadcast("trackActionSteps", "Show Login Prompt");
1871                    }
1872                }
1873            },
1874            checkIsLoggedIn: function (event, toggleId) {
1875                if (!$scope.UserNav.IsUserLoggedOn) {
1876                    event.stopPropagation();
1877                    event.preventDefault()
1878
1879                    $scope.LoginPrompt.TargetUrl = null;
1880
1881                    var anchor = event.target.closest("a");
1882                    if (anchor) {
1883
1884                        var targetUrl = anchor.getAttribute('href');
1885                        if (targetUrl) {
1886                            $scope.LoginPrompt.TargetUrl = targetUrl;
1887                        }
1888
1889                    }
1890
1891                    $scope.LoginPrompt.togglePrompt(true);
1892
1893                    if (toggleId) {
1894                        $('#' + toggleId).dropdown('toggle');
1895                    }
1896
1897                    return false;
1898                }
1899
1900                return true;
1901            },
1902
1903            //Track user Journey if not loggedIn
1904            checkAndTrackIsLoggedIn: function (event, toggleId, userJourneyFeature, targetFeature, userJourneyScenario, userJourneyAction) {
1905                if (!$scope.UserNav.IsUserLoggedOn) {
1906                    event.stopPropagation();
1907                    event.preventDefault()
1908
1909                    $scope.LoginPrompt.TargetUrl = null;
1910
1911                    var anchor = event.target.closest("a");
1912
1913                    if (anchor) {
1914
1915                        var targetUrl = anchor.getAttribute('href');
1916                        if (targetUrl) {
1917                            $scope.LoginPrompt.TargetUrl = targetUrl;
1918                        }
1919                    }
1920
1921                    if (userJourneyFeature && userJourneyScenario && userJourneyAction) {
1922
1923                        $scope.LoginPrompt.TargetFeature = targetFeature;
1924
1925                        $rootScope.$broadcast("startTrackActionStepsAndFeature", userJourneyFeature + ": " + targetFeature, userJourneyScenario, userJourneyAction);
1926                    }
1927
1928                    $scope.LoginPrompt.togglePrompt(true, true);
1929
1930                    if (toggleId) {
1931                        $('#' + toggleId).dropdown('toggle');
1932                    }
1933
1934                    return false;
1935                }
1936
1937                return true;
1938            },
1939
1940            checkIsPrime: function (event, modal, source, tracker) {
1941                if (!$scope.UserNav.IsUserLoggedOn) {
1942                    event.stopPropagation();
1943                    event.preventDefault();
1944
1945                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.NAV, modal);
1946                }
1947                else if (!$scope.UserNav.UserAccess.hasPrimeAccess) {
1948                    event.stopPropagation();
1949                    event.preventDefault();
1950
1951                    $rootScope.$broadcast("triggerModalLimiter", modal);
1952                }
1953            },
1954            checkIsPrimePlusOrPrimeElite: function (event, modal, source, tracker) {
1955                if (!$scope.UserNav.IsUserLoggedOn) {
1956                    event.stopPropagation();
1957                    event.preventDefault();
1958
1959                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.NAV, modal);
1960                }
1961                else if (!$scope.UserNav.UserAccess.Data.IsInvestaPrimePlusNotExpired &&
1962                    !$scope.UserNav.UserAccess.Data.IsInvestaPrimeEliteNotExpired) {
1963                    event.stopPropagation();
1964                    event.preventDefault();
1965
1966                    $rootScope.$broadcast("triggerModalLimiter", modal);
1967                }
1968            },
1969            checkIsPrimeElite: function (event, modal, source, tracker) {
1970                if (!$scope.UserNav.IsUserLoggedOn) {
1971                    event.stopPropagation();
1972                    event.preventDefault();
1973
1974                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.NAV, modal);
1975                }
1976                else if (!$scope.UserNav.UserAccess.Data.IsInvestaPrimeEliteNotExpired) {
1977                    event.stopPropagation();
1978                    event.preventDefault();
1979
1980                    $rootScope.$broadcast("triggerModalLimiter", modal);
1981                }
1982            },
1983
1984            checkAndTrackIsPrimeElite: function (event, modal, userJourneyFeature, userJourneyScenario, userJourneyAction) {
1985                if (!$scope.UserNav.IsUserLoggedOn) {
1986                    event.stopPropagation();
1987                    event.preventDefault();
1988
1989                    $rootScope.$broadcast("startTrackActionStepsAndFeature", userJourneyFeature, "Guest " + userJourneyScenario, userJourneyAction);
1990                    $rootScope.$broadcast("setUserJourneyDataForPrimeLandingPage");
1991
1992                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.NAV, modal);
1993                }
1994                else if (!$scope.UserNav.UserAccess.Data.IsInvestaPrimeEliteNotExpired) {
1995                    event.stopPropagation();
1996                    event.preventDefault();
1997
1998                    $rootScope.$broadcast("triggerModalLimiter", modal);
1999                }
2000            },
2001            checkAndTrackIsPrimePlusOrPrimeElite: function (event, modal, userJourneyFeature, userJourneyScenario, userJourneyAction) {
2002                if (!$scope.UserNav.IsUserLoggedOn) {
2003                    event.stopPropagation();
2004                    event.preventDefault();
2005
2006                    $rootScope.$broadcast("startTrackActionStepsAndFeature", userJourneyFeature, "Guest " + userJourneyScenario, userJourneyAction);
2007                    $rootScope.$broadcast("setUserJourneyDataForPrimeLandingPage");
2008
2009                    $scope.UserNav.navigateToPrimeLandingPage(Constant.TrafficSource.NAV, modal);
2010                }
2011                else if (!$scope.UserNav.UserAccess.Data.IsInvestaPrimePlusNotExpired &&
2012                    !$scope.UserNav.UserAccess.Data.IsInvestaPrimeEliteNotExpired) {
2013                    event.stopPropagation();
2014                    event.preventDefault();
2015
2016                    $rootScope.$broadcast("triggerModalLimiter", modal);
2017                }
2018            },
2019
2020            checkIsPseData: function (event, source, tracker) {
2021                if (!$scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access) {
2022                    event.stopPropagation();
2023                    event.preventDefault();
2024
2025                    if (!source) {
2026                        source = Constant.TrafficSource.NAV;
2027                        tracker = Constant.TrackerName.NAV;
2028                    }
2029
2030                    $scope.UserNav.navigateToPSEPlanPage(source, tracker);
2031                }
2032            },
2033
2034            checkAndTrackIsPseData: function (event, source, tracker, userJourneyFeature, userJourneyScenario, userJourneyAction) {
2035                if (!$scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access) {
2036                    event.stopPropagation();
2037                    event.preventDefault();
2038
2039                    if (!source) {
2040                        source = Constant.TrafficSource.NAV;
2041                        tracker = Constant.TrackerName.NAV;
2042                    }
2043
2044                    $rootScope.$broadcast("startTrackActionStepsAndFeature", userJourneyFeature, userJourneyScenario + " Guest User", userJourneyAction);
2045                    $rootScope.$broadcast("setUserJourneyDataForPrimeLandingPage");
2046
2047                    $scope.UserNav.navigateToPSEPlanPage(source, tracker);
2048                }
2049            },
2050
2051            logInReminderInterval: null,
2052            checkIfNeedToShowLoginReminder: function () {
2053
2054                var timeInterval = Constant.TimeDurationConstant.Milliseconds.MINUTES_1;
2055
2056                if (isProdEnvironment) {
2057                    var timeInterval = Constant.TimeDurationConstant.Milliseconds.MINUTES_5;
2058                }
2059
2060                $scope.LoginPrompt.logInReminderInterval = setInterval(function () {
2061
2062
2063                    $scope.GlobalNav.checkIfThereAreOngoingModalOrPlatformTour(function () {
2064                        if (gaAuthenticatedUserId <= 0) {
2065                            //show LoginReminder modal
2066                            $scope.LoginPrompt.ShowPrompt = true;
2067                        }
2068                        else {
2069                            //clear interval here
2070                            clearInterval($scope.LoginPrompt.logInReminderInterval);
2071                            return;
2072                        }
2073                    });
2074
2075                }, timeInterval);
2076            }
2077        };        
2078
2079        $scope.CommonFunc = {
2080            getDefaultCurrencyByExchange: function (exchangeType) {
2081                switch (exchangeType) {
2082                    case Enum.StockExchangeEnum.PSE:
2083                    case Enum.StockExchangeEnum.PSEO:
2084                    case Enum.StockExchangeEnum.PHMF:
2085                        return "PHP";
2086                    default:
2087                        return "USD";
2088                }
2089            },
2090
2091            getCurrencySymbolByExchange: function (exchangeType) {
2092                var currency = $scope.CommonFunc.getDefaultCurrencyByExchange(exchangeType);
2093                return $filter('stringCurrencyToSymbol')(currency);
2094
2095            },
2096
2097            isVolTrackedByExchange: function (exchangeType) {
2098                switch (exchangeType) {
2099                    case Enum.StockExchangeEnum.CMD:
2100                    case Enum.StockExchangeEnum.INDEX:
2101                    case Enum.StockExchangeEnum.FX:
2102                        return false;
2103                    default:
2104                        return true;
2105                }
2106            },
2107
2108            getVolUnitString: function (exchangeType, code) {
2109                if (exchangeType == 400 || code) {
2110                    return code;
2111                }
2112                else
2113                    return 'shares';
2114            },
2115
2116            getAssetRealtimeIndicator: function (exchangeType, stockType) {
2117
2118
2119                var isRealtime = false;
2120                var indicatorLabel = "";
2121                var indicatorTooltip = "";
2122
2123                switch (exchangeType) {
2124                    case Enum.StockExchangeEnum.PSE:
2125
2126                        ////Temporary hide realtime indicator label for all PSE stocks
2127                        //if ($scope.UserNav.UserAccess.hasPSElvl1Orlvl2Access || $scope.UserNav.UserAccess.hasPrimeAccess) {
2128                        //    indicatorLabel = "Real-time";
2129                        //    isRealtime = true;
2130                        //}
2131                        //else {
2132                        //    indicatorLabel = "D";
2133                        //    indicatorTooltip = "Delayed";
2134                        //}
2135
2136                        break;
2137
2138                    case Enum.StockExchangeEnum.SGX:
2139                    case Enum.StockExchangeEnum.BONDS:
2140                        indicatorLabel = "D";
2141                        indicatorTooltip = "Delayed";
2142                        break;
2143
2144
2145                    case Enum.StockExchangeEnum.NYSE:
2146                    case Enum.StockExchangeEnum.NASDAQ:
2147
2148                        if (stockType != Enum.StockType.Index) {
2149                            indicatorLabel = "Real-time";
2150                            isRealtime = true;
2151                        }
2152
2153                        break;
2154
2155                    case Enum.StockExchangeEnum.CRYPTO:
2156                    default:
2157                        indicatorLabel = "Real-time";
2158                        isRealtime = true;
2159                        break;
2160                }
2161
2162                return {
2163                    Label: indicatorLabel,
2164                    Tooltip: indicatorTooltip,
2165                    IsRealtime: isRealtime
2166                };
2167            }
2168        };
2169
2170
2171
2172
2173        //Common Functions
2174        $scope.GlobalNav = {
2175
2176            IsMobilePhone: false,
2177            IsPortrait: true,
2178            IsTabletView: false,
2179
2180            IsOnboardingActive: false,//set this if there are any active on-boarding / patform tour
2181
2182            DesktopNotifPermission: null,
2183
2184            ButtonCTA: {
2185                Link: "https://invs.st/PrimeMomNav",
2186                EndDate: new Date(2023, 4, 16, 23, 59, 59), // 0 - January, 1 - February, etc
2187                Show: false,
2188                displayBtn: function (display) {
2189                    $scope.GlobalNav.ButtonCTA.Show = display;
2190                },
2191                showBtn: function () {
2192                    $scope.GlobalNav.ButtonCTA.displayBtn(true);
2193                },
2194                init: function () {
2195                    if ($scope.GlobalNav.ButtonCTA.EndDate <= new Date())
2196                        return;
2197
2198                    $scope.GlobalNav.ButtonCTA.showBtn();
2199                }
2200            },
2201
2202            checkIfMobilePhone: function () {
2203
2204                var contentHeight = $(window).height();
2205
2206                var contentWidth = $(window).width();
2207
2208
2209                $scope.GlobalNav.IsPortrait = window.innerHeight > window.innerWidth;
2210
2211                if ($scope.GlobalNav.IsPortrait) {
2212
2213                    if (contentWidth < 991 && contentHeight < 1181) {
2214                        $scope.GlobalNav.IsTabletView = true;
2215                    }
2216
2217                    if (contentWidth < 576 && contentHeight < 991) {
2218                        $scope.GlobalNav.IsMobilePhone = true;
2219                    }
2220
2221                }
2222                else {
2223
2224                    if (contentWidth < 991 && contentHeight < 500) {
2225                        $scope.GlobalNav.IsMobilePhone = true;
2226                    }
2227
2228                    if (contentWidth < 1199 && contentHeight < 821) {
2229                        $scope.GlobalNav.IsTabletView = true;
2230                    }
2231
2232                }
2233
2234            },
2235
2236
2237            checkNotifPermission: function () {
2238
2239                try {
2240                    if (!Notification) {
2241                        $scope.GlobalNav.DesktopNotifPermission = "notsupported";
2242                    }
2243                    else if (Notification.permission !== "granted") {
2244
2245                        if (Notification.permission == "denied") {
2246                            $scope.GlobalNav.DesktopNotifPermission = "de
2246nied";
2247                        }
2248                        else {
2249                            $scope.GlobalNav.DesktopNotifPermission = "pending";
2250                        }
2251                    }
2252                    else {
2253                        $scope.GlobalNav.DesktopNotifPermission = "allow";
2254                    }
2255                }
2256                catch (ex) {
2257
2258                }
2259
2260            },
2261
2262            copyToClipboard: function (text, callback) {
2263                ngCopy(text);
2264
2265                if (callback) {
2266                    callback();
2267                }
2268            },
2269
2270
2271            //Use this method if you want to check first if there are current modal opened
2272            //if there are on- going platform tour 
2273            //if LoginPrompt is visible
2274            //before executing the callbackFunction
2275            //This will prevent display of two or more popup modal simultaneously
2276            checkIfThereAreOngoingModalOrPlatformTour: function (callbackFunction) {
2277
2278                //need to consider if paltform tour is already done, prevent display conflict for platform tour and gems onboarding simultaneously
2279                var isPlatformTourDone = true;
2280
2281                $scope.PlatformTourNav.getUserPlatformTour(false, function () {
2282
2283                    if ($scope.PlatformTourNav.UserPlatformTour) {
2284                        if ($scope.UserNav.ActivePage === "HomeSocialFeed") {
2285                            isPlatformTourDone = $scope.PlatformTourNav.UserPlatformTour.IsWebHomeDone;
2286                        }
2287
2288
2289                        if ($scope.UserNav.ActivePage === "ProScreener") {
2290                            isPlatformTourDone = $scope.PlatformTourNav.UserPlatformTour.IsWebProScreenerHomeDone;
2291                        }
2292                    }
2293
2294
2295                    //check if there are current open modal
2296                    var modalCurrentlyOpened = $('.modal.show').length;
2297
2298                    if ($scope.GlobalNav.IsOnboardingActive) {
2299                        modalCurrentlyOpened++;
2300                    }
2301
2302                    if (modalCurrentlyOpened == 0 && isPlatformTourDone && callbackFunction && !$scope.LoginPrompt.ShowPrompt) {
2303                        callbackFunction();
2304                    }
2305                });
2306
2307            },
2308
2309
2310            initGlobalNav: function () {
2311
2312                $scope.GlobalNav.checkIfMobilePhone();
2313
2314                var invHideNav = getParameterByName("invHideNav");
2315
2316                if (invHideNav != "true") {
2317                    invHideNav = LocalStorageCache.InvHideNav.Get();
2318                }
2319
2320                if (invHideNav == "true") {
2321                    $scope.UserNav.IsShowMainNav = false;
2322                    $scope.UserNav.IsShowFooter = false;
2323
2324                    LocalStorageCache.InvHideNav.Set(invHideNav);
2325                }
2326
2327
2328                setTimeout(function () {
2329                    $scope.UserNav.initValue();
2330                    $scope.$digest();
2331                }, 100);
2332
2333
2334                // Load this way to finish loading main components before calling dark mode
2335                angular.element(function () {
2336                    $scope.DarkMode.initDarkMode();
2337                });
2338            }
2339
2340        };
2341
2342
2343        $scope.$on("setGlobalNavIsOnboardingActive", function (e, data) {
2344            $scope.GlobalNav.IsOnboardingActive = data;
2345        });
2346
2347
2348        //VTrade Common function used for vTrade modal on top of specific vTrade userControl
2349        //Prevent issue when nesting a .modal within another fixed element
2350        $scope.GlobalVTrade = {
2351            IsLoading: false,
2352            CompetitionId: -1,
2353            CompetitionPassword: null,
2354            RequestCompePw: null,
2355
2356            setValueAndShowJoinCompeModal: function (item, isJoin) {
2357
2358                $scope.GlobalVTrade.IsLoading = false;
2359                $scope.GlobalVTrade.CompetitionPassword = null;
2360                $scope.GlobalVTrade.CompetitionId = -1;
2361
2362                if (item) {
2363                    $scope.GlobalVTrade.CompetitionPassword = item.Competition.Password;
2364                    $scope.GlobalVTrade.CompetitionId = item.Competition.CompetitionId;
2365                }
2366
2367                $('#JoinVTradeCompetitionModal').modal('show');
2368
2369            },
2370
2371            joinVTradeCompetition: function () {
2372
2373                $scope.GlobalVTrade.IsLoading = true;
2374
2375                var data = {
2376                    Password: $scope.GlobalVTrade.RequestCompePw,
2377                    CompetitionId: $scope.GlobalVTrade.CompetitionId
2378                }
2379
2380                $scope.$broadcast("braodcastJoinVTradeCompetition", data);
2381            }
2382        };
2383
2384        $scope.$on("userNavMasterSiteActiveNav", function (event, activePanel) {
2385            $scope.UserNav.ActivePanel = activePanel;
2386        });
2387
2388
2389        $scope.$on("broadcastPortfolioAccountOverview", function (event, data) {
2390            if (data) {
2391
2392                $scope.UserNav.PortfolioV2.HasPaperGain = data.HasPaperGain;
2393            }
2394        });
2395
2396
2397
2398
2399        $scope.$on("refreshAuthenticatedUserPrimaryWallet", function (event, arg) {
2400
2401            $scope.UserNav.getOwnPrimaryWallet();
2402
2403        });
2404
2405
2406
2407
2408        $scope.$on("refreshAuthenticatedUserAccess", function (event, arg) {
2409
2410            $scope.UserNav.UserAccess.getUserAccess();
2411
2412        });
2413
2414
2415        $scope.$on("refreshAuthenticatedUserProfileLocalSession", function (event, arg) {
2416
2417            $scope.UserNav.getUserSessionProfile();
2418
2419            $scope.UserNav.UserAccess.getUserAccess();
2420
2421            //$scope.UserNav.getOwnPrimaryWallet();
2422
2423            //$scope.UserNav.UserFreeTrial.getIsEligibleForPrimeFreeTrial();
2424
2425            //$scope.UserNav.UserSubscription.getEligibleInternalPromo();
2426
2427            //$scope.UserNav.UserSubscription.getMainSubscriptionAccessTypeTrafficSource();
2428
2429            $scope.UserNav.UserSubscription.getSubscriptionSession();
2430
2431        });
2432
2433
2434        $scope.$on("clearAuthenticatedUserProfileLocalSession", function (event, arg) {
2435
2436            LocalStorageCache.AuthenticatedUserProfile.Remove();
2437
2438        });
2439
2440
2441        $scope.$on("updateFollowingCount", function (event, followingCount) {
2442
2443            if ($scope.UserNav.AuthenticatedUserProfile) {
2444                $scope.UserNav.AuthenticatedUserProfile.SocialProfileInfo.FollowingCount += followingCount;
2445
2446                if ($scope.UserNav.AuthenticatedUserProfile.SocialProfileInfo.FollowingCount < 0) {
2447                    $scope.UserNav.AuthenticatedUserProfile.SocialProfileInfo.FollowingCount = 0;
2448                }
2449            }
2450
2451
2452        });
2453
2454
2455        $('#genericlimiterModal').on('hide.bs.modal', function () {
2456            $rootScope.$broadcast("cancelTrackActionSteps", "Close Limiter Mod
2456al");
2457        });
2458
2459        //Always Last -- INIT method
2460        $scope.GlobalNav.initGlobalNav();
2461
2462
2463
2464    }
2465);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.