angular.module('kalgudiApp.profile').controller('mybrandsController', ["$scope", "newProfileService", "profileService", "$state", "$rootScope", "$timeout", '$filter', 'kalgudiLiterals', "$sce", "commonServices", "helpandlegalservice", "Upload", '$injector', 'S3UploadService', function($scope, newProfileService, profileService, $state, $rootScope, $timeout, $filter, kalgudiLiterals, $sce, commonServices, helpandlegalservice, Upload, $injector, S3UploadService) { $scope.profileLiterals=kalgudiLiterals; if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $uibModal = $injector.get("$uibModal"); } else{ $ionicModal=$injector.get("$ionicModal"); $ionicModal.fromTemplateUrl('app/themes/mobile_app/myprofile/templates/view/productSku.html', { scope: $scope, animation: 'slide-in-up' }).then(function(modal) { $scope.modal = modal; }); }; $scope.openModal = function() { $scope.brandSku=_.find($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts,function(e){return e.showMySKUflag==true;}); $scope.modal.show(); }; $scope.closeModal = function() { $scope.modal.hide(); }; // Cleanup the modal when we're done with it! $scope.$on('$destroy', function() { $scope.modal.remove(); }); $scope.skuRequest={ mediaURLs:[] }; $scope.sku = { imageURL : [], } $scope.redirect = function() { document.body.scrollTop = document.body.scrollHeight; } $scope.onBrandImageChange=function($files, $file, $newFiles, $duplicateFiles, $invalidFiles, $event){ if($file){ var contentType = $file.type; helpandlegalservice.uploadBrandsImagePolicy(contentType).then(function(result){ $scope.policyData= result; $scope.customModel = $files; /*$scope.compressFile( $file,$files);*/ S3UploadService.compressImage($file).then( function (compressedImage) { $scope.compressUploadProfilePic (compressedImage, $files); }); }); } } /*$scope.compressFile=function(file,uploadedFiles) { //Create an image var img = document.createElement("img"); // Create a file reader var reader = new FileReader(); // Load files into file reader reader.readAsDataURL(file); // Set the image once loaded into file reader reader.onload = function(e) { img.src = e.target.result; var canvas = document.createElement("canvas"); var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var MAX_WIDTH = 720; var MAX_HEIGHT = 720; var width = img.width; var height = img.height; if(width>0||height>0){ if (width > height) { if (width > MAX_WIDTH) { height *= MAX_WIDTH / width; width = MAX_WIDTH; } } else { if (height > MAX_HEIGHT) { width *= MAX_HEIGHT / height; height = MAX_HEIGHT; } } canvas.width = width; canvas.height = height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, width, height); var dataurl = canvas.toDataURL("image/jpeg",0.8); var byteString; if (dataurl.split(',')[0].indexOf('base64') >= 0) byteString = atob(dataurl.split(',')[1]); else byteString = unescape(dataurl.split(',')[1]); // separate out the mime component var mimeString = dataurl.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to a typed array var ia = new Uint8Array(byteString.length); for (var i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } var tempBlob = new Blob([ia], {type:"image/jpeg"}); $scope.compressUploadProfilePic(tempBlob,uploadedFiles); } else { $scope.compressUploadProfilePic(file,uploadedFiles); } } }*/ $scope.compressUploadProfilePic=function(file,tempFile) { var bucketname= 'kalgudibucket'; if($scope.customModel != undefined){ file.upload = Upload.upload({ //url: 'http://'+bucketname+'.s3.amazonaws.com/', //S3 upload url including bucket name url : ATTACH_BUCKETNAME+".s3.amazonaws.com/", method: 'POST', data: { key: 'data/userUploads/' + $scope.customModel[0].name, // the key to store the file on S3, could be file name or customized AWSAccessKeyId: 'AKIAJPKIEGQPZLTARDXQ', acl: 'public-read', // sets the access to the uploaded file in the bucket: private, public-read, ... policy: $scope.policyData.policy, // base64-encoded json policy (see article below) signature: $scope.policyData.signature, // base64-encoded signature based on policy string (see article below) "Content-Type": file.type != '' ? file.type : 'application/octet-stream', // content type of the file (NotEmpty) // this is needed for Flash polyfill IE8-9 file: file }, }); file.upload.then(function (response) { $timeout(function () { file.result = response.data; if($scope.customModel != undefined){ var urlMediaObject={url:ATTACH_BUCKETNAME+".s3.amazonaws.com/"+'data/userUploads/' + $scope.customModel[0].name}; urlMediaObject.itemType="image"; $scope.sku.imageURL.unshift(urlMediaObject); $scope.skuRequest.mediaURLs=$scope.sku.imageURL; } else { $scope.web.imageURL=[]; } }); }); } } /*Changing State*/ $scope.changeState = function(sku,brands,type){ if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000000'){ $state.go("mybusiness.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000007' || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000012' || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000015' || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000016' || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000017' || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000018' || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000019' ){ $state.go("basicApp.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000001'){ $state.go("CA.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000002'){ $state.go("farmer.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000006'){ $state.go("mywarehouse.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000008'){ console.log("imgherer"); $state.go("agriInput.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000013'){ $state.go("intermediaryApp.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000014'){ $state.go("agencyApp.transactionInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000010'){ $state.go("coApp.streamInbox"); }else if($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == 'BT000003'){ $state.go("mytransporter.streamInbox"); } var request = { productList : brands, sku:sku, type:type } $timeout(function(){ if(type != 'sale' && type != 'purchase'){ $rootScope.$broadcast("fromProfileState",request); } else{ $rootScope.$broadcast("fromProfileStateTransaction",request); } },500); } /*End of Changing state*/ $scope.profileServiceCallRefresh =function(){ profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey).then(function(result) { $rootScope.loggedInUserBusinessProfile = result; localStorage['userdata'] = JSON.stringify(result); $rootScope.loggedInUserCurrentBussinessInfo = _.find($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo,function(rw){ return rw.businessUUID == $rootScope.globalConfig.currentBussinessId }); //$rootScope.$broadcast('loggedInUserProfieLoaded',"true"); }); } /*To open in new window*/ $scope.specialClick = function (brands) { var url = $state.href('brandsFullview', {brandId: brands.productId}); window.open(url,'_blank'); } /*End of opening new window*/ /*For framing img for Video url*/ if ($scope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo && $scope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts.length && $state.params.brandId) { $rootScope.spinerisActive = true; var existed = false; for(var i in $scope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts){ if($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[i].hasOwnProperty('brandId') && $scope.loggedInUserCurrentBussinessInfo.listofUserBrands[i].brandId == $state.params.brandId){ $rootScope.spinerisActive = false; existed = true; $scope.fullviewbrand=$rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands[i]; for(var j in $scope.fullviewbrand.mediaUrls.videourls){ $scope.frame_temp = $scope.fullviewbrand.mediaUrls.videourls[j].url; if($scope.frame_temp.includes("=")){ $scope.UrlId = $scope.frame_temp.substring($scope.frame_temp.lastIndexOf("=")); $scope.UrlId = $scope.UrlId.replace("=","/"); }else{ $scope.UrlId = $scope.frame_temp.substring($scope.frame_temp.lastIndexOf("/")); } $scope.ImgUrlVideo = "https://img.youtube.com/vi"+$scope.UrlId+"/default.jpg"; break; } break; } else if($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[i].productId == $state.params.brandId){ $rootScope.spinerisActive = false; existed = true; $scope.fullviewbrand=$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[i]; if($scope.fullviewbrand.hasOwnProperty('mediaURLs')){ for(var j in $scope.fullviewbrand.mediaURLs.videourls){ $scope.frame_temp = $scope.fullviewbrand.mediaURLs.videourls[j].url; if($scope.frame_temp.includes("=")){ $scope.UrlId = $scope.frame_temp.substring($scope.frame_temp.lastIndexOf("=")); $scope.UrlId = $scope.UrlId.replace("=","/"); }else{ $scope.UrlId = $scope.frame_temp.substring($scope.frame_temp.lastIndexOf("/")); } $scope.fullviewbrand.mediaURLs.videourls[j].ImgUrlVideo = "https://img.youtube.com/vi"+$scope.UrlId+"/default.jpg"; } } break; } else{ $rootScope.spinerisActive = false; } } if(!existed){ commonServices.getProductinfo($state.params.brandId) .then( function(serviceResponse) { $rootScope.spinerisActive = false; $scope.fullviewbrand = serviceResponse; }); } } if($scope.fullviewbrand && $scope.fullviewbrand.hasOwnProperty('mediaURLs')){ for(var k in $scope.fullviewbrand.mediaURLs.imageUrls){ if($scope.fullviewbrand.mediaURLs.imageUrls[k].itemType == "image"){ $scope.imgIndex = k; break; } } } /*End of framing thumbnail for youtube*/ /*url construction and binding*/ $scope.ClickedVideo = false; $scope.changeImg = function(index){ $scope.clickedAnotherImg = true; $scope.ClickedVideo = false; $scope.showImg = $scope.fullviewbrand.mediaURLs.imageUrls[index].url; } $scope.ClickedVideo = false; $scope.constructUrl= function(videUrl){ $scope.frame_temp = videUrl.url; if($scope.frame_temp.includes("=")){ $scope.UrlId = $scope.frame_temp.substring($scope.frame_temp.lastIndexOf("=")); $scope.UrlId = $scope.UrlId.replace("=","/"); }else{ $scope.UrlId = $scope.frame_temp.substring($scope.frame_temp.lastIndexOf("/")); } $scope.clickedAnotherImg = false; $scope.ClickedVideo = true; $scope.showImg = "https://www.youtube.com/embed"+$scope.UrlId; $scope.showImg = $sce.trustAsResourceUrl($scope.showImg); } /*end of url construction and binding*/ /*limit changes based on function click*/ $scope.limit = 2; $scope.noText = true; $scope.incrementLimit = function() { $scope.limit += 2; //var totalBrandsCount = 0; var totalProductsCount = 0; var totalCount = $scope.limit; /*if($scope.loggedInUserCurrentBussinessInfo.hasOwnProperty('listofUserBrands') && $scope.loggedInUserCurrentBussinessInfo.listofUserBrands.length!=0){ totalBrandsCount = $scope.loggedInUserCurrentBussinessInfo.listofUserBrands.length; }*/ if($scope.loggedInUserCurrentBussinessInfo.hasOwnProperty('lstOfProducts') && $scope.loggedInUserCurrentBussinessInfo.lstOfProducts.length!=0){ totalProductsCount = $scope.loggedInUserCurrentBussinessInfo.lstOfProducts.length; } if(totalCount>=totalProductsCount){ $scope.noText = false; } for(var skuOpen in $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts){ $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[skuOpen].showMySKUflag = false; } }; $scope.decreementLimit = function(){ $scope.noText = true; $scope.limit = 2; for(var skuOpen in $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts){ $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[skuOpen].showMySKUflag = false; } }; /*End limit changes based on function click*/ /*Showing SKU on click*/ //$scope.showMySKUflag = false; $scope.showSKUaction=false $scope.showMySKU = function(index){ $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[index].showMySKUflag = !$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[index].showMySKUflag; } /*End of Showing SKU on click*/ /*For open 3 dor menu*/ /*$scope.showmenu = function(index){ $scope.mainIndex = index; $rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands[index].showmenuFlag = !$rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands[index].showmenuFlag; }*/ $scope.showSKUmenuFlag = false; $scope.showSKUmenu = function(sku){ sku.showSKUmenuFlag = !sku.showSKUmenuFlag; } $scope.showProductmenuFlag = false; $scope.showProductmenu = function(index){ $scope.showProductmenuFlag = !$scope.showProductmenuFlag; } /*End of three dot menu*/ $scope.offset = 0; $scope.shiftRight = function(){ $scope.offset = $scope.offset + 3; if($rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands){ $scope.offset = $rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands.length - ($rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands.length - $scope.offset); if($scope.offset >= $rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands.length){ $scope.offset = 0; } } } $scope.shiftLeft = function(){ $scope.offset = $scope.offset - 3; if($rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands){ if($scope.offset < 0){ $scope.offset = $rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands.length -3; } } } $scope.dealsOffset= 0; $scope.shiftDealRight = function(){ $scope.dealsOffset = $scope.dealsOffset + 3; if($rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts){ $scope.dealsOffset = $rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts.length - ($rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts.length - $scope.dealsOffset); if($scope.dealsOffset >= $rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts.length){ $scope.dealsOffset = 0; } } } $scope.shiftDealLeft = function(){ $scope.dealsOffset = $scope.dealsOffset - 3; if($rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts){ if($scope.dealsOffset < 0){ $scope.dealsOffset = $rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts.length -3; } } } $scope.deleteUserBrand=function(id,type,sku,list){ var temp = true; if(sku && list.skusList.length == 1){ temp = false; } if(temp){ newProfileService.deleteProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,id,type,sku).then(function(result){ //$scope.resetBrands(); if(result.code == "201"){ $scope.profileServiceCallRefresh(); //$rootScope.loggedInUserCurrentBussinessInfo.listofUserBrands[$scope.mainIndex].showmenuFlag = false; } }) } else{ alert("One sku should be in your brand"); } } //Add stock to sku $rootScope.$on('stockMenuopen',function(event,data){ if((data.skusList && data.skusList.length == 0) || !data.hasOwnProperty('skusList')) $scope.addSkuToStock('',data); }) $scope.addSkuToStock = function(index,brands){ profileService.getUnitsByProductId(brands.productId,$rootScope.loggedInUserCurrentBussinessInfo.locationTo.countryId).then(function(result){ if(result!=""){ $scope.skuUnits=result[0].listofUnits.concat(result[0].customunits); } }); brands.showmenuFlag=false; brands.showAddStockFlag = !brands.showAddStockFlag; if (typeof $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[index] !== 'undefined' && $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[index] !== null) { $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfProducts[index].showMySKUflag=false; } $scope.addStock = { name:brands.productName, Image:'', stock:0, price:0, unit:'' } if(brands.hasOwnProperty('productList') && brands.productList[0]!=undefined){ $scope.addStock.unit=brands.productList[0].baseUnitName; }else{ $scope.addStock.unit=brands.baseUnitName; } $scope.skuRequest.mediaURLs[0] = {}; if(brands.hasOwnProperty('mediaURLs')){ $scope.skuRequest.mediaURLs[0].url =brands.mediaURLs.imageUrls[0].url } else{ $scope.skuRequest.mediaURLs[0].url = brands.imageUrl } } $scope.closeStockFunc=function(brand){ brand.showAddStockFlag=false } $scope.addStockFunc = function(brand){ var unit; if(brand.isApproved){ unit=$scope.addStock.unit.unitName; } else{ unit=$scope.addStock.unit; } var request = { 'brandId':brand.hasOwnProperty('brandId') ? brand.brandId : brand.productId, 'imageUrl':$scope.skuRequest.mediaURLs[0].url, 'name':$scope.addStock.name, 'unit':unit, 'stock':$scope.addStock.stock, 'price':$scope.addStock.price, 'entryDate':$filter('date')(new Date(), 'yyyy-MM-dd' ), 'productName':brand.productName, 'stock':parseFloat($scope.addStock.stock), 'price':parseFloat($scope.addStock.price), 'approved':brand.isApproved } newProfileService.addStockProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,request).then(function(result){ //$scope.resetBrands(); if(result.code == "201"){ $rootScope.$broadcast("brandsupdated","products"); $scope.profileServiceCallRefresh(); $scope.sku.imageURL = []; $scope.skuRequest.mediaURLs = []; } }) } $scope.addStock = { name:'', Image:'', stock:'', price:'', unit:'' } $scope.openEdit = function(brands) { //$scope.edit = true; $scope.open('sm','edit',brands); brands.showmenuFlag = false; } $scope.open = function (size,type,brands) { var request = { data : brands, type: "edit" } var modalInstance = $uibModal.open({ templateUrl: 'myModalContent.html', controller: 'mybrandsmodalController', size:size, windowClass:'brands_modal', resolve: { items: function () { return request; } } }); modalInstance.result.then(function (selectedItem) { }, function () { }); }; }]); angular.module('kalgudiApp.profile').controller('mybrandsfullviewController', ["$scope","newProfileService","profileService","$state","$rootScope","$timeout",'$filter','kalgudiLiterals',"$uibModal",'items','$uibModalInstance', function($scope,newProfileService,profileService,$state,$rootScope,$timeout,$filter,kalgudiLiterals,$uibModal,items,$uibModalInstance){ $scope.profileLiterals=kalgudiLiterals; $scope.fullviewbrand=items; $scope.edit=false; $scope.fullviewOfImage={image:$scope.fullviewbrand.mediaURLs[0].url,type:'image'}; $scope.cancel = function() { $uibModalInstance.dismiss('cancel'); }; $scope.profileServiceCallRefresh =function(){ profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey).then(function(result) { $rootScope.loggedInUserBusinessProfile = result; $rootScope.loggedInUserCurrentBussinessInfo = _.find($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo,function(rw){ return rw.businessUUID == $rootScope.globalConfig.currentBussinessId }); }); } $scope.deleteUserBrand=function(id){ newProfileService.deleteProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,id).then(function(result){ $scope.cancel(); if(result.code == "201"){ $scope.profileServiceCallRefresh(); } }) } $scope.editBrand=function(){ newProfileService.editProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,$scope.fullviewbrand).then(function(result){ $scope.edit=false; if(result.code == "201"){ $scope.profileServiceCallRefresh(); } }); } $scope.openEdit = function(argument) { //$scope.edit = true; $scope.open('sm','edit') } $scope.open = function (size,type) { var request = { data : $scope.fullviewbrand, type: "edit" } var modalInstance = $uibModal.open({ templateUrl: 'myModalContent.html', controller: 'mybrandsmodalController', size:size, windowClass:'brands_modal', resolve: { items: function () { return request; } } }); modalInstance.result.then(function (selectedItem) { }, function () { }); }; }]); var mybrandsmodalController = function($scope,newProfileService,profileService,$state,$rootScope,$timeout,$filter,kalgudiLiterals){ //amit change $scope.connectsLiterals = kalgudiLiterals; var $uibModalInstance,$uibModal,items; if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $uibModal = arguments[arguments.length-3];//$injector.get("$uibModal"); $uibModalInstance = arguments[arguments.length-2];//$injector.get("$uibModalInstance"); items = arguments[arguments.length-1];//$injector.get("items"); }; $scope.brandRequest={ brandDescription:'', brandTitle:'', mediaURLs:[], youTube: '', docxUrls:[], VideoUrls:[] } $scope.brandsInfo ={ product:[], brand_name:'', description:'', company:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, keyword:'', base_unit:'', productNames:'' } $scope.productInfo = { name:'', description:'', company:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, baseUnit:'', keyword:'' } $scope.otherFields = { fields:[] } $scope.brandsFlag = false; $scope.productsFlag = false; $scope.closeSelectionFlag = true; $scope.createBrand = function(){ $scope.brandsFlag = true; $scope.productsFlag = false; $scope.closeSelectionFlag = false; } $scope.createProducts =function(){ $scope.productsFlag = true; $scope.brandsFlag = false; $scope.closeSelectionFlag = false; } $scope.backbrandsProducts =function(){ $scope.closeSelectionFlag = true; $scope.brandsFlag = false; $scope.productsFlag = false; } $scope.profileServiceCallRefresh =function(){ profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey).then(function(result) { $rootScope.loggedInUserBusinessProfile = result; $rootScope.$broadcast('stockMenuopen',result.lstOfUserBusinessDetailsInfo[0].lstOfProducts[0]); $rootScope.loggedInUserCurrentBussinessInfo = _.find($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo,function(rw){ return rw.businessUUID == $rootScope.globalConfig.currentBussinessId }); //$rootScope.$broadcast('loggedInUserProfieLoaded',"true"); }); } $scope.resetBrands=function(){ $scope.brandRequest.brandDescription=''; $scope.brandRequest.brandTitle=''; $scope.brandRequest.mediaURLs=[]; $rootScope.$broadcast('resetMultiIMages'); } $scope.cancel = function() { if(!(window.location.pathname.indexOf('mobile_index')>-1)){ $uibModalInstance.dismiss('cancel'); }else{ $scope.homeInboxBack(); } $rootScope.$broadcast('createdBrands'); }; function exractModelIfObject(){ for(var i in $scope.brands.fields.fields){ if($scope.brands.fields.fields[i].isFieldSelected && $scope.brands.fields.fields[i].hasOwnProperty('items') && $scope.brands.fields.fields[i].items.length != 0){ $scope.brands.fields.fields[i].model = $scope.brands.fields.fields[i].model.name; } } } /*function addyouTubeUrl() { if($scope.brandRequest.youTube != ''){ var urlMediaObject={url:$scope.brandRequest.youTube}; urlMediaObject.itemType="video"; $scope.brandRequest.mediaURLs.push(urlMediaObject); $scope.brandRequest.youTube = ''; } } $scope.youTube = function(argument) { addyouTubeUrl(); }*/ function brandsValidation(){ var brandsValidate = true; $scope.fieldsFlag = false; if($scope.brandRequest.mediaURLs.length == 0){ alert('Add one image atleast'); brandsValidate = false; } else{ brandsValidate = true; } if($scope.brandRequest.mediaURLs.length != 0 ){ brandsValidate = false; for(var i in $scope.brandRequest.mediaURLs){ if($scope.brandRequest.mediaURLs[i].itemType == 'image'){ brandsValidate = true; } } } /*for(var i in $scope.brands.fields.fields){ if($scope.brands.fields.fields[i].isFieldSelected == true){ if($scope.brands.fields.fields[i].model == '' && $scope.brands.fields.fields[i].name != 'Others'){ brandsValidate = false; $scope.fieldsFlag = true; $timeout(function(){ $scope.fieldsFlag = false; },2000) } } }*/ return brandsValidate; } $rootScope.$on('pickerclosed', function (event, data) { $scope.openProduct = false; }); $scope.openProductPicker = function(argument) { $scope.openProduct = true; $rootScope.createButtonhide = false; } $scope.addUserBrand=function(){ exractModelIfObject(); var mediarequest = { imageUrls:$scope.brandRequest.mediaURLs, videourls:$scope.brandRequest.VideoUrls } var request = { 'data':$scope.brands.fields, 'mediaURLs':mediarequest, 'productList':$scope.brandsInfo.product, 'keywords':$scope.brandsInfo.keyword, 'companyName':$scope.brandsInfo.company, 'productDescription':$scope.brandsInfo.description, 'productName':$scope.brandsInfo.brand_name, 'brand':true, 'skusList':[] } var url = "userbrands"; if(brandsValidation()){ newProfileService.addProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,request,url).then(function(result){ $scope.resetBrands(); if(result.code == "201"){ $scope.profileServiceCallRefresh(); } $scope.cancel(); }) } } $scope.addUserProduct = function(){ var mediarequest = { imageUrls:$scope.brandRequest.mediaURLs, videourls:$scope.brandRequest.VideoUrls } var request = { 'productName':$scope.productInfo.name, 'mediaURLs':mediarequest, 'baseUnitName':$scope.productInfo.baseUnit, 'keywords':$scope.productInfo.keyword, 'productDescription':$scope.productInfo.description, 'companyName':$scope.productInfo.company, 'brand':false, 'skusList':[] } var url = "userbrands"; if(brandsValidation()){ newProfileService.addProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,request,url).then(function(result){ $scope.resetBrands(); if(result.code == "201"){ $scope.profileServiceCallRefresh(); } $scope.cancel(); }) } } if(typeof items !== 'undefined' && items == 'businessmessages'){ $scope.first_tab = true; } $scope.tabs_click = function(tab) { switch(tab){ case 'first_tab': $scope.first_tab = true; $scope.second_tab = false; $scope.third_tab = false; $scope.subCategory = false; $scope.brands.categories = $scope.brands.tempStorage; break; case 'second_tab': $scope.first_tab = false; $scope.third_tab = false; $scope.second_tab = true; break; case 'third_tab': $scope.first_tab = false; $scope.second_tab = false; $scope.third_tab = true; } } $scope.brands={ /*categories:[ {name:'Agriculture',Id:1,openCategory: false,fields:[{name:'Title',description:"hello i am amit sharma presently working in vasudhaika softwre",id:0,isFieldSelected:true,model:''},{name:'Description',description:"hello i am amit sharma presently working in vasudhaika softwre",id:1,isFieldSelected:true,model:''},{name:'Other',description:"hello i am amit sharma presently working in vasudhaika softwre",id:2,isFieldSelected:false}]}, {name:'Auto mobile',Id:2,openCategory: false,fields:[{name:'Title',description:"hello i am amit sharma presently working in vasudhaika softwre",id:0,isFieldSelected:true,model:''},{name:'Description',description:"hello i am amit sharma presently working in vasudhaika softwre",id:1,isFieldSelected:true,model:''},{name:'Other',description:"hello i am amit sharma presently working in vasudhaika softwre",id:2,isFieldSelected:false}]}, {name:'Hospitility',Id:3,openCategory: false,fields:[{name:'Description',description:"hello i am amit sharma presently working in vasudhaika softwre",id:0,isFieldSelected:true,model:''},{name:'Other',description:"hello i am amit sharma presently working in vasudhaika softwre",id:1,isFieldSelected:true,model:''}]}, {name:'Policies',Id:4,openCategory: false,subCategories:[{name:'Hospitility',Id:3,openCategory: false,fields:[{name:'Description',description:"hello i am amit sharma presently working in vasudhaika softwre",id:0,isFieldSelected:true,model:''},{name:'Other',description:"hello i am amit sharma presently working in vasudhaika softwre",id:1,isFieldSelected:true,model:''}]},{name:'Auto mobile',Id:2,openCategory: false,fields:[{name:'Title',description:"hello i am amit sharma presently working in vasudhaika softwre",id:0,isFieldSelected:true,model:''},{name:'Description',description:"hello i am amit sharma presently working in vasudhaika softwre",id:1,isFieldSelected:true,model:''},{name:'Other',description:"hello i am amit sharma presently working in vasudhaika softwre",id:2,isFieldSelected:false}]}]} ],*/ categories :[], openCategoryList:false, fields:[], openSubmitForm:false, selectCategory : '' } $scope.getBrandCategory = function(){ /*newProfileService.getBrandsCategories($rootScope.loggedInUserBusinessProfile.profileKey).then(function(data){ $scope.brands.categories = JSON.parse(data.data); $scope.brands.tempStorage = JSON.parse(data.data); })*/ if( typeof items !== 'undefined' && items.hasOwnProperty('type') && items.type == 'edit'){ if(items.data.brand){ editFilled(); } else{ editProductFilled(); } } } $scope.getBrandCategory(); /*Edit*/ function editFilled(){ $scope.brandsFlag = true; $scope.closeSelectionFlag = false; $scope.brandRequest.mediaURLs = items.data.mediaURLs.imageUrls; $scope.customModel = items.data.mediaURLs.imageUrls; $scope.brandRequest.VideoUrls = items.data.mediaURLs.videourls $scope.otherFields.fields = items.data.otherFields if($scope.otherFields.fields && $scope.otherFields.fields.length != 0){ $scope.showMoreFields = true; } $scope.brandsInfo ={ product:items.data.productList, brand_name:items.data.productName, description:items.data.productDescription, company:items.data.companyName, keyword:items.data.keywords, base_unit:'', productNames:'' } 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(); //$scope.brandRequest.mediaURLs = items.data.mediaURLs; //$scope.otherFields.fields = items.data.otherFields $scope.type = items.type; } function editProductFilled(){ console.log("items.data",items.data); $scope.productsFlag = true; $scope.closeSelectionFlag = false; $scope.brandRequest.mediaURLs = items.data.mediaURLs.imageUrls; $scope.customModel = items.data.mediaURLs.imageUrls; $scope.brandRequest.VideoUrls = items.data.mediaURLs.videourls $scope.otherFields.fields = items.data.otherFields; if($scope.otherFields.fields && $scope.otherFields.fields.length != 0){ $scope.showMoreFields = true; } var mediarequest = { imageUrls:$scope.brandRequest.mediaURLs, videourls:$scope.brandRequest.VideoUrls } $scope.productInfo = { name:items.data.productName, description:items.data.productDescription, company:items.data.companyName, baseUnit:items.data.baseUnitName, keyword:items.data.keywords } $scope.type = items.type; } function extractForEdit(){ for(var i in $scope.brands.fields.fields){ if($scope.brands.fields.fields[i].isFieldSelected && $scope.brands.fields.fields[i].hasOwnProperty('items') && $scope.brands.fields.fields[i].items.length != 0){ for(var z in $scope.brands.fields.fields[i].items){ if($scope.brands.fields.fields[i].items[z].name == $scope.brands.fields.fields[i].model){ $scope.brands.fields.fields[i].model = $scope.brands.fields.fields[i].items[z]; } } } } } $scope.editBrand=function(){ if($scope.brandRequest.brandTitle != ''){ if($scope.otherFields.fields == undefined){ $scope.otherFields.fields = []; } $scope.otherFields.fields[$scope.otherFields.fields.length] = { name: $scope.brandRequest.brandTitle, description : $scope.brandRequest.brandDescription, }; } var mediarequest = { imageUrls:$scope.brandRequest.mediaURLs, videourls:$scope.brandRequest.VideoUrls } var request = { 'data':$scope.brands.fields, 'mediaURLs':mediarequest, 'productList':$scope.brandsInfo.product, 'keywords':$scope.brandsInfo.keyword, 'companyName':$scope.brandsInfo.company, 'productDescription':$scope.brandsInfo.description, 'productName':$scope.brandsInfo.brand_name, 'productId':items.data.productId, 'otherFields':$scope.otherFields.fields, 'brand':true, 'skusList':items.data.skusList } var url = "userbrands"; //exractModelIfObject(); /*var request ={ 'data': $scope.brands.fields, 'mediaURLs':$scope.brandRequest.mediaURLs, 'otherFields':$scope.otherFields.fields, 'brandId':items.data.brandId }*/ if(brandsValidation()){ newProfileService.editProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,request,url).then(function(result){ $scope.edit=false; if(result.code == "201"){ $scope.profileServiceCallRefresh(); } $scope.cancel(); }); } } $scope.editProduct = function(){ if($scope.brandRequest.brandTitle != ''){ if($scope.otherFields.fields == undefined){ $scope.otherFields.fields = []; } $scope.otherFields.fields[$scope.otherFields.fields.length] = { name: $scope.brandRequest.brandTitle, description : $scope.brandRequest.brandDescription, }; } var mediarequest = { imageUrls:$scope.brandRequest.mediaURLs, videourls:$scope.brandRequest.VideoUrls } var request = { 'productName':$scope.productInfo.name, 'mediaURLs':mediarequest, 'baseUnitName':$scope.productInfo.baseUnit, 'keywords':$scope.productInfo.keyword, 'productDescription':$scope.productInfo.description, 'companyName':$scope.productInfo.company, 'productId':items.data.productId, 'otherFields':$scope.otherFields.fields, 'brand':false, 'skusList':items.data.skusList } var url = "userbrands"; newProfileService.editProfileBrand($rootScope.loggedInUserBusinessProfile.profileKey,request,url).then(function(result){ $scope.resetBrands(); if(result.code == "201"){ $scope.profileServiceCallRefresh(); } $scope.cancel(); }) } /*end of edit*/ $scope.getCategoryDescription = function(categories,type){ if(type == 'category'){ categories.openCategory = !categories.openCategory } else{ categories.openFieldDescription = !categories.openFieldDescription } } $scope.openCategoryList = function(data){ if(data.hasOwnProperty('subCategories')){ $scope.subCategory = true; $scope.first_tab = false; for(var index in $scope.brands.categories){ if($scope.brands.categories[index].id == data.id){ $scope.brands.categories = $scope.brands.categories[index].subCategories; //$scope.brands.selectCategory = $scope.brands.categories[index].name; } } } else{ $scope.second_tab = true; $scope.first_tab = false; $scope.subCategory = false; } for(var index in $scope.brands.categories){ if($scope.brands.categories[index].id == data.id){ $scope.brands.fields = $scope.brands.categories[index]; //$scope.brands.selectCategory = $scope.brands.categories[index].name; } } } $scope.fieldScreenActionChange = function(type,field){ switch (type) { case 'previous': $scope.first_tab = true; $scope.second_tab = false; break; case 'next': $scope.third_tab = true; $scope.first_tab = false; $scope.second_tab = false; break; case 'fieldSelect': addField(field); } } function addField(field){ if(field.name == 'Title' || field.name == 'Description' || field.name == 'companyName'){ field.isFieldSelected = true; } else{ field.isFieldSelected = !field.isFieldSelected; } } function othersValidation(){ var othersValidate = true; if($scope.brandRequest.brandTitle == '' || $scope.brandRequest.brandDescription == ''){ othersValidate = false; alert("Please fill title and description properly"); } else{ othersValidate = true; } return othersValidate; } $scope.addOtherField = function(){ if($scope.otherFields.fields == undefined){ $scope.otherFields.fields = []; } if(othersValidation()){ $scope.otherFields.fields[$scope.otherFields.fields.length] = { name: $scope.brandRequest.brandTitle, description : $scope.brandRequest.brandDescription, }; $scope.brandRequest.brandTitle = ''; $scope.brandRequest.brandDescription = ''; } } $scope.editOtherFields = function (index,value) { $scope.otherFields.fields[index] ={ name:value.name, description: value.description } } /*Date Picker Code*/ var today = new Date(); $scope.AvailableDate = new Date(); $scope.ExpireDate = new Date(); $scope.dateFormat = 'dd-MMM-yy'; $scope.availableDateOptions = { formatYear: 'yy', startingDay: 1, minDate: new Date(1995, 5, 22), maxDate: new Date(2030, 5, 22) }; $scope.expireDateOptions = { formatYear: 'yy', startingDay: 1, minDate: today, maxDate: new Date(2030, 5, 22) }; $scope.availableDatePopup = { opened: false }; $scope.expireDatePopup = { opened: 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; //model = $scope.AvailableDate; }; $scope.ChangeDate = function(model) { $scope.AvailableDate = model; }; $scope.OpenExpireDate = function() { $scope.expireDatePopup.opened = !$scope.expireDatePopup.opened; }; /*Date Picker Code End*/ } if(!(window.location.pathname.indexOf('mobile_index')>-1)) mybrandsmodalController.$inject = ["$scope","newProfileService","profileService","$state","$rootScope","$timeout",'$filter','kalgudiLiterals','$uibModal','$uibModalInstance','items']; else mybrandsmodalController.$inject = ["$scope","newProfileService","profileService","$state","$rootScope","$timeout",'$filter','kalgudiLiterals']; angular.module('kalgudiApp.profile').controller('mybrandsmodalController',mybrandsmodalController);