angular.module('kalgudiApp.surveys').controller('createSurveysController', ['$scope', '$rootScope', '$injector', 'S3UploadService', 'kalgudiLiterals', 'surveyServices', '$state', function ($scope, $rootScope, $injector, S3UploadService, kalgudiLiterals, surveyServices, $state) { var title = "Create Survey"; $rootScope.$broadcast("changeHeaderTitle", title); /*Extendng Survey data from the old survey*/ if($state.params.oldSurvey) { $scope.extendSurvey = $state.params.oldSurvey; } /** Chekcing the user's device */ if(!IS_MOBILE_DEVICE) { $uibModal = $injector.get('$uibModal'); } else { $ionicModal = $injector.get("$ionicModal"); $scope.modal = $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue +'surveys/question-modal.html', { scope : $scope, animation : 'slide-in-up', }).then( function (modal) { $scope.modal = modal; }); } if(IS_MOBILE_DEVICE){ $(document).ready(function(){ setTimeout( function() { $('.tabs').tabs(); }, 100); }); var id = document.getElementsByClassName("stepper-circle active"); var step = id[0].innerHTML; } /** Checking the device End */ $scope.settingLiterals = kalgudiLiterals; $scope.attachmentObject = { "msgType" : "", "name" : "", "size" : "", "url" : "", "context" : "", "localFile" : "" } //survey request Object $scope.surveyObject = { id : '', title :'', surveyPicURL : '', description : '', location : '', expiryDate : null, isResubmittable : true, questions : [], admins : [], members : [], // filters : {} } $scope.question = { id : '', questionType : '', questionText : '', options : [] } $scope.selectedType = function (selectedValue) { if ($scope.question.questionType != null) { if ($scope.hideFlag > 0) { counter = 0; } $scope.answers_menu = true; $scope.questionLabelFlag = true; $scope.question.options=[]; $scope.typeList.push(selectedValue.name); $scope.question_label = 'Enter the question'; if($scope.question.questionType.val>3){ for (var i = 0; i < selectedValue.val; i++) { counter++; $scope.question.options.push(""); } $scope.hideFlag++; } } } /** * Reset survey creation form */ $scope.reset = function () { $scope.surveyObject.id = ''; $scope.surveyObject.title = ''; $scope.surveyObject.surveyPicURL = ''; $scope.surveyObject.description = ''; $scope.surveyObject.location = ''; $scope.surveyObject.expiryDate = null; $scope.surveyObject.isResubmittable = true; $scope.surveyObject.questions = []; $scope.surveyObject.admins = []; $scope.surveyObject.members = []; }; $scope.next = function (surveyObject) { //validations if($("#surveyTitle").val() == '') { $("#surveyTitle").addClass("invalid"); $("#surveyTitle").prop("aria-invalid", "true"); return true; } if($("#surveyDesc").val()=='') { $("#surveyDesc").addClass("invalid"); $("#surveyDesc").prop("aria-invalid", "true"); return true; } if($scope.isSubmit == true) { /* Assign Old Survey Questions to new survey */ $scope.surveyObject.questions = ($scope.extendSurvey) ? $scope.extendSurvey.questions : []; surveyObject.createdBy = { name : $rootScope.loggedInUserBusinessProfile.firstName, id : $rootScope.loggedInUserBusinessProfile.profileKey, bizId : $rootScope.loggedInUserCurrentBussinessInfo.businessKey, location : $rootScope.loggedInUserCurrentBussinessInfo.locationTo.locationLong, bizTypeName : $rootScope.loggedInUserCurrentBussinessInfo.businessTypeName }; // Add program details if survey created under program if ($scope.isSurveyCreatedUnderProgram) { try { // Get selected program details from localStorage const selectedProgram = JSON.parse(localStorage['selectedProgram']); surveyObject.entityId = selectedProgram.entityId; surveyObject.entityName = selectedProgram.entityName; } catch (e) { console.log('Selected program details not found'); } // Add list of all admins and contributors of current selected program var programDetails = localStorage['selectedProgram']; if (programDetails) { programDetails = JSON.parse(programDetails); // Add all admins if (programDetails.lstOfAdmins) { programDetails.lstOfAdmins.forEach(function (admin) { surveyObject.admins.push({ name : admin.firstName, id : admin.profileKey, bizId : admin.businessKey, location : admin.locationLong || '', bizTypeName : admin.businessTypeName }); }); } // Add all contributors if (programDetails.lstOfTeamMembers) { programDetails.lstOfTeamMembers.forEach(function (contributor) { surveyObject.admins.push({ name : contributor.userfname, id : contributor.userid, bizId : contributor.userbizid, location : contributor.locationLong || '', bizTypeName : contributor.userbusinesstypename }); }); } } } else { surveyObject.admins.push(surveyObject.createdBy); } surveyObject.isDisabled=false; delete surveyObject.filters; surveyObject.members = []; // Add members details to survey $scope.selectedAudience.forEach( function (user) { const userToAdd = { name: user.firstName, id: user.profileKey, bizId: user.defaultBusinessKey, location: '', bizTypeName: '', }; try { if (user.lstOfUserBusinessDetailsInfo && user.lstOfUserBusinessDetailsInfo.length > 0) { userToAdd.bizTypeName = user.lstOfUserBusinessDetailsInfo[0].businessTypeName; if (user.lstOfUserBusinessDetailsInfo.locationTo) { userToAdd.location = user.lstOfUserBusinessDetailsInfo.locationTo.locationLong; } } } catch (e) {} surveyObject.members.push(userToAdd); }); // surveyObject.members = $scope.selectedAudienceProfileKey; /* Assign Old Survey Members to new survey*/ $scope.surveyObject.members = ($scope.extendSurveyMembers.isExtended) ? $scope.extendSurvey.members : []; surveyObject.expiryDate = surveyObject.expiryDate || new Date(); $rootScope.spinerisActive = true; surveyServices.createSurvey(surveyObject).then( function(response){ $rootScope.spinerisActive = false; if(response.code==201){ var title = "Success"; var icon = "done"; var expires = "3000"; var message= "Survey Created"; $rootScope.showAlertBox (message, title, icon, expires); /*$state.go("surveys.home");*/ history.back(); setTimeout(function() { $rootScope.$broadcast('switchToMySurvey', true); }, 300); } }, function(err) { $rootScope.spinerisActive = false; }); } else { step++; switch(step){ case 1: { $scope.currentStep = 'about'; $('#about .stepper-circle').addClass('active'); break; } /*case 2: { $scope.currentStep = 'questions'; $('#about_survey').hide(); $('#about .stepper-circle').removeClass('active'); $('#questions .stepper-circle').addClass('active'); $('#questions_survey').show(); $('#prv_btn').show(); break; } case 3: { $scope.currentStep = 'members'; $('#questions_survey').hide(); $('#questions .stepper-circle').removeClass('active'); $('#members .stepper-circle').addClass('active'); $('#members_survey').show(); break; }*/ case 2: { $scope.currentStep = 'settings'; $('#about_survey').hide(); $('#members .stepper-circle').removeClass('active'); $('#settings .stepper-circle').addClass('active'); $('#settings_survey').show(); $('#prv_btn').show(); $('#nxt_btn').html('Submit'); $scope.isSubmit = true; break; } }//switch } } $scope.currentStep = 'about'; $scope.previous = function(){ console.log("previous", step) step--; switch(step){ case 1: { $scope.currentStep = 'about'; $('#about_survey').show(); $('#questions .stepper-circle').removeClass('active'); $('#about .stepper-circle').addClass('active'); $('#settings_survey').hide(); $('#prv_btn').hide(); $('#nxt_btn').html('Next'); $scope.isSubmit = false; break; } /*case 2: { $scope.currentStep = 'questions'; $('#questions_survey').show(); $('#members .stepper-circle').removeClass('active'); $('#questions .stepper-circle').addClass('active'); $('#members_survey').hide(); $('#nxt_btn').html('Next'); $scope.isSubmit = false; break; } case 3: { $scope.currentStep = 'members'; $('#members_survey').show(); $('#settings .stepper-circle').removeClass('active'); $('#members .stepper-circle').addClass('active'); $('#settings_survey').hide(); $('#nxt_btn').html('Next'); $scope.isSubmit = false; break; }*/ }//switch } /* $scope.questions = { questionType:'', questionName:'', answers:[] } */ $scope.answers_template = []; $scope.hideFlag=0; $scope.typeList = []; $scope.question_count = 0; $scope.selectedValue = ''; $scope.typeOptions = [ {"name":"Yes/No", "val":"1", "type": "YES_NO"}, {"name":"Text", "val":"2", "type": "TEXT"}, {"name":"Rating", "val":"3", "type": "RATING"}, {"name":"Multiple Choice with 4","val":"4", "type": "MULTIPLE_CHOICE_QUESTION"}, {"name":"Multiple Choice with 5", "val":"5", "type": "MULTIPLE_CHOICE_QUESTION"}, {"name":"Multiple Choice with 6", "val":"6", "type": "MULTIPLE_CHOICE_QUESTION"}, // {"name":"Multiple Selection with 4", "val":"4", "type": "MULTIPLE_CHOICE_SELECTION"}, // {"name":"Multiple Selection with 5", "val":"5", "type": "MULTIPLE_CHOICE_SELECTION"}, // {"name":"Multiple Selection with 6", "val":"6", "type": "MULTIPLE_CHOICE_SELECTION"} ]; $scope.headerTitle = 'Add Question'; $scope.isQuestionForm = true; var counter = 0; //select dropdown choice // true if survey is created under program else false $scope.isSurveyCreatedUnderProgram = false; $scope.init = function () { try { $scope.isSurveyCreatedUnderProgram = (typeof $state.params.programId === 'string' && $state.params.programId.trim().length > 0) || (typeof $state.params.entityId === 'string' && $state.params.entityId.trim().length > 0); } catch (e) { } } $scope.saveQuestion = function (question) { if(!$scope.isQuestionValid(question)) { return; } question.questionType=question.questionType.type; $scope.question_count++; $scope.questionLabelFlag = false; $scope.isQuestion_Template = false; $scope.answers_menu = false; $scope.surveyObject.questions.push(question); $scope.question_form = false; $scope.question = {}; $scope.closeModal(); $scope.selectedValue = 0; } $scope.isQuestionValid = function (question) { switch(+$scope.question.questionType.val){ case 1: case 2: case 3: if(!question.questionText){ $scope.isQuestionEmtpy = true; return false; } break; case 4: case 5: case 6: if(!question.questionText){ $scope.isQuestionEmtpy = true; return false; } if (question.options) { for (var i = 0; i < question.options.length; i++) { if(!question.options[i]){ return false; } } } break; } return true; } $scope.removeQuestion = function (questionToRemove, index) { $scope.surveyObject.questions.splice(index, 1); } // will be called on image file selection for attachment $scope.uploadImage = function(files, file, newFile, duplicateFiles, invalidFiles, event) { if( invalidFiles && invalidFiles.length) { $scope.errorImageFlag = true; $scope.errorFileFlag = false; } else { $scope.errorImageFlag = false; } if(file) { S3UploadService.compressImage(file).then( function (compressedImage) { $scope.attachmentObject.name = compressedImage.name; $scope.attachmentObject.size = compressedImage.size; $scope.currentImageBase64 = S3UploadService.base64Image.target.result; delete S3UploadService.base64Image; $scope.getUploadPolicy(file, compressedImage); }); /*$scope.compressImage(file, 720, 720);*/ } } // will call a service to get policy for uploading object to S3 $scope.getUploadPolicy=function(file, compressesFile) { // if final compressed file size is less than 2 MB if(compressesFile.size < 2097152) { var fileType = file.type; $scope.uploadFileToS3(compressesFile, fileType); } else { console.log("file size is more than 2 MB"); } } // will upload the given file to S3 $scope.uploadFileToS3 = function (fileToUpload, fileType) { // To show spinner and hide submit button while uploading the file $scope.enableOk = false; // checking for file size, should be less than 5 MB if(fileToUpload.size > 5000000) { $rootScope.commonTopErrorAlert("Files with more than 5MB size, can not be attached"); $scope.modal.hide(); return false; } S3UploadService.uploadToS3(fileToUpload, fileType) .then( function (res) { $scope.enableOk = true; $scope.surveyObject.surveyPicURL = res; }, function (err) { $scope.enableOk = true; $scope.attachmentObject.fileType = fileType; $scope.attachmentObject.fileName = fileToUpload.name; console.error (err); } ); } $scope.openModal = function() { $scope.isQuestionEmtpy = false; $scope.modal.show(); }; $scope.closeModal = function() { $scope.surveyObject.filters.products=[]; $scope.surveyObject.filters.location=[]; $scope.surveyObject.filters.businessType=[]; $scope.surveyObject.filters.programs=[]; for(var i in $rootScope.selectedProductList){ $scope.surveyObject.filters.products.push($rootScope.selectedProductList[i].id); } for(var i in $rootScope.selectedLocationList){ $scope.surveyObject.filters.location.push($rootScope.selectedLocationList[i].id);; } for(var i in $rootScope.selectedBusinessList){ $scope.surveyObject.filters.businessType.push($rootScope.selectedBusinessList[i].id); } for(var i in $rootScope.selectedProgramList){ $scope.surveyObject.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(); }); } /* ------------------------ TARGET AUDIENCE ----------------------- */ $scope.audienceCount = 0; $scope.selectedAudience = []; $scope.selectedAudienceProfileKey = []; $scope.isUserPickerShown = false; $scope.onAudienceSelect = function (users) { // Push all selected elements to selected audience for (i in users) { $scope.selectedAudience.push(users[i]); } // Filter our profile keys of selected users. $scope.selectedAudienceProfileKey = $scope.selectedAudience.map(function (e) { return e.profileKey; }); $scope.isUserPickerShown = false; // Update audience count $scope.audienceCount = $scope.selectedAudience.length; } $scope.showUserPicker = function() { title = "Select Target Members"; $rootScope.$broadcast("changeHeaderTitle", title); $scope.isUserPickerShown = true; } $scope.userPickerClosed = function() { title = "Create Survey"; $rootScope.$broadcast("changeHeaderTitle", title); $scope.isUserPickerShown = false; } $scope.expiryDateFlag=false; $scope.datepickerObject = { todayLabel: 'Today', closeLabel: 'Close', inputDate: new Date(), step: "1", format: "12", callback: function (val) { datePickerCallback(val); } } var datePickerCallback = function (val) { if (typeof(val) === 'undefined') { } else { $scope.surveyObject.expiryDate = val; $scope.datepickerObject.inputDate=val; }; } $scope.isResubmittable = function (surveyObject) { $scope.surveyObject.isResubmittable = $scope.surveyObject.isResubmittable; /* var title = "Success"; var icon = "done"; var expires = "3000"; var message= "Changes Saved" $rootScope.showAlertBox (message, title, icon, expires);*/ } $scope.Flag={}; $scope.resetLocationtsbs=function(){ $scope.Flag.country=false; $scope.Flag.state=false; $scope.Flag.district=false; } /*----------------- To use date picker while creating a survey -----------------*/ var today = new Date(); $scope.datevar = { fromDate :new Date(), toDate : new Date() } $scope.AvailableDate = ''; $scope.ExpireDate = new Date(); $scope.dateFormat = 'dd-MMM-yy'; $scope.availableDateOptions = { formatYear: 'yy', startingDay: 1, minDate: new Date(), maxDate: new Date(2030, 5, 22) }; $scope.expireDateOptions = { formatYear: 'yy', startingDay: 1, minDate: today, maxDate: new Date(2030, 5, 22) }; $scope.availableDatePopup = { opened: false, fromOpened: false, toOpened: false }; $scope.expireDatePopup = { opened: false }; $scope.extendSurveyMembers = { isExtended : false } $scope.ChangeExpiryMinDate = function(availableDate) { if (availableDate != null) { var expiryMinDate = new Date(availableDate); $scope.expireDateOptions.minDate = expiryMinDate; $scope.ExpireDate = expiryMinDate; } }; $scope.ChangeExpiryMinDate(); $scope.OpenAvailableDate = function() { $scope.availableDatePopup.opened = !$scope.availableDatePopup.opened; $scope.postMessageFormData = $scope.AvailableDate; $scope.datepickerObject.inputDate = $scope.postMessageFormData.AvailableDate; }; $scope.ChangeDate = function(indexChangeDate) { $scope.postMessageFormData.date = indexChangeDate; }; $scope.OpenExpireDate = function() { $scope.expireDatePopup.opened = !$scope.expireDatePopup.opened; }; /* ------------------------- end of date picker ---------------------*/ /*---------------------------calling create survey service ---------------------*/ $scope.create = function (surveyObject) { console.log('survey-object: ',surveyObject); /* Assign Old Survey Questions to new survey */ $scope.surveyObject.questions = ($scope.extendSurvey) ? $scope.extendSurvey.questions : []; /* Assign Old Survey Members to new survey*/ $scope.surveyObject.members = ($scope.extendSurveyMembers.isExtended) ? $scope.extendSurvey.members : []; $rootScope.spinerisActive = true; surveyObject.createdBy = { name : $rootScope.loggedInUserBusinessProfile.firstName, id : $rootScope.loggedInUserBusinessProfile.profileKey, bizId : $rootScope.loggedInUserCurrentBussinessInfo.businessKey, location : $rootScope.loggedInUserCurrentBussinessInfo.locationTo.locationLong, bizTypeName : $rootScope.loggedInUserCurrentBussinessInfo.businessTypeName }; // Add program details if survey created under program if ($scope.isSurveyCreatedUnderProgram) { try { // Get selected program details from localStorage const selectedProgram = JSON.parse(localStorage['selectedProgram']); surveyObject.entityId = selectedProgram.entityId; surveyObject.entityName = selectedProgram.entityName; } catch (e) { console.log('Selected program details not found'); } // Add list of all admins and contributors of current selected program var programDetails = localStorage['selectedProgram']; if (programDetails) { programDetails = JSON.parse(programDetails); // Add all admins if (programDetails.lstOfAdmins) { programDetails.lstOfAdmins.forEach(function (admin) { surveyObject.admins.push({ name : admin.firstName, id : admin.profileKey, bizId : admin.businessKey, location : admin.locationLong || '', bizTypeName : admin.businessTypeName }); }); } // Add all contributors if (programDetails.lstOfTeamMembers) { programDetails.lstOfTeamMembers.forEach(function (contributor) { surveyObject.admins.push({ name : contributor.userfname, id : contributor.userid, bizId : contributor.userbizid, location : contributor.locationLong || '', bizTypeName : contributor.userbusinesstypename }); }); } } } else { surveyObject.admins.push(surveyObject.createdBy); } surveyObject.isDisabled = false; surveyServices.createSurvey(surveyObject).then( function(response){ $rootScope.spinerisActive = false; if(response.code==201) { $rootScope.showSuccessMessage('Survey Created Successfully', '', 2500); if (!$scope.isSurveyCreatedUnderProgram) { history.back(); setTimeout(function() { $rootScope.$broadcast('switchToMySurvey', true); }, 300); } else { // If survey created under program // Reset survey creation form $scope.reset(); // Fire event to reload program survey stream $rootScope.$broadcast('newSurveyStreamObject', JSON.parse(response.data)); } } else { $rootScope.showErrorMessage('Something went wrong', 'Please try again after some time', 2500); } }, function(err) { $rootScope.spinerisActive = false; }); } /*---------------------- end of calling create survey servey for webApp -------------------*/ /*---------------------- If Entered Details of the survey is cleared ----------------------*/ // $scope.reset = function() { // $scope.surveyObject.title = ''; // $scope.surveyObject.description = ''; // $scope.surveyObject.location = ''; // $scope.surveyObject.expiryDate = ''; // $scope.surveyObject.surveyPicURL = ''; // } /*--------------------- end of clearing the details of the survey from UI -----------------*/ /*---------------------Extend Survey (Edit or Delete Questions) ------------------------ */ $scope.isEditQuestions = false; $scope.editSurveyQuestions = function () { $scope.isEditQuestions = !$scope.isEditQuestions; } $scope.removeOldQuestion = function (questionToRemove, index) { $scope.extendSurvey.questions.splice(index, 1); } /*---------------------End Extend Survey (Edit or Delete Questions) ------------------------ */ $scope.init(); }]); // 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.selectLocationList = []; // $scope.selectProgramList = []; // $scope.entitesList = []; // pageServices.getRangeToFilterSubscribers($state.params.where).then(function(response){ // $scope.rangeData = JSON.parse(response.data); // console.log($scope.rangeData) // }); // 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": $scope.entitesList[i].programId, "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.tabs = { // first : false, // second : false // } // $scope.changeTab = function (tab) { // switch (tab) { // case 'FIRST': // $scope.tabs.first = true; // $scope.tabs.second = false; // $scope.isLocationTab = false; // $scope.isLocationRange = true; // break; // case 'SECOND' : // $scope.tabs.second = true; // $scope.tabs.first = false; // $scope.isLocationTab = true; // $scope.isLocationRange = false; // break; // } // } // $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(); // }