angular.module('kalgudiApp').controller('programsController', ['$scope', '$state', '$rootScope', '$filter', '$interval', 'programsFactory','pageServices', 'kalgudiLiterals', '$injector', 'profileServicedata','profileService', function($scope, $state, $rootScope, $filter, $interval, programsFactory, pageServices, kalgudiLiterals, $injector, profileServicedata,profileService) { $scope.programLiterals = kalgudiLiterals; $scope.programstate = ""; /** * Types of digital assistance activity. */ const ACTIVITY_TYPE = { SH : 'SHAREATHOUGHT', QA : 'QA', POST: 'BUSINESS_REQUIREMENT', PROFILE_PIC_UPDATE: 'PROFILE_PIC_UPDATE', REPORT_ACTIVITY: 'REPORT_ACTIVITY', }; $scope.activityType = ACTIVITY_TYPE; $scope.programsList = {}; $scope.programsList.ownedPrograms = []; $scope.programsList.followedPrograms = []; $scope.totalProgramsCount = 0; $scope.adminProgramsCount = 0; $scope.cropNewDetails = false; $scope.messages = {feed:[]}; // List of contributors activities. $scope.contributorAssistance = { activities : [] }; $scope.isMoreFeedExists = true; $scope.isMoreActivitiesExists = true; $scope.searchPlaceholder = "Search programs"; $scope.searchBar = { text : '', hasFocus : false } var firstName = $rootScope.loggedInUserBusinessProfile.firstName; if (firstName.indexOf(' ') != -1) { firstName = firstName.slice(0, firstName.indexOf(' ')); } $scope.relevanceTypes = [ {'id' : 'MY_PROGRAM', 'text' : firstName + $scope.connectsLiterals.searchByKey('MY_PROGRAMS'), 'icon' : 'description'} ] $scope.program = { relevance : $scope.relevanceTypes[0].id } $scope.reloadTheStream = function () { $scope.getAllPrograms(); } $scope.selectedSubscriber = {}; $scope.selectedContributor = {}; $scope.activitiesCount = {}; $scope.isSubscribersPickerActive = false; /* Implementation of loadmore in myprograms list APK **/ $scope.loadMore = { text: $scope.programLiterals.searchByKey('COMMON_LOAD_MORE_LOADING'), limit:20, flag:true } $scope.requestObject = { limit: $scope.loadMore.limit, offset: 0 } $scope.prgListLoadMoreCount = function (result) { if(result.length >= $scope.loadMore.limit){ $scope.loadMore.text = $scope.programLiterals.searchByKey('COMMON_LOAD_MORE_MORE_MSG'); $scope.loadMore.flag = true; }else{ $scope.loadMore.text = $scope.programLiterals.searchByKey('COMMON_LOAD_MORE_NO_MORE_MSG'); $scope.loadMore.flag = false; } } /* End of load more **/ //initalize dynamically inject dependency pagesFactory = detectmob()?$injector.get("pagesFactory"):''; this.$onInit = function () { if(!detectmob()){ $uibModal = $injector.get("$uibModal"); } } $scope.noDataErrorHeading = "No programs yet"; $scope.noDataErrorDesc = "You are not a subscriber\ admin of any programs"; $scope.init = function() { // Get all programs if you do not have it // Get all feed if you dont have it // Get all activities if you dont have it // Set current selected program programsFactory.resetFeed(); $scope.getAllPrograms(); if($scope.selectedProgram) { $rootScope.fromFullviewGroup = { programId : $scope.selectedProgram.entityId }; } // Continously fetch geoLocation every 10 seconds GPS_INTERVAL = $interval(getLatLongValues, 10000); if(!detectmob()) { //fetchFrequentMembersList(); $scope.getSubscribersList(); } } $scope.request = { offset : 0, limit : 10, entityId : detectmob()?$rootScope.programId : $state.params.programId, entityrRelationType : "FOLLOWER" } $scope.subscribersList= []; $scope.getSubscribersList = function() { programsFactory.getSubscribersList($scope.request).then(function(response){ $scope.request.offset = $scope.request.offset + $scope.request.limit; addSubscribersToList(response); },function(error){ // Check for frequent users in the subscribers list // and populate the subscribers list from localStorage var localKey = 'getMemberProfiles?id=' + ($rootScope.programId || $state.params.programId); var frequentList = localStorage[localKey]; // Frequent user exists in localStorage if(frequentList) { frequentList = JSON.parse(frequentList); addSubscribersToList(frequentList); } }); } /** * Adds list of subscribers to the subscribers list * * @subscribers Array of subscribers. */ addSubscribersToList = function(subscribers) { for(var i in subscribers){ $scope.subscribersList.push(subscribers[i]); } /*if($scope.subscribersList.length < $scope.request.offset) $scope.loadMore.text = $scope.contentliterals.searchByKey('COMMON_LOAD_MORE_NO_MORE'); else $scope.loadMore.text = $scope.contentliterals.searchByKey('COMMON_VIEW_MORE');*/ } /** * Clears all intervals, timeouts and performs resource cleanup process. */ $scope.finalize = function() { if(angular.isDefined(GPS_INTERVAL)) { // Clear interval $interval.cancel(GPS_INTERVAL); GPS_INTERVAL = undefined; } } /** * Gets, list of all programs that the current logged in user is a * part. * Calling this make a service call to get list of all programs, * if unable to get response from service fetches list of all programs * from localStorage (if available). */ $scope.getAllPrograms = function() { $rootScope.spinerisActive = true; // clearPrograms(); // Get list of all programs owned by current logged in user programsFactory.getAllPrograms($scope.requestObject,'program').then( function(entities) { if($state.params.programId || $state.params.entityId){ $rootScope.programId = $state.params.programId || $state.params.entityId; } // Successfully fetched all entities // Now filter list of programs in the entities list for(var i in entities) { entities[i].following = true; } //calling loadmore method $scope.prgListLoadMoreCount(entities); filterProgramsList(entities); $rootScope.spinerisActive = false; }, function(error) { // Will take some action later. console.error('[ERROR]' + error); $rootScope.spinerisActive = false; }); }; $rootScope.$on('enableOffline', function (event, flag) { var programId = $rootScope.programId || $state.params.programId || $state.params.entityId; var contributorId = $rootScope.loggedInUserBusinessProfile.profileKey; setSelectedProgram(programId, true); saveFrequentAssistedMember(programId, contributorId); }); saveFrequentAssistedMember = function (programId, contributorId) { programsFactory.getFrequentMembers(programId, contributorId).then( function (response) { var localKey = 'getMemberProfiles?id=' + $rootScope.programId; localStorage[localKey] = JSON.stringify(response); // Get assets of frequent members if(response.length){ saveAssetListForAssistedMember(response); } }, function(error) { addSubscribersToList($scope.getFrequentList()); }); }; saveAssetListForAssistedMember = function(members){ members.forEach(function(member){ profileService.getAsset(member.profileKey, 15, 0).then(function (data) { var localKey = 'getAsset?id=' + member.profileKey; localStorage[localKey] = JSON.stringify(data); }, function (err) { console.log('Error while geting assets'); }); }); }; setSelectedProgram = function(programId, isOfflineAvailable) { /** * Get, program details of current selected program. */ programsFactory.getProgramsDetails(programId, isOfflineAvailable) .then( function (program) { $scope.activitiesCount = program.activitiesCount; $scope.selectedProgram = program.entityDetails; // Set the current program details in rootscope $rootScope.selectedProgram = program.entityDetails; // Set flag whether the current logged in user is admin or not. $scope.isAdminOrContributer($scope.selectedProgram); $rootScope.programId = $scope.selectedProgram.entityId; $rootScope.fromFullviewGroup = {programId : $scope.selectedProgram.entityId}; if($state.params.contributorId) { // This is an activities page hence get contributors activities $scope.selectedContributor = getContributor($state.params.contributorId); // Reset load more flag $scope.isMoreActivitiesExists= true; // Reset previous activities programsFactory.resetActivities(); // Fetch list of activities of current $scope.getContributorActivities(); } // Reset previous feed programsFactory.resetFeed(); // Get program feed $scope.getProgramFeed($scope.selectedProgram.entityId); localStorage['selectedProgram'] = JSON.stringify($scope.selectedProgram); }, function (error) { console.error('[ERROR]' + error); } ); } /** * Clears list of all programs in the programsList array. * Resets all program count stats to 0. */ clearPrograms = function() { // Remove programs list from memory $scope.programsList = ""; $scope.totalProgramsCount = 0; $scope.adminProgramsCount = 0; } /** * Filters list of all programs from the given list of entities * and adds it to programsList variable. */ filterProgramsList = function(entities) { // Clear already existed programs list // $scope.programsList = {}; // $scope.programsList.ownedPrograms = []; // $scope.programsList.followedPrograms = []; $scope.hidePageIds =['O00j48o1PROCRE2017062146196906UNH001','O00j48o1PROCRE2017090534998363UNH001','O00j48o1PROCRE2017090531697993UNH001']; // $scope.adminProgramsCount = 0; // $scope.totalProgramsCount = 0; entities.forEach(function(entity) { // If entity type is program if (entity.entityType === 'PROGRAM') { // Increase total programs count $scope.totalProgramsCount++; var dummyEntity = { entityDetails: entity }; // Increase total admin programs count if current user // is admin of program. if(isAdmin(entity) || isContributor(entity)) { $scope.programsList.ownedPrograms.push(dummyEntity); $scope.adminProgramsCount++; } else { $scope.programsList.followedPrograms.push(dummyEntity); } // Set selected program if not set if($state.params.programId && $state.params.programId === entity.entityId) { setSelectedProgram(entity.entityId); $scope.isAdminOrContributer(entity); } } }); // End of checking all PROGRAM entities //Hiding of kalgudi content,kalgudi opportunities,kalgudi alerts in program tab. $scope.programsList.followedPrograms = _.filter($scope.programsList.followedPrograms, function(o) { return !$scope.hidePageIds.includes(o.entityDetails.entityId); }); } /** * Function to check whether a user admin of a page. * * @programDetails Entity full data. */ isAdmin = function(programDetails) { // For all admins check if current user is admin of the program if(programDetails.lstOfAdmins) { admins = programDetails.lstOfAdmins; for(i = 0; i < admins.length; i++) { // Return true if current user is admin of program if(admins[i].profileKey === $rootScope.loggedInUserBusinessProfile.profileKey) { programDetails.isContributor = false; return true; } } } // Reached bottom means current logged in user is not admin return false; }; /** * Function to check whether a user is contributer of a page. * * @programDetails Entity full data. */ isContributor = function(programDetails) { // For all admins check if current user is admin of the program if(programDetails.lstOfTeamMembers) { contributors = programDetails.lstOfTeamMembers; for(i = 0; i < contributors.length; i++) { // Return true if current user is contributor of program if(contributors[i].userid === $rootScope.loggedInUserBusinessProfile.profileKey) { programDetails.isContributor = true; return true; } } } // Reached bottom means current logged in user is not contributor return false; }; /** * Function to check whether a user is either admin or contributer of a page. * * @programDetails Entity full data. */ $scope.isAdminOrContributer = function(programDetails) { isUserAdminOrContributor = false; $rootScope.isProgramAdmin = isAdmin(programDetails); $rootScope.isProgramContributor= isContributor(programDetails); // Return any of the two values return $rootScope.isProgramAdmin || $rootScope.isContributor; }; /** * Navigates to program home stream. * * @program Object containing program details to open. */ $scope.openProgram = function(program) { $scope.getParentPageDetails (program.entityDetails.entityId); setSelectedProgram(program.entityDetails.entityId); // Navigate to feed state $rootScope.goToState('programs.feed', {programId: program.entityDetails.entityId}); } // To get program's parent details $scope.getParentPageDetails = function (entityId) { pageServices.getFullviewData (entityId).then( function (data) { if (data.entityDetails) { $rootScope.parenetEntitydetailes = data.entityDetails.parentEntityDetails; } }); } /** * Searches for programs. * * @text program search keyword */ $scope.search = function (text) { if(text != "") { $rootScope.spinerisActive = true; $scope.programsList.ownedPrograms = []; $scope.programsList.followedPrograms = []; profileServicedata.pagesSearchResults(text).then( function(result) { if(result && result.length) { $rootScope.spinerisActive = false; filterProgramsList(result); } else { $rootScope.spinerisActive = false; $scope.noDataErrorHeading = $scope.programLiterals.searchByKey('NO_SEARCH_RESULT_TITLE'); $scope.noDataErrorDesc = 'No programs found with the name \'' + text + '\''; } }); } } /** * Sets, selected contributor as current contributor and navigates to * programs.activities statem. * * @contributor Object wrapping contributor details whose activities * is to be fetched. */ $scope.openContributorActivities = function(contributor) { // Change current selected contributor $scope.selectedContributor = contributor; // Reset load more flag $scope.isMoreActivitiesExists= true; // Reset previous activities programsFactory.resetActivities(); // Fetch list of activities of current $scope.getContributorActivities(); // Navigate to activities state. $rootScope.goToState('programs.activities', {'programId': $rootScope.programId, 'contributorId': contributor.userid}); } /** * Gets, object containing contributors details from the list of all contributors. * It matches list of contributors with the given contributor Id and returns a * contributor if his Id is matched with passed contributor Id. * * @contributorId Unique Id of a program contributor. * * @return Object that wraps contributor details if contributor Id is matched * with his Id, otherwise returns undefined. */ getContributor = function(contributorId) { // If there is lstOfTeamMembers field then start index is array length-1 otherwise -1 var i = ($scope.selectedProgram.lstOfTeamMembers) ? ($scope.selectedProgram.lstOfTeamMembers.length - 1) : -1; // For each contributors return current contributor if his // Id matches with given contributor id or not. while(i >= 0) { if($scope.selectedProgram.lstOfTeamMembers[i].userid === contributorId) return $scope.selectedProgram.lstOfTeamMembers[i]; i--; } // If there is lstOfAdmins field then start index is array length-1 otherwise -1 i = ($scope.selectedProgram.lstOfAdmins) ? ($scope.selectedProgram.lstOfAdmins.length - 1) : -1; // No contributors matched check if he is an admin of the page or not while(i >= 0) { if($scope.selectedProgram.lstOfAdmins[i].profileKey === contributorId) return $scope.selectedProgram.lstOfAdmins[i]; i--; } // Reached bottom of function means no contributor found return undefined; } /** * Gets, list of feed items in the programs. * * @programId Unique Id of program. */ $scope.getProgramFeed = function(programId) { $rootScope.spinerisActive = true; programsFactory.getProgramFeed(programId).then( function(feeds) { $rootScope.spinerisActive = false; for (var index = 0; index < feeds.length; index++) { $scope.seperateMultimediaAttachments(feeds[index]); feeds[index].latestActivity = { latestActivity: { type: 'Share a Thought', } } } $scope.messages.feed = feeds; $scope.messages.feed = $filter('orderBy')($scope.messages.feed, 'LUT', true); pageServices.getShareToList().then(function(adminpageslist) { if( $scope.messages.feed.hasOwnProperty('parentEntityid')){ $scope.messages.feed.parenetEntitydetailes=_.find(adminpageslist,function(rw){ return rw.entityId==$scope.messages.feed.parentEntityid}); $rootScope.parenetEntitydetailes = $scope.messages.feed.parenetEntitydetailes; } if($scope.messages.feed.hasOwnProperty("parentEntityDetails")){ $rootScope.parenetEntitydetailes = $scope.programFeed.parentEntityDetails; } }); }, function(error) { $rootScope.spinerisActive = false; } ); } /** * Seperates other media attachments other than image from * list of attachments. This function will rmeove all media * attachments from lstOfAttachments field and put them to a * separate field lstOfMediaAttachments. * * @feed Feed object containing lstOfAttachments. */ $scope.seperateMultimediaAttachments = function (feed) { // Return if there is no attachments if (!feed || !feed.lstOfAttachments || !feed.lstOfAttachments.length) return; var mime = []; // Push all media attachments to separate array. for (var i = 0; i < feed.lstOfAttachments.length; i++) { if (feed.lstOfAttachments[i].msgType != 'IMAGE') { mime.push(feed.lstOfAttachments[i]); } } // Remove all media attachments from lstOfAttachments feed.lstOfAttachments = feed.lstOfAttachments.filter( function (attachment) { return (attachment.msgType === 'IMAGE'); } ); feed.lstOfMediaAttachments = mime; // Raise a flag for audio and doc attachments used by view mime.forEach(function (item) { if (item.msgType === 'DOCUMENT') feed.hasDocumentAttachment = true; if (item.msgType === 'AUDIO') feed.hasAudioAttachment = true; }); } /** * Loads more feed items and pushes to the current program feed. */ $scope.loadMoreFeeds = function() { programsFactory.getProgramFeed($scope.selectedProgram.entityId).then( function(feeds) { if(feeds.length > 0) { // For each loaded feed push to programs feed feeds.forEach(function(feed) { $scope.messages.feed.push(feed); $scope.seperateMultimediaAttachments(feed.data); }); } else { $scope.isMoreFeedExists = false; } }, function(error) { } ); } $scope.showPicker = function(pickerType) { $scope.isSubscribersPickerActive = false; } /** * Gets, list of activities done by a contributor in a program. */ $scope.getContributorActivities = function() { programId = $scope.selectedProgram.entityId; contributorId = $scope.selectedContributor.userid || $scope.selectedContributor.profileKey; programsFactory.getContributorActivities(programId, contributorId).then( function(activities) { // Successfully recieved list of activities // Clear and Populate contributor assistance object $scope.contributorAssistance = {}; $scope.contributorAssistance.activities = []; for(var index in activities.activities){ activities.activities[index].LUT=activities.activities[index].activityTo.notifyTime; } $scope.contributorAssistance = activities; $scope.contributorAssistance.activities = $filter('orderBy')($scope.contributorAssistance.activities, 'LUT', true); if(activities.activities.length == 0) { $scope.isMoreActivitiesExists = false; } }, function(error) { } ); } /** * Loads more contributor activities items and push to the current * contributor activities. */ $scope.loadMoreActivities = function() { var contributorId = $scope.selectedContributor.profileKey || $scope.selectedContributor.userid; programsFactory.getContributorActivities($scope.selectedProgram.entityId, contributorId).then( function(activities) { if(activities.activities.length > 0) { // For each loaded activity push to contributors activities array activities.activities.forEach(function(activity) { activity.LUT=activity.activityTo.notifyTime; $scope.contributorAssistance.activities.push(activity); }); } else { $scope.isMoreActivitiesExists = false; } }, function(error) { } ); } /** * Opens activity fullview. Full view is either share a thought, * QA or post fullview. * * @param {Object} activity Program assistance activity object. */ $scope.openActivityFullview = function(activity) { switch (activity.activityType) { case ACTIVITY_TYPE.SH: $rootScope.goToState('myshareqa.shareAThoughtfullview', {'shareId': activity.activityId}); break; case ACTIVITY_TYPE.QA: $rootScope.goToState('myshareqa.questionfullview', {'questionId': activity.activityId}); break; case ACTIVITY_TYPE.POST: // Not getting masterThreadId and threadId from service to navigate to post fullview break; case ACTIVITY_TYPE.PROFILE_PIC_UPDATE: var userId = activity.activityTo.latestActivity.id; var bizId = activity.activityTo.bizKey; $rootScope.goToState('myconnects.userprofile', {'userId': userId, 'businessId': bizId}); break; case ACTIVITY_TYPE.REPORT_ACTIVITY: $rootScope.goToState('programs.reportActivityFullview', { reportActivityId: activity.reportActivity.activityId }); break; } } /* * FREQUENT ASSISTED MEMBERS LIST FUNCTIONS --------------------------------------------------------------------*/ $scope.frequentMembers = []; /** * Calls, service endpoint to get the list of frequent members. If * service call fails the list of frequent members are loaded from * localStorage if exists. * * On each success service call the method updates the list of frequent * members in localStorage. * * @returns Promise object that made service call. */ fetchFrequentMembersList = function() { // Fetch frequent members from server var programId = detectmob()?$rootScope.programId : $state.params.programId; var contributorId = $rootScope.loggedInUserBusinessProfile.profileKey; programsFactory.getFrequentMembers(programId, contributorId) .then( function(response) { if(response) { $scope.frequentMembers = response; // Update frequent members in localStorage if(detectmob()) setFrequentMembers($scope.frequentMembers); } }, function(error) { // On error try to fetch frequent members from localStorage $scope.frequentMembers = getFrequentMembers() || []; } ); } // fetchFrequentMembersList(); /** * Gets frequent list of subscriber from localStorage. * * @return Returns list of frequent subscribers if exists otherwise * returns undefined. */ getFrequentMembers = function() { var localKey = 'getMemberProfiles?id=' + $rootScope.programId; frequentMembers = localStorage[localKey]; if(frequentMembers) return JSON.parse(frequentMembers); else return undefined; } /** * Sets, frequent list of program members in localStorage. * * @frequentMembers List of frequent members. */ setFrequentMembers = function(frequentMembers) { // Null checks if(!frequentMembers) return; var localKey = 'getMemberProfiles?id=' + ($rootScope.programId || $state.params.programId); return localStorage[localKey] = JSON.stringify(frequentMembers); } /** * Sets, program members as frequently assisted members. This function * calls a service to update the list of frequently assisted members in * a program. * * @members Array of members profile details, who are assisted frequently. */ setAsFrequentMembers = function(members) { $rootScope.spinerisActive = true; // Call service to set members as frequent members. var programId = $rootScope.programId; var contributorId = $rootScope.loggedInUserBusinessProfile.profileKey; // Update the list of frequent members to server. programsFactory.setFrequentMembers(programId, contributorId, members) .then( function(response) { $rootScope.spinerisActive = false; // On success update the frequent members list in localStorage fetchFrequentMembersList(); }, function(error) { $rootScope.spinerisActive = false; // On failure inform user try { window.plugins.toast.show('Unable to add members to frequent list. Please try again later!.', 'long', 'bottom'); } catch(e) { $rootScope.commonTopErrorAlert('Unable to add members to frequent list. Please try again later!'); } } ); } /** * Shows/Hides member picker. */ $scope.toggleMembersPicker = function() { $scope.isSubscribersPickerActive = !$scope.isSubscribersPickerActive; } /** * Subscribe to the event raised by subscriber picker. */ $rootScope.$on('onSubscribersSelectionSubmit', function(event, data) { var selectedMembers = []; // Trim unwanted data and prepare new requestObject for (var i = data.length - 1; i >= 0; i--) { var member = { 'profileKey' : data[i].profileKey, 'firstName' : data[i].firstName, 'profilePicUrl' : data[i].profilePicUrl, 'mobileNo' : data[i].mobileNo, 'address2' : data[i].address2, 'defaultBusinessKey' : data[i].defaultBusinessKey, }; /* * Select only required properties from lstOfUserBusinessDetailsInfo array. * For this we use array reduce function and spread operator. It selects * specific properties inside lstOfUserBusinessDetailsInfo array and reduces * to member payload object. */ member.lstOfUserBusinessDetailsInfo = data[i].lstOfUserBusinessDetailsInfo.reduce( function(prev, curr) { // Specify properties to select from lstOfUserBusinessDetailsInfo field. var selectedDetails = [ { locationTo : curr.locationTo, lstOfProducts : curr.lstOfProducts } ]; // Spread previous array elements with current selected details. // Commenting spread operator since it does not works with grunt. // return [ ...prev, ...selectedDetails ]; return Object.assign([], selectedDetails) }, [] ); // Add member to selected members list selectedMembers.push(member); } // Set list of selected member as frequently assisted members setAsFrequentMembers(selectedMembers); // fetchFrequentMembersList(); }); $rootScope.$on("subscriberDetails", function(event , subscriberDetails){ if(subscriberDetails.mobileNo) subscriberDetails.mobileNumber = parseInt(subscriberDetails.mobileNo.split(subscriberDetails.mobileCode)[1]); $scope.selectedSubscriber = subscriberDetails; $scope.subscribersProducts = subscriberDetails.lstOfUserBusinessDetailsInfo[0].lstOfProducts; $scope.subscribersLocation = subscriberDetails.lstOfUserBusinessDetailsInfo[0].locationTo; getCropDetails(subscriberDetails.profileKey); }); $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){ if(toState.name === 'programs.feed') { programsFactory.resetFeed(); // $scope.getAllPrograms(); // reset selected contributor $scope.selectedContributor = undefined; $scope.isMoreActivitiesExists = true; } if(toState.name === 'programs.assistedmembers') { fetchFrequentMembersList(); } if($state.current.data.screenId == "profileUpdate" && fromState.data.screenId != "locationUpdate" && fromState.data.screenId != "crop-details") { $scope.selectedSubscriber = ""; $scope.isSubscribersPickerActive = true; } if (fromState.data.screenId == "crop-details") { getCropDetails($scope.selectedSubscriber.profileKey); } if(toState.name === 'programs.activities') { if(!$scope.selectedContributor || !$scope.selectedContributor.hasOwnProperty("userid")) { $scope.selectedContributor = $rootScope.loggedInUserBusinessProfile; $scope.selectedContributor.userid = $rootScope.loggedInUserBusinessProfile.profileKey; } // Reset previous activities programsFactory.resetActivities(); // Fetch list of activities of current $scope.getContributorActivities(); } }); // Will set available cropDetails into farmer's profile from localstorage getCropDetails = function(userId) { if (window.localStorage['crop' + userId]) { $scope.subscribersCropList = JSON.parse (window.localStorage['crop' + userId]); } else { $scope.subscribersCropList = []; } } /** * Subscribe an event when programs share is created successfully. */ $rootScope.$on('shareUpdatesInHome', function(event, data) { // Add new share details at top of feeds. // $scope.messages.feed.unshift(data); // Instead of adding the share response object make a fresh service call to get all feeds $scope.getProgramFeed($scope.selectedProgram.entityId); } ); $rootScope.$on('shareUpdatesinactity', function(event, data) { // Add new share details at top of feeds. // $scope.messages.feed.unshift(data); // Instead of adding the share response object make a fresh service call to get all feeds if($scope.selectedContributor && !$scope.selectedContributor.hasOwnProperty("userid")) { $scope.selectedContributor = $rootScope.loggedInUserBusinessProfile; $scope.selectedContributor.userid = $rootScope.loggedInUserBusinessProfile.profileKey; } // Reset previous activities programsFactory.resetActivities(); // Fetch list of activities of current $scope.getContributorActivities(); } ); /** * Subscribe event to clean all resources before destroying the scope. */ $scope.$on('$destroy', $scope.finalize); $scope.openAddNewSubscriber = function () { var modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue+'/shared/programsAddNewSubscriber.html', controller: 'SubscriberProgramsContacts', resolve:{ selectedSubscriber:$scope.selectedSubscriber } }); modalInstance.result.then(function (selectedItem) { }, function () { }); }; $scope.openUpdateSubscriberProfile = function (selectedSubscriber) { $rootScope.$broadcast("subscriberDetails" , selectedSubscriber); $scope.openUpdateSubscriberProfilemodalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue+'mypages/updateProfile/product.html', scope:$scope }); $scope.openUpdateSubscriberProfilemodalInstance.result.then(function (selectedItem) { }, function () { }); }; $scope.openUpdateSubscriberLocation = function (selectedSubscriber) { $rootScope.$broadcast("subscriberDetails" , selectedSubscriber); $scope.modalLocationInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue+'mypages/updateProfile/location.html', scope:$scope }); $scope.modalLocationInstance.result.then(function (selectedItem) { }, function () { }); }; $scope.openProductpicker=function(){ $rootScope.openProduct=true; } $scope.closeProductPicker=function(){ $rootScope.openProduct=false; } $scope.closeSubscriberProductPicker=function(){ $scope.openUpdateSubscriberProfilemodalInstance.close(); } $scope.closeLocationPicker= function () { $scope.modalLocationInstance.close(); }; $scope.viewAllFrequestMembers = function (data,type) { $scope.modalInstanceFrequestMembers = $uibModal.open({ templateUrl: 'webapp/themes/html/mypages/viewall/programFrequentMembers.html', scope:$scope, size: 'md', resolve: { } }); $scope.modalInstanceFrequestMembers.result.then(function (selectedItem) { }, function () { }); }; $scope.closeFrequestMembers= function () { $scope.modalInstanceFrequestMembers.close(); }; $scope.openUpdateCompany = function (selectedSubscriber) { $rootScope.$broadcast("subscriberDetails" , selectedSubscriber); // Storing details for editing default company / organization for employee types $rootScope.selectedEmployee = {}; if(selectedSubscriber.lstOfUserBusinessDetailsInfo[0].businessTypeId == 'BT000017'){ $rootScope.selectedEmployee.profileKey = selectedSubscriber.profileKey; $rootScope.selectedEmployee.companyDetails = selectedSubscriber.lstOfUserBusinessDetailsInfo[0].businessTypeName; $rootScope.selectedEmployee.businessTypeId = selectedSubscriber.lstOfUserBusinessDetailsInfo[0].businessTypeId; $rootScope.selectedEmployee.digitalAssitanceFlag = true; } $scope.modalInstanceCompany = $uibModal.open({ templateUrl: 'webapp/themes/html/mypages/updateProfile/editCompany.html', scope:$scope, size: 'md', resolve: { } }); }; $scope.closeUpdateCompany = function () { $scope.modalInstanceCompany.close(); }; $scope.openUpdateSubscriberCrop = function (selectedSubscriber) { $rootScope.$broadcast("subscriberDetails" , selectedSubscriber); $scope.programstate='crop'; $scope.modalInstanceCropDetails = $uibModal.open({ templateUrl: 'webapp/themes/html/mypages/updateProfile/cropDetails.html', scope:$scope, size: 'md', resolve: { } }); $scope.modalInstanceCropDetails.result.then(function (selectedItem) { }, function () { $scope.programstate=""; }); }; $scope.closeUpdateCropDetails= function () { $scope.modalInstanceCropDetails.close(); }; $scope.toggleCropdetails=function(){ $scope.cropNewDetails=!$scope.cropNewDetails; } // for switching between about and activity tabs $scope.tabs = ['About', 'Activities']; $scope.selectedTab = $scope.tabs[1]; $scope.tabs = ['About', 'Activities']; $scope.selectedTab = $scope.tabs[1]; //Surveys tab $scope.getTemplates=function(){ localKey = 'myEntities?profileKey=' + $rootScope.loggedInUserBusinessProfile.profileKey; entities = localStorage[localKey]; if(entities!=undefined){ entities =JSON.parse(entities) for(i=0;i