angular.module('kalgudiApp').controller('queShareGroupSearchController', ['$scope','$rootScope','$state','helpandlegalservice','$http','$filter','profileServicedata','kalgudiLiterals','groupsFactory', function($scope,$rootScope,$state,helpandlegalservice,$http,$filter,profileServicedata,kalgudiLiterals,groupsFactory){ //Auto complete $scope.searchTypeAutoComplete = ""; $scope.hideInternalTemplate = false; $scope.showAutocomplete = false; $scope.autocompletesSearchProp = { minChar : 2, maxAutoCompletes : 5, keyPressDelay : 500, showTemplate : false, outerTemplateCss: 'z-index: 4;' }; //autocomplete end $rootScope.searchResultFlag = true; $scope.loadMore = { text:"Loading ...", limit:20, flag:true } $scope.requestObject = { "keyword" : $state.params.keyword, "limit" : $scope.loadMore.limit, "offset" : 0 } $scope.fromDatePlaceholder = 'From'; $scope.toDatePlaceholder = 'To'; $scope.fromdatepickerObject = { todayLabel : 'Today', closeLabel : 'Close', inputDate : '', step : "1", format : "12", callback : function (val) { setFromDatePicker(val); } } $scope.todatepickerObject = { todayLabel : 'Today', closeLabel : 'Close', inputDate : '', step : "1", format : "12", callback : function (val) { setToDatePicker(val); } } $scope.advanceSearchData = { text : '', product : '', publishedBy : '', type : '', group : '', sortBy : '', popularity : '', formaDate : '', toDate : '', }; $scope.advanceQandAData = { questionText : '', answerText : '', questionState : '', askedBy : '', questionLocality: '', sortBy : '', fromDate : '', toDate : '', }; $scope.init = function() { if(groupsFactory.advancedUpdatesSearchObj) $scope.advanceSearchData = groupsFactory.advancedUpdatesSearchObj; if(groupsFactory.advancedQnASearchObj) $scope.advancedQnASearchObj = groupsFactory.advancedQnASearchObj; }; var setFromDatePicker = function(val){ if (typeof(val) !== 'undefined') { $scope.fromdatepickerObject.inputDate = val; var day = val.getDate(); var month = val.getMonth() +1; var year = val.getFullYear(); if(month < 9 ){ month = '0'+month; } if(day < 9 ){ day = '0'+day; } var fullFromDate = year+'-'+month+'-'+day; // console.log(fullFromDate); $scope.advanceSearchData.fromDate = fullFromDate; $scope.advanceQandAData.fromDate = fullFromDate; $scope.fromDatePlaceholder = ''; }; } var setToDatePicker = function(val){ if (typeof(val) !== 'undefined') { $scope.todatepickerObject.inputDate = val; var day = val.getDate(); var month = val.getMonth() +1; var year = val.getFullYear(); if(month < 9 ){ month = '0'+month; } if(day < 9 ){ day = '0'+day; } var fullToDate = year+'-'+month+'-'+day; // console.log(fullToDate); $scope.advanceSearchData.toDate = fullToDate; $scope.advanceQandAData.toDate = fullToDate; $scope.toDatePlaceholder = ''; }; } $scope.searchThreadsList = { data : [] }; $scope.searchLiterals= kalgudiLiterals; $scope.loadmoreCount = function (result) { if (result.length < $scope.loadMore.limit) { $scope.loadMore.text = $scope.searchLiterals.searchByKey('COMMON_NO_MORE_RESULTS'); $scope.loadMore.flag = false; } else { $scope.loadMore.text = $scope.searchLiterals.searchByKey('COMMON_VIEW_MORE'); $scope.loadMore.flag = true; } } $scope.search = function() { switch ($state.current.name) { case "groups.search" : if (!$state.params.keyword) { return false; } $rootScope.spinerisActive = true; profileServicedata.getGroupsSearchResults($scope.requestObject).then(function(result) { $rootScope.spinerisActive = false; $scope.searchThreadsList.data=$scope.searchThreadsList.data.concat(result); $scope.loadmoreCount(result); }); break; case "myshareqa.search" : if (!$state.params.keyword) { return false; } $rootScope.spinerisActive = true; profileServicedata.qaSearchResults($state.params.keyword).then(function(result){ $rootScope.spinerisActive = false; $scope.searchThreadsList=result; }); break; case "myshareqa.updateSearch" : if (!$state.params.keyword) { return false; } $rootScope.spinerisActive = true; var request = { keyword: $state.params.keyword, offset : 0, limit : 20 } helpandlegalservice.searchForUpdates(request).then(function(result) { $rootScope.spinerisActive = false; $scope.searchThreadsList = result; }); break; case "pages.search" : if($state.params.keyword != "") { $rootScope.spinerisActive = true; profileServicedata.pagesSearchResults($state.params.keyword).then(function(result) { $rootScope.spinerisActive = false; $scope.searchThreadsList=result; }); } break; } } $scope.search(); $scope.joinGroup=function(groupId) { groupsFactory.joinInGroup(groupId).then(function(result){ if(result.code == 201){ $scope.search(); } }); } $scope.joinRequest=function(groupId, type){ groupsFactory.joinRequest(groupId, type).then(function(result){ if(result.code == 201){ $scope.search(); } }); } $scope.followPage=function(entityId){ $scope.request = { "profileKey":$rootScope.loggedInUserBusinessProfile.profileKey, "businessKey":$rootScope.loggedInUserCurrentBussinessInfo.businessKey, "businessName":$rootScope.loggedInUserCurrentBussinessInfo.businessName, "businessTypeId":$rootScope.loggedInUserCurrentBussinessInfo.businessTypeId, "mobileNo":$rootScope.loggedInUserBusinessProfile.mobileNo, "emailId":$rootScope.loggedInUserBusinessProfile.emailId, "businessTypeName":$rootScope.loggedInUserCurrentBussinessInfo.businessTypeName }; profileServicedata.joinInFollow($scope.request, entityId).then(function(result){ if(result.code == 201){ $scope.search(); } }); } $scope.sortChange = function(sort){ if(sort == 'popularity'){ $scope.dateFlag = false; }else if(sort == 'date'){ $scope.dateFlag = true; } else if(sort == 'recent'){ $scope.dateFlag = false; } else { $scope.dateFlag = false; } } $scope.searchBarUrl; /*===Method for Advance Search Share an Update====*/ $scope.advanceSearch = function (searchFlag, searchUrlOne) { groupsFactory.advancedUpdatesSearchObj = $scope.advanceSearchData; $scope.strURL = 'text=' + $scope.advanceSearchData.text + '&product=' + $scope.advanceSearchData.product + '&publishedBy=' + $scope.advanceSearchData.publishedBy + '&type=' + $scope.advanceSearchData.type + '&group=' + $scope.advanceSearchData.group + '&sortBy=' + $scope.advanceSearchData.sortBy + '&fromDate=' + $scope.advanceSearchData.fromDate + '&toDate=' + $scope.advanceSearchData.toDate; $rootScope.goToState('myconnects.advanceSearchResults',{query : $scope.strURL, sort: ''}); }; /*---Method for Advance Search Q and A---*/ $scope.advanceSearchQnA = function (searchFlag, searchUrlOne) { groupsFactory.advancedQnASearchObj = $scope.advanceQandAData; $scope.strURL = 'questionText=' + $scope.advanceQandAData.questionText + '&answerText=' + $scope.advanceQandAData.answerText + '&questionState=' + $scope.advanceQandAData.questionState + '&askedBy=' + $scope.advanceQandAData.askedBy + '&questionLocality=' + $scope.advanceQandAData.questionLocality + '&sortBy=' + $scope.advanceQandAData.sortBy + '&fromDate=' + $scope.advanceQandAData.fromDate + '&toDate=' + $scope.advanceQandAData.toDate; $rootScope.goToState('myconnects.advanceSearchResults',{query : $scope.strURL, sort: ''}); }; $scope.editSearch = function () { $scope.searchThreadsList.data = []; $scope.searchResultFlag = true; } $scope.changeIcon = function (flag) { if (flag == 'change') { $scope.requestObject.offset = 0; $scope.searchThreadsList.data = []; $scope.icon = false; }else{ $scope.icon = true; } } //autocomplete service which gets called inside the autocomplete directive $scope.callTheService = function () { var obj = {"type":$scope.searchTypeAutoComplete, "offset":0, "limit": $scope.autocompletesSearchProp.maxAutoCompletes }; switch($state.current.url){ case "/advanceShareAnUpdateSearch" :{ obj.keyword = $scope.advanceSearchData.product; break;//advanceShareAnUpdateSearch }; case "/advancedQuestionAnswerSearch" :{ obj.keyword = $scope.advanceQandAData.questionLocality; break;//advancedQuestionAnswerSearch }; }; return profileServicedata.autocompleteSearch(obj).then(function(result){ return result.data; }); }; /*clicking on the field will enable autocomplete template*/ $scope.activeAutocomplete = function (autocompletetype) { $scope.searchTypeAutoComplete = autocompletetype; $scope.showAutocomplete = true; }; /*clicking anywhere on the screen will disappear the autocomplate*/ angular.element(document).on("click", function(e) { $scope.$apply(function() { $scope.hideInternalTemplate = !$scope.hideInternalTemplate; }); }); $scope.init(); } ]);