var groupCompanyApp = angular.module('groupCompanyApp', ["commonsApp"]); groupCompanyApp.directive('groupCompany',['Constants','commonsAppServices','mySharedService', function( Constants,commonsAppServices,sharedService) { return { restrict: "E", templateUrl: Constants.cdnFullPath + 'scripts/angular/commons/modules/groupcompany/groupCompany.html', replace: true, scope: { control : '=', groupData : '@', companyId : '@', followedCompany : '@', offsetLeft : '=', offsetTop : '=', arrowPosition : '=', dontShowChecked : '@' }, link: function (scope, element, attrs) { scope.modifiedData = []; scope.ui = {'mode' : 'view'}; scope.groupCompany = {}; scope.dontShowPopup = "false"; scope.groupCompany.mixpanelTracking = true; scope.groupCompany.duplicateName = false; if(scope.dontShowPopup = "false") { commonsAppServices.getIsFollowAndAssign().then(function(result) { scope.dontShowPopup = result.data; }); } scope.control.getGroup = function(event,followedCompany, companyId) { scope.groupCompany.onSaving = false; scope.showGroupPopup = false; scope.modifiedData = []; scope.group = null; scope.arrowPosition = ""; event.target.disabled = true; scope.followedCompany = followedCompany; scope.groupCompany.companyId = companyId; scope.ui = {'mode' : 'assign'}; if(companyId != "") { if(scope.dontShowPopup == "true") { sharedService.followSuggestion(scope.followedCompany); } else { commonsAppServices.getGroupData(companyId).then(function(result) { scope.groupData = result.data; var rawDom = event.target; var _x = 0; var _y = 0; var body = document.documentElement || document.body; var scrollX = window.pageXOffset || body.scrollLeft; var scrollY = window.pageYOffset || body.scrollTop; _x = rawDom.getBoundingClientRect().left + scrollX - 215; _y = rawDom.getBoundingClientRect().top + scrollY - 103; scope.offsetLeft = _x + "px"; scope.offsetTop = _y + "px"; scope.arrowPosition = "arrow_right"; scope.showGroupPopup = true; if(scope.groupCompany.mixpanelTracking) { mixpanel.people.set("Number of Groups", scope.groupData.length); scope.groupCompany.mixpanelTracking = false; } }); } }; }; scope.control.getData = function(event, companyId) { scope.groupCompany.onSaving = false; sharedService.showLoading(); scope.groupCompany.companyId = companyId; scope.showGroupPopup = false; scope.followedCompany = null; scope.arrowPosition = ""; scope.modifiedData = []; scope.group = null; scope.ui = {'mode' : 'view'}; if(companyId != "") { commonsAppServices.getGroupData(companyId).then(function(result) { scope.groupData = result.data; var rawDom = event.target; var _x = 0; var _y = 0; var body = document.documentElement || document.body; var scrollX = window.pageXOffset || body.scrollLeft; var scrollY = window.pageYOffset || body.scrollTop; _x = rawDom.getBoundingClientRect().left + scrollX + 100; _y = rawDom.getBoundingClientRect().top + scrollY - 110; scope.offsetLeft = _x + "px"; scope.offsetTop = _y + "px"; scope.arrowPosition = "arrow_left"; scope.showGroupPopup = true; sharedService.hideLoading(); if(scope.groupCompany.mixpanelTracking) { mixpanel.people.set("Number of Groups", scope.groupData.length); scope.groupCompany.mixpanelTracking = false; } }); }; }; var newGroupCount= 0; scope.addNewGroup = function(group) { if(group != null) { if(group.name != null && scope.groupData.length < 10) { var newGroup = new Object(); newGroup.id = getRandomGroupId(100, 200)+""; newGroup.name = group.name; newGroup.selected = true; newGroup.status = "ADDED"; newGroupCount++; var addToArray=true; for(var i=0;i