angular.module('kalgudiApp').controller('productPickerController',['$scope','$rootScope','kalgudiLiterals','$state','profileService','$timeout' ,'$injector','profileServicedata', function ($scope,$rootScope,kalgudiLiterals,$state,profileService,$timeout,$injector,profileServicedata) { if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $uibModal = $injector.get("$uibModal"); } else{ $ionicModal=$injector.get("$ionicModal"); $ionicSlideBoxDelegate=$injector.get("$ionicSlideBoxDelegate"); }; var similarAka =[]; var dissimilarAka = []; $scope.first_tab = true; $scope.modalProductCategory = false; $scope.modalProductCategorytype=""; $scope.thread_index=0; var pickersTime=1500; $scope.buttonFlag= { productVariety : false }; $scope.filterShow=true; $scope.queryValidationFlag ={ queryFlag :false }; $scope.filter = { filterByLocation : "", filterByBusinessType : "", }; $scope.typeList = ["My country","Connected countries","World wide"] $rootScope.smallHeaderDisplay=false; $scope.filterpicker = false; $scope.listofproduct = []; $scope.transactionLiterals = kalgudiLiterals; $scope.ionic_limit={ "limit":10}; $scope.noresultFlag=false; $scope.productSearchQuery = ""; $scope.query={}; $scope.searchBar = { text : '', hasFocus : false } // Hiding deals with while adding products on profile if($state.current.name != "profile.viewProductshome.viewProducts") { $scope.showDealswith = true; } if($state.current.data.module != "myprofile") { $scope.relevanceTypes = [ {'id' : 'MY', 'text': 'Products you trade'}, {'id' : 'POPULAR', 'text': 'Popular products in kalgudi'}, ] } else { $scope.relevanceTypes = []; } $scope.productPicker = { relevance : $scope.relevanceTypes[0] } $scope.reloadTheStream = function () { if($scope.productPicker.relevance == $scope.relevanceTypes[0].id || $scope.productPicker.relevance == $scope.relevanceTypes[1].id) { $scope.showDealswith = true; } else { $scope.showDealswith = false; } } $scope.groups ={}; $scope.searchDate= new Date(); $scope.businessTypeList = []; var profilekey = $rootScope.loggedInUserBusinessProfile.profileKey; var businesskey = $rootScope.loggedInUserBusinessProfile.defaultBusinessKey; $scope.LoggedinUserproducts = []; $scope.commodity_picker_active = true; $scope.searchProductList = []; var fertilizers_groupId=["20"]; var pesticides_groupId=["21","22","23","24","26"]; var filtered_Array=[]; var seeds_groupId= fertilizers_groupId.concat(pesticides_groupId); $scope.groups = _.groupBy($rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts, "commodityId"); $scope.commodity_picker_active = false; $scope.selectProductDoneFlag = false; $scope.commodity_thread=0; if($state.current.name=="profile.viewProductshome.viewProducts" || $state.current.data.action=="products" ){ $scope.createProductFlag=true; } $scope.hidefirstslide=$state.current.name; $scope.slidetobeChangedpicker = function(index){ $scope.selectedRow = -1; if(index==0){ $scope.commodity_thread=0; } else if(index==1){ $scope.commodity_thread=1; } } $scope.commoditypicker = function(index) { $ionicSlideBoxDelegate.$getByHandle('commoditymodal').slide(index, [300]); } if(window.location.pathname.indexOf('mobile_index')>-1){ if($state.current.name=="profile.viewProductshome.viewProducts"){ $scope.selectedRow = -1; $scope.thread_index=1; $scope.commodity_thread=1; } }; $scope.scroll_function=function() { $scope.ionic_limit.limit = $scope.ionic_limit.limit+10; } $scope.tabs_click = function(tab){ if(tab === 'first_tab'){ $scope.first_tab = true; $scope.second_tab = false; $scope.third_tab = false; } else if(tab ==='second_tab'){ $scope.first_tab = false; $scope.second_tab = true; $scope.third_tab = false; }else{ $scope.first_tab = false; $scope.second_tab = false; $scope.third_tab = true; } } if($state.current.name == "publish"){ $scope.isPublish = true; } else { $scope.isPublish = false; } $scope.ok = function () { $rootScope.openProduct = false; $scope.modalInstance.close('cancel'); $rootScope.$broadcast('pickerclosed'); $rootScope.createButtonhide = false; }; $scope.cancel = function () { $rootScope.openProduct = false; $scope.modalInstance.dismiss('cancel'); $rootScope.$broadcast('pickerclosed'); $rootScope.createButtonhide = false; }; $scope.expandBrands = function (argument) { $scope.openBrands('lg'); $scope.cancel(); } $scope.openBrands = function (size) { var modalInstance = $uibModal.open({ templateUrl: 'myModalContent.html', controller: 'mybrandsmodalController', size:'md', windowClass:'custom-model', resolve: { items: function () { return 'businessmessages'; } } }); modalInstance.result.then(function (selectedItem) { }, function () { }); }; $scope.businessTypeFun = function(){ commonServices.bizTypes().then(function(result){ var displayList = result; for(index in displayList) { $scope.businessTypeList[index] = displayList[index].businessTypeName; } }); } $scope.pickerSearchServiceCall = function(query,countryCode,stateId) { //$rootScope.linearprogressbardisplay(); $rootScope.spinerisActive = true; profileService.pickerproductscat(query,countryCode,stateId).then(function(result){ $rootScope.spinerisActive = false; if(result.length==0){ $scope.listofproduct = []; $scope.noresultFlag=true; } else{ $scope.listofproduct = []; $scope.noresultFlag=false; $scope.searchProductList = result; for(var index in $scope.searchProductList){ for(i in $scope.searchProductList[index].productList) { if($scope.searchProductList[index].productList[i].alsoKnownAs != '') { $scope.ProductAlsoKnownAsNames = $scope.searchProductList[index].productList[i].alsoKnownAs.split(','); $scope.searchProductList[index].productList[i].alsoKnownAsNames = $scope.ProductAlsoKnownAsNames; } } $scope.listofproduct.push({"listofproduct":$scope.searchProductList[index]}); $scope.commoditypickerwindows = function(productname,index) { if(productname.alsoKnownAs.indexOf(":") > -1){ $scope.Modelproduct = productname.alsoKnownAs; } else { $scope.Modelproduct = $scope.transactionLiterals.searchByKey('KL_SHRD_0144')+ productname.alsoKnownAs; } var alertPopup = $ionicPopup.alert({ title: productname.productName, template : $scope.Modelproduct, }); alertPopup.then(function(res) { }); } } } $scope.commodity_picker_active = false; $rootScope.spinerisActive = false; //$rootScope.linearprogressbarcancel(); }); } $scope.pickerNewSearchServiceCall = function(query,countryCode,stateId) { $rootScope.spinerisActive = true; profileService.newProductPicker(query,countryCode,stateId) .then(function(result) { $rootScope.spinerisActive = false; if(result.length==0){ $scope.listofproduct = []; $scope.noresultFlag=true; $scope.baseProducts =""; $scope.varities =""; $scope.brands =""; $scope.lstOfindividualProducts = []; $scope.brandsCount=0; $scope.varitiesCount=0; $scope.baseCount = 0; } else { $scope.listofproduct = []; $scope.baseProducts =""; $scope.varities =""; $scope.brands =""; $scope.lstOfindividualProducts = []; $scope.noresultFlag=false; $scope.searchProductList = result; for(var index in $scope.searchProductList){ for(i in $scope.searchProductList[index].productList) { if($scope.searchProductList[index].productList[i].alsoKnownAs != '') { $scope.ProductAlsoKnownAsNames = $scope.searchProductList[index].productList[i].alsoKnownAs.split(','); $scope.searchProductList[index].productList[i].alsoKnownAsNames = $scope.ProductAlsoKnownAsNames; } } $scope.listofproduct.push({"listofproduct":$scope.searchProductList[index]}); for(var i in $scope.listofproduct){ if($scope.listofproduct[i].listofproduct.productType == 'Base Product'){ // this loop will concatinate commonAka and localAka name and sort list according to search 'key' for(var j in $scope.listofproduct[i].listofproduct.lstOfProducts){ similarAka =[]; dissimilarAka = []; var commonAka; if($scope.listofproduct[i].listofproduct.lstOfProducts[j].commonAlsoKnownAs){ commonAka = ''; commonAka = $scope.listofproduct[i].listofproduct.lstOfProducts[j].commonAlsoKnownAs.split(','); for(var k in commonAka){ if(commonAka[k].toLowerCase().includes(query.toLowerCase())){ similarAka.push(commonAka[k]); }else{ dissimilarAka.push(commonAka[k]); } } } if($scope.listofproduct[i].listofproduct.lstOfProducts[j].localAlsoKnownAs){ commonAka = ''; commonAka = $scope.listofproduct[i].listofproduct.lstOfProducts[j].localAlsoKnownAs.split(','); for(var k in commonAka){ if(commonAka[k].toLowerCase().includes(query.toLowerCase())){ similarAka.push(commonAka[k]); }else{ dissimilarAka.push(commonAka[k]); } } } $scope.listofproduct[i].listofproduct.lstOfProducts[j].similarAka = similarAka.join(', '); $scope.listofproduct[i].listofproduct.lstOfProducts[j].dissimilarAka = dissimilarAka.join(', '); } $scope.baseProducts = $scope.listofproduct[i].listofproduct.lstOfProducts; $scope.baseCount = $scope.listofproduct[i].listofproduct.count;} if($scope.listofproduct[i].listofproduct.productType == 'variety'){ $scope.varities = $scope.listofproduct[i].listofproduct.lstOfProducts; $scope.varitiesCount = $scope.listofproduct[i].listofproduct.count;} if($scope.listofproduct[i].listofproduct.productType == 'brand'){ $scope.brands = $scope.listofproduct[i].listofproduct.lstOfProducts; $scope.brandsCount = $scope.listofproduct[i].listofproduct.count;} if($scope.listofproduct[i].listofproduct.suggestedWord){ $scope.searchResultsText = 'search results for' + ' "' + $scope.listofproduct[i].listofproduct.suggestedWord + '" ' + 'instead of' + ' "' + $scope.listofproduct[i].listofproduct.keyword + '"'; }else{ $scope.searchResultsText = 'search results for' + ' "' + $scope.listofproduct[i].listofproduct.keyword + '"'; } } } } $scope.commodity_picker_active = false; }, function (err) { $rootScope.spinerisActive = false; } ); } $scope.getNewProductsList = function(query){ $scope.showAutocomplete = false; $scope.showDealswith = false; $scope.filterShow=true; $scope.listofproduct = []; $scope.countryCode = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId; $scope.stateId = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.stateId; $scope.searchSuggestion = ""; $scope.searchSuggestionFlag = false; if(query != "" && query != undefined) { $scope.commodity_picker_active = true; $scope.pickerNewSearchServiceCall(query,$scope.countryCode,$scope.stateId); } } $scope.getProductsList = function(query){ $scope.filterShow=true; $scope.listofproduct = []; $scope.countryCode = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId; $scope.stateId = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.stateId; $scope.searchSuggestion = ""; $scope.searchSuggestionFlag = false; if(query != "" && query != undefined) { $scope.commodity_picker_active = true; $scope.pickerSearchServiceCall(query,$scope.countryCode,$scope.stateId); } } $scope.getProductsByType = function(query,type){ $scope.countryCode = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId; $scope.stateId = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.stateId; $scope.listofproductByType = []; $scope.productsByTypeServiceall($scope.searchProductList[0].keyword,$scope.countryCode,$scope.stateId,type); } $scope.productsByTypeServiceall = function(query,countryCode,stateId,type) { //$rootScope.linearprogressbardisplay(); profileService.productsByTypeService(query,countryCode,stateId,type).then(function(result){ if(result.length==0){ $scope.listofproductByType = []; } else{ $scope.listofproductByType = []; $scope.listofproductByType = result; for(var i in $scope.listofproductByType){ $scope.lstOfindividualProducts = $scope.listofproductByType[i].lstOfProducts; } } }); } for(var index in $scope.groups){ if($scope.isPublish){ $scope.groups[index][0].isSelected = false; } if($scope.groups[index][0].groupId != "31" && $scope.groups[index][0].groupId != "32" && $scope.groups[index][0].groupId != "33" && $scope.groups[index][0].groupId != "34" && $scope.groups[index][0].groupId != "35" && $scope.groups[index][0].groupId != undefined){ var product = { "pickerCommonInfoTo":"", "productList":[] } product.pickerCommonInfoTo = { "groupId":$scope.groups[index][0].groupId, "groupName":$scope.groups[index][0].groupName, "commodityId":$scope.groups[index][0].commodityId, "commodityName":$scope.groups[index][0].commodityName }; for(var i in $scope.groups[index]){ product.productList.push($scope.groups[index][i]); } $scope.searchProductList.push(product); } } for(var index in $scope.searchProductList){ $scope.LoggedinUserproducts.push($scope.searchProductList[index]); $scope.productknownas=[]; $scope.productknownaslength=""; $scope.strFlag=false; var productname = []; for(var i in $scope.searchProductList[index].productList){ $scope.searchProductList[index].productList[i].productlength = 0; $scope.searchProductList[index].productList[i].alsoKnownAsList = []; if($scope.searchProductList[index].productList[i].alsoKnownAs != undefined && $scope.searchProductList[index].productList[i].alsoKnownAs != ""){ if($scope.searchProductList[index].productList[i].alsoKnownAs.indexOf(':') > -1){ productname = $scope.searchProductList[index].productList[i].alsoKnownAs.split(':'); $scope.searchProductList[index].productList[i].alsoKnownAsList = productname[1].split(","); $scope.searchProductList[index].productList[i].productlength = $scope.searchProductList[index].productList[i].alsoKnownAsList.length; }else{ $scope.searchProductList[index].productList[i].alsoKnownAsList = $scope.searchProductList[index].productList[i].alsoKnownAs.split(","); $scope.searchProductList[index].productList[i].productlength = $scope.searchProductList[index].productList[i].alsoKnownAsList.length; } } else{ $scope.searchProductList[index].productList[i].alsoKnownAsList = []; $scope.searchProductList[index].productList[i].productlength = 0; } } $scope.commoditypickerwindow = function(productname,index) { if(productname.alsoKnownAs.indexOf(":") > -1){ $scope.Modelproduct = productname.alsoKnownAs; } else { $scope.Modelproduct = $scope.transactionLiterals.searchByKey('KL_SHRD_0144')+productname.alsoKnownAs; } var alertPopup = $ionicPopup.alert({ title: productname.productName, template : $scope.Modelproduct, }); alertPopup.then(function(res) { }); } } $scope.productVariety = function(index,productlist){ $scope.mainListIndex = index; if(productlist != undefined){ if(productlist.listofproduct.productList){ } else{ $scope.productlistisLoading = true; profileService.pickerproductscatProd($scope.countryCode,$scope.stateId,productlist.listofproduct.commodityId).then(function(result){ if($scope.isPublish){ for(var i in result[0][productlist.listofproduct.commodityId].productList){ result[0][productlist.listofproduct.commodityId].productList[i].isSelected = false; } } $scope.productlistisLoading = false; productlist.listofproduct.productList = result[0][productlist.listofproduct.commodityId].productList; }); } } $scope.selectedRow = -1; $scope.selectedList = index; $scope.buttonFlag.productVariety = !$scope.buttonFlag.productVariety; } $scope.unitsBygroup=function(listUnits,customUnits){ for(var indexlistOfunits in listUnits){ listUnits[indexlistOfunits].UnitType="Units"; } for(var indexlistOfCustomunits in customUnits){ customUnits[indexlistOfCustomunits].UnitType="Custom Units"; } return listUnits.concat(customUnits); } $scope.selectSingleProduct = function(productname,index,sku){ if($scope.isPublish){ var isAlreadyAdded = -1; for( var product in $rootScope.selectedProductList){ if($rootScope.selectedProductList[product].productId == productname.productId){ isAlreadyAdded = product ; break; } } if(isAlreadyAdded > -1){ $scope.LoggedinUserproducts[$scope.mainListIndex].productList[index].isSelected = false; $rootScope.selectedProductList.splice(isAlreadyAdded,1); }else { $scope.LoggedinUserproducts[$scope.mainListIndex].productList[index].isSelected = true; $rootScope.selectedProductList.push(productname); } } else { $scope.productDetails = productname.productName; $scope.selectedRow = index; $scope.selectProductDoneFlag = true; $scope.selectProduct = function(){ $rootScope.spinerisActive=true; if(($state.current.data.action == "createTransaction" || $state.current.data.action == "transaction" || $state.current.data.action == "editAndAccept" || $state.current.data.action == "createPool" || $state.current.data.action == "postFullView")||$rootScope.transactionFlagforPicker){ //$scope.currentCommodity.units.unitName = ""; $scope.currentCommodity.units = false; profileService.getUnitsByProductId(productname.productId,$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then(function(result){ if(result != ""){ if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000003"){ if(window.location.pathname.indexOf('mobile_index')>-1) $scope.showProduct.productname = result[0].productName; $scope.currentCommodity.commodityName = result[0]; } else{ if($state.current.data.screenId =="farmer.procurementdetails"){ $scope.transactionProcurementData.commodityName= result[0]; } else{ if(result != ""){ $scope.currentCommodity.commodityName = result[0]; } else{ $scope.currentCommodity.commodityName = productname; } } } $rootScope.qualifierList = []; if($scope.currentCommodity.commodityName.hasOwnProperty("qualifiers") || ($scope.pool != undefined && $scope.pool.selectedPoolProduct.hasOwnProperty("qualifiers"))){ /*if($scope.pool != undefined && $scope.pool.qualifierFlag == true){ $scope.qualifiers = $scope.qualifiers +","+ $scope.pool.selectedPoolProduct.qualifiers; } else{*/ $scope.qualifiers = $scope.qualifiers +","+ $scope.currentCommodity.commodityName.qualifiers; /*}*/ var splitlist = $scope.qualifiers.split(','); $rootScope.qualifierList.push(splitlist); } $scope.currentCommodity.commodityName.allunits=[]; $scope.currentCommodity.commodityName.allunits=$scope.unitsBygroup($scope.currentCommodity.commodityName.listofUnits,$scope.currentCommodity.commodityName.customunits); } else{ $scope.currentCommodity.commodityName = productname; } if(sku){ var request = { productList : $scope.currentCommodity.commodityName, sku:sku, type:'' } $scope.autoFilledSkuData(request); } }); } if($state.current.data.action == "ccppost"){ profileService.getUnitsByProductId(productname.productId,$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then(function(result){ if(result != ""){ $scope.currentCommodity.commodityName = result[0]; } else{ $scope.currentCommodity.commodityName = productname; } }); } if($state.current.data.action == "createPool") { if(window.location.pathname.indexOf('mobile_index')>-1){ $scope.closePoolCommodityModal(productname); } } if($state.current.data.action=="home" || $state.current.name=="myconnects.groups" ){ profileService.getUnitsByProductId(productname.productId,$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then(function(result){ if(result != ""){ $scope.currentCommodity.commodityName = result[0]; $scope.currentCommodity.commodityName.allunits=[]; $scope.currentCommodity.commodityName.allunits=$scope.unitsBygroup($scope.currentCommodity.commodityName.listofUnits,$scope.currentCommodity.commodityName.customunits); } else{ $scope.currentCommodity.commodityName = productname; } }); } if(($state.current.data.action == "post" || $state.current.data.action == "visitorsPostMessage" ||$state.current.data.action=="postMessage" || $state.current.name=="myconnects.opportunityInbox" || $state.current.data.action == "postMessage_stream"||$state.current.data.action == "streamInbox" )&& !$rootScope.transactionFlagforPicker|| ($state.current.name=="programs.activities" && $scope.fourth_tab)){ const isCropModal = $scope.cropModal; profileService.getUnitsByProductId(productname.productId,$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then(function(result){ if(result != ""){ result[0].qualifiersList = result[0].qualifiers.split(','); if($scope.postMessageFormData){ if (isCropModal) { $scope.postMessageFormData.crop = result[0]; $scope.postMessageFormData.product = result[0].productName; } else { $scope.postMessageFormData.commodity = result[0]; $scope.postMessageFormData.product = result[0].productName; $scope.postMessageFormData.commodity.allunits=[]; $scope.postMessageFormData.commodity.allunits=$scope.unitsBygroup($scope.postMessageFormData.commodity.listofUnits,$scope.postMessageFormData.commodity.customunits); } } if($scope.currentCommodity){ $scope.currentCommodity.commodityName = result[0]; $scope.currentCommodity.commodityName.allunits=[]; $scope.currentCommodity.commodityName.allunits=$scope.unitsBygroup($scope.currentCommodity.commodityName.listofUnits,$scope.currentCommodity.commodityName.customunits); } } else{ $scope.postMessageFormData.commodity = productname; } if(sku){ var request = { productList : $scope.postMessageFormData? $scope.postMessageFormData.commodity :$scope.currentCommodity.commodityName, sku:sku, type:'' } $scope.autoFilledSkuData(request); } }); } /*if($state.current.data.action == "createPool") { $scope.closePoolCommodityModal(productname); }*/ if($state.current.data.action=="shareAnUpdate"){ profileService.getUnitsByProductId(productname.productId,$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then(function(result){ if(result != ""){ $scope.currentCommodity.commodityName = result[0]; }else{ $scope.currentCommodity.commodityName = productname; } }); } if(($state.current.data.action == "myprofile" || $state.current.data.action == "precreations" || $state.current.name=="profile.viewProductshome.viewProducts") && $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId != 'BT000010') { if($scope.currentCommodity){ $scope.currentCommodity.commodityName = productname; if(!$rootScope.isProductNotRequired){ $scope.productToProfile(); } else{ $scope.addProductToAssets(); } } if($scope.brandsInfo){ $scope.brandsInfo.product.push({ productId:productname.productId, productName:productname.productName, baseUnitId:productname.baseUnitId, baseUnitName:productname.baseUnitName, imageUrl :productname.imageUrl }); var productArr= []; var baseUnitArr = []; for(var i in $scope.brandsInfo.product){ productArr.push({ name:$scope.brandsInfo.product[i].productName, id:$scope.brandsInfo.product[i].productId, imageUrl: $scope.brandsInfo.product[i].imageUrl } ); $scope.brandsInfo.productNames = productArr; baseUnitArr.push($scope.brandsInfo.product[i].baseUnitName); } var unique = baseUnitArr.filter(function(elem, index, self) { return index == self.indexOf(elem); }) $scope.brandsInfo.base_unit = unique.join(); } } if(($state.current.name=="profile.viewProductshome.viewProducts"||$state.current.data.module == "myprofile") && $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000010'){ if($scope.stockboardDetails){ $scope.stockboardDetails[0].productName = productname; } if($scope.currentCommodity){ $scope.currentCommodity.commodityName = productname; $scope.productToProfile(); } if($scope.brandsInfo){ $scope.brandsInfo.product.push({ productId:productname.productId, productName:productname.productName, baseUnitId:productname.baseUnitId, baseUnitName:productname.baseUnitName, imageUrl :productname.imageUrl }); var productArr= []; var baseUnitArr = []; for(var i in $scope.brandsInfo.product){ productArr.push({ name:$scope.brandsInfo.product[i].productName, id:$scope.brandsInfo.product[i].productId, imageUrl: $scope.brandsInfo.product[i].imageUrl } ); $scope.brandsInfo.productNames = productArr; baseUnitArr.push($scope.brandsInfo.product[i].baseUnitName); } var unique = baseUnitArr.filter(function(elem, index, self) { return index == self.indexOf(elem); }) $scope.brandsInfo.base_unit = unique.join(); } } if($state.current.name=="programs.profileHome.productUpdate" || ($state.current.name=="programs.activities" && !$scope.fourth_tab)){ if($scope.currentCommodity){ $scope.currentCommodity.commodityName = productname; $scope.productToProfile(); } } if ($state.current.name === 'mybusiness.amp.virtualPost.create') { $scope.getProductUnits(productname); } if ("catalogue-creation" === $state.current.data.action) { $scope.selectedProduct(productname); } if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $scope.ok(); $rootScope.openProduct=false; }else{ $scope.closecommodityModal(); } $rootScope.spinerisActive=false; $rootScope.$broadcast('onProductSelection', productname); } } } /** * Gets, product units and on success groups all unit in their individual * sections. * * @param {any} productDetails */ $scope.getProductUnits = function (productDetails) { profileService.getUnitsByProductId(productDetails.productId, $rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then( function(res) { if(res && res.length > 0) { res[0].qualifiersList = res[0].qualifiers.split(','); productDetails.allUnits = $scope.unitsBygroup(res[0].listofUnits, res[0].customunits); } $rootScope.$broadcast('productSelected', productDetails); }, function (err) { console.warn('Unable to get product units for selected product. ', productDetails); console.warn(err); } ); } $scope.onchangeflagValidation= function(){ $scope.queryValidationFlag.queryFlag = false; $scope.searchDate= new Date(); $timeout(function(){ if(Number(new Date())-Number($scope.searchDate)>= pickersTime){ $scope.searchDate= new Date(); if($scope.query.productName.length>2){ //$scope.getProductsList($scope.query.productName); } } },pickersTime); } $scope.showFilterOptions = function(){ $scope.filterByFlag = !$scope.filterByFlag; if($scope.filterByFlag == true){ $scope.businessTypeFun(); } } $scope.filterSearchResults =function(filterByLocation,filterByBusinessType){ var tempflag = true; if($scope.query.productName== undefined || $scope.query.productName== ''){ $scope.queryValidationFlag.queryFlag = true; $rootScope.commonTopErrorAlert($scope.transactionLiterals.searchByKey('KL_SRCH_0001')); tempflag = false; $scope.showFilterOptions(); } else{ //$scope.selectedRow = index; $rootScope.spinerisActive = true; $scope.countryobj=''; $scope.stateobj = ''; if(filterByLocation=="My country") { //$scope.typeList[id].isSelected = true; $scope.countryobj=$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId; } else if(filterByLocation=="Connected countries") { //$scope.typeList[id].isSelected = true; var countryArrObj = []; for(var Countries in $rootScope.loggedInUserCurrentBussinessInfo.lstBizInterest) { if(countryArrObj.indexOf($rootScope.loggedInUserCurrentBussinessInfo.lstBizInterest[Countries].placeId.substring(0,3))<0){ countryArrObj.push($rootScope.loggedInUserCurrentBussinessInfo.lstBizInterest[Countries].placeId.substring(0,3)); } } for(var countryIndex in countryArrObj){ if($scope.countryobj == ""){ $scope.countryobj = countryArrObj[countryIndex]; } else{ $scope.countryobj = $scope.countryobj +","+countryArrObj[countryIndex]; } } } else if(filterByLocation=="World wide" || filterByLocation==undefined){ //$scope.typeList[id].isSelected = true; $scope.countryobj='ALL'; } $scope.stateobj=$rootScope.loggedInUserCurrentBussinessInfo.locationTo.stateId; $scope.pickerSearchServiceCall($scope.query.productName,$scope.countryobj,$scope.stateobj); $scope.filterByFlag = !$scope.filterByFlag; return tempflag; } } $scope.openmodalProductCategoryModal = function(type) { $scope.modalProductCategory = true; $scope.modalProductCategorytype=type; //$scope.modalProductCategory.show(); }; $scope.closemodalProductCategoryModal = function() { $scope.modalProductCategorytype=""; $scope.modalProductCategory = false; //$scope.modalProductCategory.hide(); }; //Autocomplete : passing this service through directive attribute to get the result $scope.callTheService= function(){ var obj = {"type":"Products","keyword":$scope.query.productName,"offset":0,"limit": $scope.autocompletesSearchProp.maxAutoCompletes} return profileServicedata.autocompleteSearch(obj).then(function(result){ return result.data; }); }; // Cleanup the modal when we're done with it! /*$scope.$on('$destroy', function() { if((window.location.pathname.indexOf('mobile_index')>-1) && $scope.modalProductCategory) $scope.modalProductCategory.remove(); }); */ }]);