manageCompaniesApp.controller("manageCompaniesController", [ '$scope', 'manageCompaniesService', 'mySharedService', 'Constants', 'cache', function($scope, manageCompaniesService, sharedService, Constants, cache) { $scope.companyId = ""; $scope.suggestion = {}; $scope.data = {}; $scope.data.dataLoading = false; $scope.showTips = false; $scope.myCompaniesList = {}; $scope.followedCompaniesList = []; var limitStep = 10; $scope.suggestion.start = 0; $scope.suggestion.end = 10; $scope.loaderShow = true; $scope.suggestedCompaniesLoader = true; $scope.incrementLimit = function() { $scope.suggestion.start += limitStep; $scope.suggestion.end += limitStep; }; // If the user is an identified user , show verify email pop up var isUserFullyAuthenticated = false; $scope.init = function(isFullyAuthenticated){ try{ if(isFullyAuthenticated != undefined){ var isUserFullyAuthenticated = isFullyAuthenticated; if(!isUserFullyAuthenticated){ $scope.$root.$broadcast("mandateAuthentication", { page: "portfolio page", isMandate:true }); } } }catch(e){ } } window.addEventListener("load",function initDefault() { var myCompaniesList = manageCompaniesService.getMyCompanies(); myCompaniesList.then(function(result) { $scope.loaderShow = false; $scope.myCompaniesList = result.data; $scope.updateFollowedCompaniesList(); mixpanel.people.set("Followed Companies Count", $scope.myCompaniesList.length); }); }); $scope.updateFollowedCompaniesList = function(){ $scope.followedCompaniesList = []; angular.forEach($scope.myCompaniesList, function(company){ $scope.followedCompaniesList.push(company.companyInfo); }); }; $scope.updateList = function(company) { var index = $scope.myCompaniesList.indexOf(company); $scope.myCompaniesList.splice(index, 1); $scope.updateFollowedCompaniesList(); }; $scope.getFollowedCompany = function() { return $scope.followedCompaniesList; }; $scope.$on('showLoading', function() { $scope.data.dataLoading = true; }); $scope.$on('hideLoading', function() { $scope.data.dataLoading = false; }); $scope.$on('companyAdded', function() { $scope.addedCompany = {}; var addedCompId = sharedService.addedCompany.idAsLong; var followedCompRes = manageCompaniesService.getFollowedCompanyInfo(addedCompId); followedCompRes.then(function(result) { $scope.data.dataLoading = false; $scope.addedCompany = result.data; $scope.myCompaniesList.unshift($scope.addedCompany); $scope.updateFollowedCompaniesList(); var index = -1; var count = -1; $scope.addedCompany = null; }); }); $scope.$on('companyRemoved', function() { $scope.removedCompany = sharedService.removedCompany; var index = -1; var count = -1; angular.forEach($scope.myCompaniesList, function(company) { count++; if (company.companyInfo.id === $scope.removedCompany.id) { index = count; return false; } }); if(index > -1){ $scope.myCompaniesList.splice(index, 1); $scope.updateFollowedCompaniesList(); } $scope.removedCompany = null; }); $scope.companyInfo = {}; //initDefault(); } ]);