angular.module('kalgudiApp.surveys').controller('surveyInboxController', ['$scope', '$state', '$rootScope', 'kalgudiLiterals', '$injector', '$filter', 'surveyServices', 'pageServices', 'programsFactory', 'surveyOfflineService', function($scope, $state, $rootScope, kalgudiLiterals, $injector, $filter, surveyServices, pageServices, programsFactory, surveyOfflineService) { /** Chekcing the user's device */ if(!IS_MOBILE_DEVICE) { // $scope.isMobileApp = false; $uibModal = $injector.get('$uibModal'); } else { // $scope.isMobileApp = true; $ionicModal = $injector.get("$ionicModal"); /** * Modal for filter surveys */ $scope.modal = $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue+'surveys/survey-filter-modal.html', { scope: $scope, animation: 'slide-in-up', }).then(function(modal) { $scope.modal = modal; }); /** * Modal for Surveys offline functionality */ $scope.daModal = $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue + 'surveys/assist-member-modal.html', { scope: $scope, animation: 'slide-in-up', }).then(function (modal) { $scope.daModal = modal; }); } /** Checking the device End */ $scope.tabs = ["Fill","Manage"]; $scope.selectedTab = "Fill"; $scope.surveysList = new Array(); $scope.mySurveys = new Array(); $scope.stats = null; $scope.statsFlag = false; $scope.surveyIndex = 0; $scope.isServey = true; $scope.offset = 0; $rootScope.isSurveyAvailable = false; $scope.settingLiterals = kalgudiLiterals; $scope.init = function() { try { $scope.isSurveyUnderProgram = typeof $state.params.programId !== 'undefined' || typeof $state.params.entityId !== 'undefined'; $scope.selectTab('Manage'); $scope.fetchSurveyList("Fill"); /*surveyServices.isSurveyAvailable($rootScope.loggedInUserBusinessProfile.profileKey).then(function(res){ if(res.code==201){ res.data = JSON.parse(res.data); // if(res.data.membersCount==0){ // $rootScope.isSurveyAvailable = true; // } }*/ /*});*/ $rootScope.isSurveyAvailable = ($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessTypeId == 'BT000010'); } catch (e) { console.log('Unable to initialize survey inbox properly.'); } } $scope.fetchSurveyList = function (tab) { $scope.selectedTab = tab; // Do nothing for program surveys if ($scope.isSurveyUnderProgram) { return; } if($scope.selectedTab == 'Fill' && $scope.surveysList.length == 0) { $rootScope.spinerisActive = true; surveyServices.surveyList($rootScope.loggedInUserBusinessProfile.profileKey, "member", $scope.offset).then( function(response) { if(response.code == 200) { try { $scope.surveysList = JSON.parse(response.data); $scope.surveysList.sort(function(a, b){ if (a.createdTS > b.createdTS) return -1; else return 1; }); } catch (e) { $scope.surveysList = response.data; } } $rootScope.spinerisActive = false; }, function (err) { $rootScope.spinerisActive = false; } ); } } $rootScope.$on('switchToMySurvey', function(event, value) { $scope.selectTab('Manage'); }); $scope.selectTab = function (tab){ $scope.selectedTab = tab; // Do nothing for program surveys if ($scope.isSurveyUnderProgram) { return; } if($scope.selectedTab == "Manage" || $scope.mySurveys.length == 0) { $rootScope.spinerisActive = true; surveyServices.surveyList($rootScope.loggedInUserBusinessProfile.profileKey, "admin", $scope.offset).then( function(response){ if(response.code==200) { try { $scope.mySurveys = JSON.parse(response.data); $scope.mySurveys.sort(function (a, b) { if (a.createdTS > b.createdTS) return -1; else return 1; }); } catch (e) { $scope.mySurveys = response.data; } } $rootScope.spinerisActive = false; }, function (err) { $rootScope.spinerisActive = false; } ); } } $scope.openAdminView=function(id){ $state.go("surveys.adminFullview",{'id':id}); } /** * Navigate to survey response submission fullview * @param {any} surveyId Survey id */ $scope.openSurveyFullView = function (surveyId) { $rootScope.goToState('surveys.response', {surveyId: surveyId, profileId: $rootScope.loggedInUserBusinessProfile.profileKey}); } $scope.assistMembers = function (surveyId) { // $rootScope.goToState('surveys.response.assist', {surveyId: surveyId, isAssisted: 'assist'}); $rootScope.goToState('surveys.offlinesurvey', { id: surveyId}); } $scope.openChatView = function() { } $scope.showStats=function(flag,surveyId,index){ $scope.statsFlag=flag; $scope.surveyIndex=index; if(flag==true){ surveyServices.getStats(surveyId).then(function(response){ $scope.stats=JSON.parse(response.data); }) } } $scope.openSurveysFullview = function(survey){ if($scope.selectedTab=="Manage" || (survey.entityId && $scope.isLoggedInUserAdminOfSurvey(survey))){ $scope.openAdminView(survey.id); } else if($scope.selectedTab=="Fill" && !$scope.isSurveyUnderProgram) { $scope.openSurveyFullView(survey.id); } else{ console.log("Do nothing"); } } /** * Checks, if current logged in user is admin of the given survey or not. * * @param {any} survey Survey object * @returns `true` if logged in user is admin otherwise `false`. */ $scope.isLoggedInUserAdminOfSurvey = function (survey) { // Null checks if (typeof survey !== 'object' || typeof survey.admins !== 'object' || !Array.isArray(survey.admins)) { return false; } for (var i = 0; i < survey.admins.length; i++) { var admin = survey.admins[i]; if (admin.id === $rootScope.loggedInUserBusinessProfile.profileKey) { return true; } } // Current user is not admin return false; } /*----------------------------------------Filters Start-----------------------------------------------------------------*/ //Filters Section $scope.filters = {}; $scope.openModal = function() { $scope.isQuestionEmtpy = false; $scope.modal.show(); }; $scope.closeModal = function() { $scope.filters.products=[]; $scope.filters.location=[]; $scope.filters.businessType=[]; $scope.filters.programs=[]; for(var i in $rootScope.selectedProductList){ $scope.filters.products.push($rootScope.selectedProductList[i].id); } for(var i in $rootScope.selectedLocationList){ $scope.filters.location.push($rootScope.selectedLocationList[i].id);; } for(var i in $rootScope.selectedBusinessList){ $scope.filters.businessType.push($rootScope.selectedBusinessList[i].id); } for(var i in $rootScope.selectedProgramList){ $scope.filters.programs.push($rootScope.selectedProgramList[i].id); } $scope.modal.hide(); }; //Cleanup the modal when we're done with it! if(IS_MOBILE_DEVICE) { $scope.$on('$destroy', function() { $scope.modal.remove(); }); // Execute action on hide modal $scope.$on('modal.hidden', function() { // Execute action }); // Execute action on remove modal $scope.$on('modal.removed', function() { // Execute action }); } /*Members Section*/ $rootScope.selectedBusinessList = []; $rootScope.selectedLocationList = []; $rootScope.selectedProductList = []; $rootScope.selectedProgramList = []; $scope.selectProductList = []; $scope.selectBusinessList = []; $scope.selectProgramList = []; $scope.selectLocationList = []; $scope.selectCountryList = []; $scope.selectStateList = []; $scope.selectDistrictsList = []; $scope.entitesList = []; $scope.orgId = ''; // pageServices.getRangeToFilterSubscribers($state.params.where).then(function(response){ // $scope.rangeData = JSON.parse(response.data); // console.log($scope.rangeData) // }); $scope.getFilters = function () { $rootScope.spinerisActive = true; surveyServices.getFilters($rootScope.loggedInUserBusinessProfile.defaultEntityDetails.entityId).then( function(res) { if (res.code == 200) { res.data = JSON.parse(res.data); $scope.orgId = res.data.organisationId; prepareFilters(res.data); // Assign service data to local fields // $scope.selectProductList = res.data.products; // $scope.selectProgramList = res.data.programs; // $scope.selectBusinessList = res.data.businessTypes; // $scope.selectLocationList = { // districts: res.data.districts, // locations: res.data.locations, // countries: res.data.countries, // statesOrRegions: res.data.statesOrRegions, // }; } $rootScope.spinerisActive = false; }, function(err) { $rootScope.spinerisActive = false; console.log(err); } ); }; function prepareFilters(data) { for (i in data.products) { if (data.products[i]) { $scope.selectProductList.push({ id: i, name: data.products[i], isSelected: false, }); } } for (i in data.programs) { if (data.programs[i]) { $scope.selectProgramList.push({ id: i, name: data.programs[i], isSelected: false, }); } } for (i in data.businessTypes) { if (data.businessTypes[i]) { $scope.selectBusinessList.push({ id: i, name: data.businessTypes[i], isSelected: false, }); } } for (i in data.locations) { if (data.locations[i]) { $scope.selectLocationList.push({ id: i, name: data.locations[i], isSelected: false, }); } }; $scope.selectProductList.sort(function(a, b) { return (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : -1}); $scope.selectProductList.sort(function(a, b) { return (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : -1}); $scope.selectBusinessList.sort(function(a, b) { return (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : -1}); $scope.selectLocationList.sort(function(a, b) { return (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : -1}); // $scope.selectLocationList = { // districts: res.data.districts, // locations: res.data.locations, // countries: res.data.countries, // statesOrRegions: res.data.statesOrRegions, // }; } // Get list of all programs owned by current logged in user /*programsFactory.getAllPrograms().then( function(entities) { $scope.entitesList = 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; } //filterProgramsList(entities); $rootScope.spinerisActive = false; }, function(error) { // Will take some action later. console.error('[ERROR]' + error); $rootScope.spinerisActive = false; } );*/ $scope.first_tab = true; $scope.tabs_click = function(tab){ if(tab === 'first_tab'){ $scope.first_tab = true; $scope.second_tab = false; $rootScope.rangeData = {}; }else{ $scope.first_tab = false; $scope.second_tab = true; $rootScope.selectedLocationList = []; $rootScope.rangeData = []; } } $scope.pickertype=''; $scope.addToList = function(selectedItem, index, pickertype) { pickertype = $scope.pickertype; console.log(pickertype) if(pickertype == "product"){ var isAlreadyAdded = -1; for( var businessId in $rootScope.selectedProductList){ if($rootScope.selectedProductList[businessId].id == selectedItem.id){ isAlreadyAdded = businessId ; break; } } if(isAlreadyAdded > -1){ $rootScope.selectedProductList.splice(isAlreadyAdded,1); $scope.selectProductList[index].isSelected = false; } else{ $rootScope.selectedProductList.push(selectedItem); $scope.selectProductList[index].isSelected = true; } console.log($rootScope.selectedProductList) } else if (pickertype == "business") { var isAlreadyAdded = -1; for( var businessId in $rootScope.selectedBusinessList){ if($rootScope.selectedBusinessList[businessId].id == selectedItem.id){ isAlreadyAdded = businessId ; break; } } if(isAlreadyAdded > -1){ $rootScope.selectedBusinessList.splice(isAlreadyAdded,1); $scope.selectBusinessList[index].isSelected = false; } else{ $rootScope.selectedBusinessList.push(selectedItem); $scope.selectBusinessList[index].isSelected = true; } console.log($rootScope.selectedBusinessList) } else if (pickertype == "location") { var isAlreadyAdded = -1; for( var businessId in $rootScope.selectedLocationList){ if($rootScope.selectedLocationList[businessId].id == selectedItem.id){ isAlreadyAdded = businessId ; break; } } if(isAlreadyAdded > -1){ $rootScope.selectedLocationList.splice(isAlreadyAdded,1); $scope.selectLocationList[index].isSelected = false; } else{ $rootScope.selectedLocationList.push(selectedItem); $scope.selectLocationList[index].isSelected = true; } // console.log($rootScope.selectedLocationList) } else if (pickertype == "programs") { var isAlreadyAdded = -1; for( var businessId in $rootScope.selectedProgramList){ if($rootScope.selectedProgramList[businessId].id == selectedItem.id){ isAlreadyAdded = businessId ; break; } } if(isAlreadyAdded > -1){ $rootScope.selectedProgramList.splice(isAlreadyAdded,1); $scope.selectProgramList[index].isSelected = false; } else{ $rootScope.selectedProgramList.push(selectedItem); $scope.selectProgramList[index].isSelected = true; } console.log($rootScope.selectedProgramList) } } $scope.selectedFilter = function (type) { $scope.pickertype = type; if (type == "product") { $scope.isLocationRange = true; $scope.isLocationTab = false; $scope.headerTitle = 'Products'; // if ($scope.selectProductList.length == 0) { // for (var i in $scope.rangeData.products) { // $scope.selectProductList.push( { "id" : i, "name" : $scope.rangeData.products[i], "isSelected" : false }); // } // } } else if (type == "business") { $scope.isLocationRange = true; $scope.isLocationTab = false; $scope.headerTitle = 'Business'; // console.log($scope.rangeData.businessTypes); // if ($scope.selectBusinessList.length == 0) { // for (var i in $scope.rangeData.businessTypes) { // $scope.selectBusinessList.push( { "id" : i, "name" : $scope.rangeData.businessTypes[i], "isSelected" : false }); // } // } } else if (type == "location") { $scope.isLocationRange = true; $scope.isLocationTab = false; $scope.tabs.first = true; $scope.headerTitle = 'Location'; /* $scope.rangeData = $scope.items;*/ // var tempList = []; // for(var country in $scope.rangeData.countries){ // tempList.push({"name":$scope.rangeData.countries[country],"id":country, "isSelected":false}); // } // tempList=$filter('orderBy')(tempList, 'name',false); // $scope.rangeData.countries = tempList; // pageServices.getLocationLists($state.params.where).then( function(locations) { // if (locations.code == "200") { // var tempObj = JSON.parse(locations.data); // for (var obj in tempObj) { // var locationObject = { // "name" : tempObj[obj], // "id" : obj, // "isSelected" : false // } // $scope.selectLocationList.push(locationObject); // } // } else if (locations.code == "500") { // console.log("error: ", locations); // } // }); console.log($scope.selectLocationList) } else if (type == "programs") { $scope.isLocationRange = true; $scope.isLocationTab = false; $scope.headerTitle = 'Programs'; console.log($scope.entitesList) if($scope.selectProgramList.length == 0){ for (var i in $scope.entitesList){ $scope.selectProgramList.push({"id":i, "name":$scope.entitesList[i].entityName,"isSelected":false}); } } console.log($scope.selectProgramList) } console.log(type) $scope.isQuestionForm = false; $scope.openModal(); } $scope.filterResult = function(filter){ $scope.searchResults = []; for(var i in $scope.completeList){ if($scope.completeList[i].name.toLowerCase().indexOf(filter.toLowerCase()) > -1){ $scope.searchResults.push($scope.completeList[i]); } } } $scope.filterbusinessSearch =function(filter){ $scope.searchFilter=filter; $scope.createTmpProfileType($scope.completeList); } $scope.locationTabs = { first : true, second : false } $scope.changeTab = function (tab) { switch (tab) { case 'FIRST': $scope.locationTabs.first = true; $scope.locationTabs.second = false; $scope.isLocationTab = false; $scope.isLocationRange = true; break; case 'SECOND' : $scope.locationTabs.second = true; $scope.locationTabs.first = false; $scope.isLocationTab = true; $scope.isLocationRange = false; break; } } $scope.Flag={}; $scope.resetLocationtsbs=function(){ $scope.Flag.country=false; $scope.Flag.state=false; $scope.Flag.district=false; } $rootScope.selectedLocationList = []; $scope.selectLocationFromRange = function (){ var stateIds = []; var regionIds = []; for(i in $scope.selectedStateList){ if($scope.selectedStateList[i].id.length == 5){ regionIds.push($scope.selectedStateList[i].id); }else { stateIds.push($scope.selectedStateList[i].id); } } var districtIds = []; for(i in $scope.selectedDistrictList){ districtIds.push($scope.selectedDistrictList[i].id); } var selectedData = { countries : $scope.selectedCountry, states: stateIds, districts :districtIds }; if(selectedData.districts.length){ for(i in selectedData.districts){ var placeName = "" ; if($scope.selectedDistrictList[i].name != "Not Applicable"){ placeName = placeName + $scope.selectedDistrictList[i].name + ', ' ; } if($scope.selectedStateList[0].name != "Not Applicable"){ placeName = placeName + $scope.selectedStateList[0].name + ', '; } placeName = placeName + selectedData.countries.name; $rootScope.selectedLocationList.push({"name": placeName,"id": $scope.selectedDistrictList[i].id}); } } else if(selectedData.states.length){ for(i in selectedData.states){ var placeName = "" ; if($scope.selectedStateList[i].name != "Not Applicable"){ placeName = placeName + $scope.selectedStateList[i].name + ', '; } placeName = placeName + selectedData.countries.name; $rootScope.selectedLocationList.push({"name": placeName,"id":$scope.selectedStateList[i].id}); } } else { $rootScope.selectedLocationList.push({"name": $scope.selectedCountry.name,"id":$scope.selectedCountry.id}); } $rootScope.rangeData.push(selectedData); $scope.selectedCountry = ""; $scope.selectedDistrictList = undefined; $scope.stateList = undefined; $scope.districtList = undefined; var countryList = $scope.rangeData.countries; $scope.rangeData.countries= undefined; $timeout(function () { $scope.rangeData.countries = countryList; },300); } $scope.getSubList = function(selectedItem, index, mainList){ console.log(selectedItem) if(mainList == 'country'){ tempList = []; $scope.selectedCountry = selectedItem; $scope.selectedStateList = [] ; for(var i in $scope.rangeData.countries){ if($scope.rangeData.countries[i].id == selectedItem.id){ $scope.rangeData.countries[i].isSelected = true; for(var state in $scope.rangeData.statesOrRegions[selectedItem.id]){ tempList.push({"name":$scope.rangeData.statesOrRegions[selectedItem.id][state],"id":state}); } if(tempList.length){ $scope.stateList = tempList ; } } else { $scope.rangeData.countries[i].isSelected = false; } } } else if(mainList == 'state'){ if(!$scope.districtList){ tempList = []; for(var districts in $scope.rangeData.districts[selectedItem.id]){ tempList.push({"name":$scope.rangeData.districts[selectedItem.id][districts],"id":districts}); } $scope.districtList = tempList ; $scope.selectedStateList.push(selectedItem); $scope.stateList.splice(index,1); $scope.selectedDistrictList = []; } else { $scope.selectedStateList.push(selectedItem); $scope.stateList.splice(index,1); $scope.selectedDistrictList = undefined; $scope.districtList = undefined; } } else if(mainList == 'district'){ $scope.districtList.splice(index,1); $scope.selectedDistrictList.push(selectedItem); } $scope.resetLocationtsbs(); } $scope.selectAll = function() { switch($scope.pickertype) { case 'product': for(i in $scope.selectProductList) { $scope.addToList($scope.selectProductList[i], i, 'product'); } break; case 'business': for(i in $scope.selectBusinessList) { $scope.addToList($scope.selectBusinessList[i], i, 'business'); } break; case 'programs': for(i in $scope.selectProgramList) { $scope.addToList($scope.selectProgramList[i], i, 'programs'); } break; case 'location': for(i in $scope.selectLocationList) { $scope.addToList($scope.selectLocationList[i], i, 'location'); } break; } } // $scope.getFilters(); /* ------------- TARGETTED AUDIENCE ----------------- */ $scope.audienceCount; $scope.targettedAudienceRequest = {} $scope.getTargettedAudienceCount = function() { var requestPayload = { organisationId: $scope.orgId, valid: true, businessTypes: [], locations: [], products: [], programs: [], }; requestPayload.businessTypes = $scope.selectedBusinessList.map(function(t) { return t.id; }); requestPayload.locations = $scope.selectedLocationList.map(function(t) { return t.id; }); requestPayload.products = $scope.selectedProductList.map( function(t) { return t.id; }); requestPayload.programs = $scope.selectedProgramList.map( function(t) { return t.id; }); $scope.targettedAudienceRequest = requestPayload; surveyServices.getTargettedAudienceCount(requestPayload).then( function (res) { $scope.audienceCount = 0; try { $scope.audienceCount = res.data; } catch (e) { } }, function (err) { console.log('Unable to get targetted audience.', err); } ); }; $scope.openMemberSelection = function() { $rootScope.spinerisActive = true; surveyId = $state.params.id; surveyServices.getTargettedAudience($scope.targettedAudienceRequest).then( function (res) { console.log(res); $rootScope.spinerisActive = false; $rootScope.goToState('surveys.response.assist', {surveyId: surveyId, isAssisted: 'assist'}); }, function (err) { console.log(err); $rootScope.spinerisActive = false; } ); } /*--------------------------------------------------------Filters End-------------------------------------------*/ /* ---------------------- SURVEY OFFLINE FUNCTIONALITIES ----------------------- */ $scope.assistMemberModal = { title: 'Cache members offline', }; $scope.searchAssistedMember = ''; $scope.assistantDetails = {}; $scope.surveyMembers = []; $scope.filterSurveyMembers = $scope.surveyMembers; $scope.selectedSurveyId = ''; $scope.openMembersDialog = function () { $scope.daModal.show(); }; $scope.closeAssistedMemberModal = function () { $scope.daModal.hide(); $scope.cacheMembers(); } $scope.selectMember = function (user) { if (user.isSelected) { user.isSelected = false; } else { user.isSelected = true; } } $scope.filterUsers = function (filter) { try { filter = filter.toLowerCase(); } catch (e) { } $scope.filterSurveyMembers = $scope.surveyMembers.filter(function (member) { if ((member.firstName && member.firstName.toLowerCase().includes(filter)) || (member.location && member.location.toLowerCase().includes(filter))) return member; }); }; $scope.getSurveyMembers = function (surveyId) { $rootScope.spinerisActive = true; surveyServices.getMembers(surveyId, 0).then( function (res) { if (res.code == 200) { res.data = JSON.parse(res.data); $scope.surveyMembers = res.data; $scope.filterSurveyMembers = $scope.surveyMembers; // $scope.filterSurveyMembers.push(JSON.parse(JSON.stringify($scope.surveyMembers[0]))); // $scope.filterSurveyMembers.push(JSON.parse(JSON.stringify($scope.surveyMembers[0]))); // $scope.filterSurveyMembers.push(JSON.parse(JSON.stringify($scope.surveyMembers[0]))); $scope.selectedSurveyId = surveyId; $scope.openMembersDialog(); } $rootScope.spinerisActive = false; }, function (err) { console.log('Unable to get member details to assist.'); $rootScope.spinerisActive = false; } ); }; $scope.cacheMembers = function() { // Filter list of all selected users const members = $scope.surveyMembers.filter(function (member) { if (member.isSelected) { delete member.isSelected; return member; } }); try { surveyOfflineService.setMembersList($scope.selectedSurveyId, members); $rootScope.showAlertBox('Offline mode enabled successfully.', 'Offline enabled', 'done'); } catch (e) { console.log(e); $rootScope.showAlertBox('Unable to cache survey locally, please try again later.', 'Cannot cache survey', 'error'); } } $scope.onEnableOfflineSurvey = function (survey) { $rootScope.spinerisActive = true; // Get survey details and cache it locally. surveyServices.getSurveyDetails(survey.id, $rootScope.loggedInUserBusinessProfile.profileKey).then( function (res) { if (res.code == 200) { const toCache = { code: res.code, info: res.info, data: res.data }; // Cache survey offline try { if ($scope.selectedTab == 'Manage') { surveyOfflineService.setAdminSurveyList(survey); // Survey of whom you are admin can only be digitally assisted to others // Hence cache all members. $scope.getSurveyMembers(survey.id); } else { surveyOfflineService.setSurveyList(survey); $rootScope.spinerisActive = false; $rootScope.showAlertBox('Survey is available for offline.', 'Offline enabled', 'done'); } surveyOfflineService.setSurveyDetails(res, JSON.parse(res.data).id); } catch (e) { $rootScope.spinerisActive = false; console.log('Unable to cache survey locally.', e); $rootScope.showAlertBox('Unable to cache survey locally, please try again later.', 'Cannot cache survey', 'error'); } } }, function (err) { $rootScope.spinerisActive = false; $rootScope.showAlertBox('Unable to cache survey locally, please try again later.', 'Cannot cache survey', 'error'); } ); } $scope.onAssistMemberClicked = function (surveyId) { $rootScope.goToState('surveys.response.assist', {surveyId: surveyId, isAssisted: 'assist'}); } $scope.onRejectClicked = function (survey) { $rootScope.spinerisActive = true; surveyServices.rejectSurvey(survey.id, $rootScope.loggedInUserBusinessProfile.profileKey).then( function (res) { $rootScope.spinerisActive = false; if (res.code == 200) { // Remove surveys from stream try { $scope.surveysList.splice($scope.surveysList.indexOf(survey), 1); } catch (e) { console.log('Unable to remove from survey inbox list', e); } } }, function (err) { console.log('Unable to reject survey', err); $rootScope.showAlertBox('Unable to reject survey, please try again later.', 'Unsuccessful', 'error'); $rootScope.spinerisActive = false; } ) } /**---------------------------- Surveys for WebApp --------------------- */ /*method to highlight tabs with border*/ $scope.selectedActivityTab = 0; $scope.surveyActivityTabs = { FILL : 0, MANAGE : 1, } $scope.toggleTabs = function (selectedTab) { $scope.selectedActivityTab = selectedTab; } /* * Extends Survey - Create a new survey from existing one */ $scope.onExtendSurvey = function (survey) { survey.isExtend = true; $state.go("surveys.createsurvey",{'oldSurvey':survey}); } /* * Survey Attendance Form */ $scope.openSurveyAttendanceFrom = function (survey) { //CHECK ALREADY THERE OR NOT surveyServices.getAttendanceForm(survey.id).then( function (response) { $rootScope.spinerisActive = false; var fetchedFormData = {}; if (response.code == 200) { fetchedFormData = JSON.parse(response.data); $scope.openAttendanceModal(survey, fetchedFormData); } else { $scope.openAttendanceModal(survey); } }, function (err) { $rootScope.spinerisActive = false; }); } $scope.openAttendanceModal = function(survey,fetchedFormData){ var mainObj={ survey:survey, fetchedFormData : fetchedFormData } $uibModal.open({ templateUrl: $rootScope.themebasepathvalue + 'surveys/attendanceForm.html', controller: 'surveyAttendanceFormController', resolve: { mainObj: function () { return mainObj; } } }); } $scope.init(); }]);