angular.module('kalgudiApp.profile').controller('landGodownVehicleController', ["$scope", "profileService", "$state", "$rootScope", '$filter', 'newProfileService', '$injector', "NgMap", "$timeout", "kalgudiLiterals", function ($scope, profileService, $state, $rootScope, $filter, newProfileService, $injector, NgMap, $timeout, kalgudiLiterals) { //For mobile App only if ((window.location.pathname.indexOf('mobile_index') > -1)) { cordovaLocationServices = $injector.get("cordovaLocationServices"); $ionicPopup = $injector.get("$ionicPopup"); console.log('cordovaLocationServices injected'); } $scope.geoFenceLiterals = kalgudiLiterals; if (!(window.location.pathname.indexOf('mobile_index') > -1)) { $uibModal = $injector.get("$uibModal"); }; $scope.landDetails = { "geoLocation": "", "descriptionForLand": "", "areaOfGeoFence": "", "locationOfGeoFence": "", "geoFencelatlngs": [], "markerGeofence": [], "documents": [], Flag: false, view: false } $scope.godownDetails = { godownName: '', godownType: "", capacity: "", location: {}, specifications: "", precaution: "", geoLocation: "", lat: "", lng: "", location_businessInfo: "", locationDisplayName: "", Flag: false }; $scope.vehicleInfo = { vehicleType: "", companyName: "", modal: "", date: "", registrationNO: "", permitNo: "", insurenceNo: "", engineNO: "", otherDetails: "", Flag: false }; $scope.resetLand = function () { $scope.landDetails.landArea = ""; $scope.landDetails.landRegNumber = ""; $scope.landDetails.landfarmerRegNumber = ""; $scope.landDetails.location = ""; $scope.landDetails.soilType = ""; $scope.landDetails.geoLocation = ""; $scope.landDetails.Flag = false; $scope.landDetails.view = false; $scope.landDetails.geoFencelatlngsArray = []; $scope.landDetails.descriptionForLand = ""; $scope.landDetails.areaOfGeoFence = ""; $scope.landDetails.locationOfGeoFence = ""; $scope.landDetails.geoFencelatlngs = []; $scope.landDetails.markerGeofence = []; $scope.landDetails.documents = []; } $scope.resetGodown = function () { $scope.godownDetails.godownName = ""; $scope.godownDetails.godownType = ""; $scope.godownDetails.capacity = ""; $scope.godownDetails.location = {}; $scope.godownDetails.specifications = ""; $scope.godownDetails.precaution = ""; $scope.godownDetails.location_businessInfo = ""; $scope.godownDetails.whDetailsId = ""; $scope.godownDetails.locationDisplayName = "" $scope.godownDetails.Flag = false; } $scope.resetvehicleInfo = function ($index) { $scope.vehicleInfo.vehicleType = ""; $scope.vehicleInfo.companyName = ""; $scope.vehicleInfo.modal = ""; $scope.vehicleInfo.date = ""; $scope.vehicleInfo.registrationNO = ""; $scope.vehicleInfo.permitNo = ""; $scope.vehicleInfo.insurenceNo = ""; $scope.vehicleInfo.engineNO = ""; $scope.vehicleInfo.otherDetails = ""; $scope.vehicleInfo.actionType = ""; $scope.vehicleInfo.Flag = false } $scope.resetMapDetails = function () { $scope.landDetails.landArea = ""; $scope.landDetails.landRegNumber = ""; $scope.landDetails.landfarmerRegNumber = ""; $scope.landDetails.location = ""; $scope.landDetails.soilType = ""; $scope.landDetails.geoLocation = ""; $scope.landDetails.Flag = false; $scope.landDetails.view = false; $scope.landDetails.geoFencelatlngsArray = []; $scope.landDetails.areaOfGeoFence = ""; $scope.landDetails.locationOfGeoFence = ""; $scope.landDetails.geoFencelatlngs = []; $scope.landDetails.markerGeofence = []; } $scope.locationType = { vehicleInfo: false, landDetails: false, godownDetails: false } $scope.resetTapPoints = function () { $scope.isStart = false; $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_START_FENCE'); if (myinterval) clearInterval(myinterval); } $scope.lat = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.latitude.split('.')[0] + '.' + $rootScope.loggedInUserCurrentBussinessInfo.locationTo.latitude.split('.')[1].substr(0, 6); $scope.lng = $rootScope.loggedInUserCurrentBussinessInfo.locationTo.longitude.split('.')[0] + '.' + $rootScope.loggedInUserCurrentBussinessInfo.locationTo.longitude.split('.')[1].substr(0, 6); $scope.geoFencelatlngs = []; $scope.createLandDetailsOfUser = function () { $rootScope.geoMap = false; if ($scope.documents) { $scope.landDetails.documents = $scope.documents; $scope.documents = []; } newProfileService.addLandDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey, $scope.landDetails).then(function (membershipResult) { $scope.profileServiceCallRefresh(); $scope.resetLand(); $rootScope.$broadcast("brandsupdated", "latlong"); }); } /*limit changes based on function click*/ $scope.limit = 2; $scope.noText = true; $scope.incrementLimit = function () { $scope.limit += 2; //var totalBrandsCount = 0; var totalLandDetailCount = 0; var totalCount = $scope.limit; /*if($scope.loggedInUserCurrentBussinessInfo.hasOwnProperty('listofUserBrands') && $scope.loggedInUserCurrentBussinessInfo.listofUserBrands.length!=0){ totalBrandsCount = $scope.loggedInUserCurrentBussinessInfo.listofUserBrands.length; }*/ if ($scope.loggedInUserCurrentBussinessInfo.hasOwnProperty('lstOfUserLandDetails') && $scope.loggedInUserCurrentBussinessInfo.lstOfUserLandDetails.length != 0) { totalLandDetailCount = $scope.loggedInUserCurrentBussinessInfo.lstOfUserLandDetails.length; } if (totalCount >= totalLandDetailCount) { $scope.noText = false; } for (var landOpen in $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfUserLandDetails) { $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfUserLandDetails[landOpen].showMySKUflag = false; } }; $scope.decreementLimit = function () { $scope.noText = true; $scope.limit = 2; for (var landOpen in $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfUserLandDetails) { $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].lstOfUserLandDetails[landOpen].showMySKUflag = false; } }; /*End limit changes based on function click*/ $scope.editLandDetails = function (landDetails) { $scope.landDetails.landArea = landDetails.landArea; $scope.landDetails.landRegNumber = landDetails.landRegNumber; $scope.landDetails.landfarmerRegNumber = landDetails.landfarmerRegNumber; $scope.landDetails.location = landDetails.location; $scope.landDetails.soilType = landDetails.soilType; $scope.landDetails.Flag = true; } $scope.deleteLandDetailsOfUser = function (landId) { var confirmPopup = $ionicPopup.confirm({ template: 'Are you sure you want to delete ?', title: "Confirm" }); confirmPopup.then(function(res){ if(res == true){ newProfileService.deleteLandDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey, landId).then(function (membershipResult) { $scope.profileServiceCallRefresh(); $scope.resetLand(); }); } }); } $scope.addgodownDetails = function () { var godownList = []; $scope.godownDetails.geoLocation = $scope.landDetails.geoLocation; $scope.godownDetails.lat = $scope.landDetails.lat; $scope.godownDetails.lng = $scope.landDetails.lng; godownList.push($scope.godownDetails); var godownDetailsObj = { "lstofWarehouseDetails": godownList }; if ($scope.godownDetails.locationDisplayName == "") { delete $scope.godownDetails["location"]; } profileService.addgodownDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey, godownDetailsObj).then(function (result) { if (result.code == 201) { $scope.profileServiceCallRefresh(); $scope.resetGodown(); } else { } }); } //documents start $scope.documents = [] $scope.document = { 'title': '', 'description': '', 'images': [], 'attachments': [] }; $scope.enableDocument = function () { $scope.showDoc = !$scope.showDoc; $scope.resetDocument(); } $scope.resetDocument = function () { $scope.document = { 'title': '', 'description': '', 'images': [], 'attachments': [] }; } $scope.addDocument = function () { if($scope.document.title){ $scope.documents.push($scope.document); $scope.enableDocument(); $scope.resetDocument(); }else{ $scope.docTitleEmpty = true; } } $scope.deleteDocument = function (index) { $scope.documents.splice(index, 1); } $scope.uploadImages = function (uploadType) { var tempObj = { uploadType: uploadType } var modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue + 'shared/uploadMultimedia.html', controller: 'uploadMultimediaController', windowClass: 'app-modal-window', size: 'lg', resolve: { items: function () { return tempObj; } } }); modalInstance.result.then(function (uploadedMedia) { $scope.showFloatButtons(); if (uploadedMedia.length) { for (i in uploadedMedia) { if (uploadedMedia[i].msgType == 'IMAGE') { $scope.document.images.push(uploadedMedia[i]); } else if (uploadedMedia[i].msgType == 'DOCUMENT') { $scope.document.attachments.push(uploadedMedia[i]); } } } }); } $scope.showFloatButtons = function () { $scope.showFloatButtonsFlag = !$scope.showFloatButtonsFlag; $scope.addAttachements = false; } $scope.deselectImageAttachment = function (index) { $scope.soilHealthCard.splice(index, 1); } $scope.deselectAttachment = function (index) { $scope.soilHealthCard.splice(index, 1); } //document end $scope.editGodownInfo = function (godown) { $scope.godownDetails.godownName = godown.godownName; $scope.godownDetails.godownType = godown.godownType; $scope.godownDetails.capacity = godown.capacity; $scope.godownDetails.location_businessInfo = godown.location_businessInfo; $scope.godownDetails.location = godown.location; $scope.godownDetails.specifications = godown.specifications; $scope.godownDetails.precaution = godown.precaution; $scope.godownDetails.whDetailsId = godown.whDetailsId; $scope.godownDetails.Flag = true; $scope.landDetails.geoLocation = godown.geoLocation; if (godown.location) $scope.godownDetails.locationDisplayName = godown.location.placeName + ', ' + godown.location.locationShort; else $scope.godownDetails.locationDisplayName = godown.location; } $scope.updateGodownDetails = function () { var godownList = []; $scope.godownDetails.geoLocation = $scope.landDetails.geoLocation; $scope.godownDetails.lat = $scope.landDetails.lat; $scope.godownDetails.lng = $scope.landDetails.lng; godownList.push($scope.godownDetails); var godownDetailsObj = { "lstofWarehouseDetails": godownList }; var warehouseDetailsId = $scope.godownDetails.whDetailsId; delete $scope.godownDetails["whDetailsId"]; profileService.updateGodownDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey, godownDetailsObj, warehouseDetailsId).then(function (result) { if (result.code == 201) { profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey).then(function (result) { $scope.profileServiceCallRefresh(); $scope.resetGodown(); }); //$rootScope.showCommonTopInfoAlert($scope.profileLiterals.searchByKey('KL_PR_0338')); } else { //$rootScope.showCommonTopInfoAlert($scope.profileLiterals.searchByKey('KL_PR_0321')); } }); } $rootScope.geoMap = false; $scope.geoMapopen = function () { $rootScope.geoMap = !$rootScope.geoMap; $rootScope.block_fencedetails = false; } $scope.editvehicleInfo = function (vehicleInfo) { $scope.vehicleInfo.vehicleType = vehicleInfo.vehicleType; $scope.vehicleInfo.companyName = vehicleInfo.companyName; $scope.vehicleInfo.modal = vehicleInfo.modal; $scope.vehicleInfo.date = vehicleInfo.date; $scope.vehicleInfo.registrationNO = vehicleInfo.registrationNO; $scope.vehicleInfo.permitNo = vehicleInfo.permitNo; $scope.vehicleInfo.insurenceNo = vehicleInfo.insurenceNo; $scope.vehicleInfo.engineNO = vehicleInfo.engineNO; $scope.vehicleInfo.otherDetails = vehicleInfo.otherDetails; $scope.vehicleInfo.actionType = "edit"; $scope.vehicleInfo.Flag = true; } $scope.UpdateVehicleinfo = function () { profileService.updatevehicleDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey, $scope.vehicleInfo).then(function (result) { if (result.code == 201) { $scope.profileServiceCallRefresh(); $scope.resetvehicleInfo(); } else { } }); } $scope.addvehicleInfo = function () { $scope.vehicleInfo.actionType = "add"; profileService.updatevehicleDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey, $scope.vehicleInfo).then(function (result) { if (result.code == 201) { $scope.profileServiceCallRefresh(); $scope.resetvehicleInfo(); } else { //$rootScope.showCommonTopInfoAlert($scope.profileLiterals.searchByKey('KL_PR_0321')); } }); } $rootScope.$on('pickerlocationclosed', function (event, data) { $scope.locationType.vehicleInfo = false; $scope.locationType.landDetails = false; $scope.locationType.godownDetails = false; $scope.locationType.godownType = false; }); $scope.lang_godown_vehicleLocationPicker = function (type) { if (type == 'godownDetails') { $scope.locationType.vehicleInfo = false; $scope.locationType.landDetails = false; $scope.locationType.godownDetails = true; $scope.locationType.godownType = false; } if (type == "landDetails") { $scope.locationType.vehicleInfo = false; $scope.locationType.landDetails = true; $scope.locationType.godownDetails = false; $scope.locationType.godownType = false; } if (type == "godownType") { $scope.locationType.vehicleInfo = false; $scope.locationType.landDetails = false; $scope.locationType.godownDetails = false; $scope.locationType.godownType = true; } } if ((window.location.pathname.indexOf('mobile_index') > -1)) { $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_START_FENCE'); $ionicModal = $injector.get("$ionicModal"); $ionicModal.fromTemplateUrl('app/themes/mobile_app/myprofile/templates/view/tapPointsToFence.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.fencemodal = modal; }); $ionicModal.fromTemplateUrl('app/themes/mobile_app/myprofile/templates/view/drawfenceonmap.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.fenceonmapmodal = modal; }); $ionicModal.fromTemplateUrl('app/themes/mobile_app/myprofile/templates/view/landDetailsFullView.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.viewLandDetailsModel = modal; }); $ionicModal.fromTemplateUrl('app/themes/mobile_app/myprofile/templates/view/editlandDetails.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.editLandDetailsModel = modal; }); //navigator.geolocation.getCurrentPosition(onSuccessMap, onErrorMap,optionsmaps); }; $scope.viewLandDetails = function(landDetails){ if(landDetails){ $scope.landDetailsTobeShow = landDetails; $scope.viewLandDetailsModel.show(); }else{ $scope.viewLandDetailsModel.hide(); } } $scope.toggelEditLandModel = function(landDetails){ if(landDetails){ $scope.landDetailsTobeEdit = landDetails; $scope.editLandDetailsModel.show(); }else{ $scope.editLandDetailsModel.hide(); } } $scope.getImgUrl = function(url){ // console.log('url :',url); if(url && url.indexOf('http') > -1){ return url; }else{ return env.secure + url; } } $scope.openNewTab = function(url){ window.open($scope.getImgUrl(url) ,'_blank'); } $scope.centerforpolygon = function () { var center = []; for (var i in $scope.landDetails.geoFencelatlngs) { var center1 = [$scope.landDetails.geoFencelatlngs[i].lat, $scope.landDetails.geoFencelatlngs[i].lng]; center.push(center1); } //$scope.landDetails.drawpolygon=center; return center; } $scope.openFenceModal = function () { $scope.landDetails.geoFencelatlngs = []; $scope.fencemodal.show(); }; $scope.closFenceeModal = function () { if ($scope.landDetails.geoFencelatlngs.length > 2) $scope.landDetails.geoFencelatlngs.push($scope.landDetails.geoFencelatlngs[0]); $scope.fencemodal.hide(); $scope.resetTapPoints(); }; function createpatharray() { var center = []; for (var i in $scope.landDetails.geoFencelatlngs) { var center1 = new google.maps.LatLng($scope.landDetails.geoFencelatlngs[i].lat, $scope.landDetails.geoFencelatlngs[i].lng); center.push(center1); } return center; } function mobilepolygonCenter(poly) { var lowx, highx, lowy, highy, lats = [], lngs = [], vertices = poly for (var i = 0; i < vertices.length; i++) { lngs.push(vertices[i].lng()); lats.push(vertices[i].lat()); } lats.sort(); lngs.sort(); lowx = lats[0]; highx = lats[vertices.length - 1]; lowy = lngs[0]; highy = lngs[vertices.length - 1]; center_x = lowx + ((highx - lowx) / 2); center_y = lowy + ((highy - lowy) / 2); return (new google.maps.LatLng(center_x, center_y)); } $scope.addressNameusingCoordinate = function (latlng) { var geocoder = new google.maps.Geocoder; var latlng = { lat: parseFloat(latlng[0]), lng: parseFloat(latlng[1]) }; geocoder.geocode({ 'location': latlng }, function (results, status) { if (status === 'OK') { if (results[0]) { $scope.landDetails.locationOfGeoFence = results[0].formatted_address; if (results[0].address_components[0] && results[0].address_components[0].long_name == "Unnamed Road") { if ($scope.landDetails.locationOfGeoFence.includes(results[0].address_components[1].long_name)) { $scope.landDetails.locationOfGeoFence = $scope.landDetails.locationOfGeoFence.replace("Unnamed Road,", ""); } else { $scope.landDetails.locationOfGeoFence = $scope.landDetails.locationOfGeoFence.replace("Unnamed Road", results[0].address_components[1].long_name); } } } } }); } $scope.openMapForLand = function(landDetails){ $scope.landDetails = landDetails; $scope.openfenceonmapmodal(landDetails); } $scope.openfenceonmapmodal = function (view) { NgMap.getMap().then(function (map) { var currCenter = map.getCenter(); google.maps.event.trigger(map, 'resize'); map.setCenter(currCenter); }); if (view) { if (view != 'true') $scope.landDetails = Object.assign({}, view); $scope.landDetails.view = true; } else { var ploygonCenter = mobilepolygonCenter(createpatharray()); var area = google.maps.geometry.spherical.computeArea(createpatharray()); $scope.landDetails.areaOfGeoFence = (0.000022957 * area).toFixed(3) + " acres"; $scope.landDetails.markerGeofence = [ploygonCenter.lat(), ploygonCenter.lng()]; $scope.addressNameusingCoordinate($scope.landDetails.markerGeofence); } $scope.zoomLevel = 8; if($scope.landDetails && $scope.landDetails.areaOfGeoFence){ var area = $scope.landDetails.areaOfGeoFence; var areaInNumber = area.substr(0,area.indexOf(' ')); if(areaInNumber < 1){ $scope.zoomLevel = 19; } else if(areaInNumber > 1 && areaInNumber < 100) { $scope.zoomLevel = 16; } else if(areaInNumber > 100 && areaInNumber < 500) { $scope.zoomLevel = 14; } else if(areaInNumber > 500 && areaInNumber < 1000) { $scope.zoomLevel = 12; } else if(areaInNumber > 1000 && areaInNumber < 50000) { $scope.zoomLevel = 10; } else { $scope.zoomLevel = 8; } } $scope.landDetails.geoFencelatlngsArray = $scope.centerforpolygon(); $scope.fenceonmapmodal.show(); }; $scope.closfenceonmapmodal = function () { /*if($scope.landDetails.view){ $scope.resetLand(); }*/ $scope.fenceonmapmodal.hide(); }; $scope.$on('$destroy', function () { if ($scope.landDetails.view) { $scope.resetLand(); } if ((window.location.pathname.indexOf('mobile_index') > -1)) { $scope.fencemodal.remove(); $scope.fenceonmapmodal.remove(); $scope.viewLandDetailsModel.remove(); $scope.editLandDetailsModel.remove(); } $scope.resetTapPoints(); }); var onSuccessMap = function (position) { var geoFencelatlngs = []; var latlng = { "lat": "", "lng": "" } latlng.lat = position.coords.latitude; latlng.lng = position.coords.longitude; //geoFencelatlngs.push(latlng); $scope.landDetails.geoFencelatlngs.push(latlng); $rootScope.spinnerActiveblock = false; }; function onErrorMap(error) { if (error.code == 3) { // $rootScope.showCommonTopInfoAlert("Having problem to fetch your location"); } else { alert(error.message); } } var optionsmaps = { enableHighAccuracy: false, timeout: 3000, maximumAge: 1000 }; $scope.getMyCurrentPosition = function () { $rootScope.spinnerActiveblock = true; navigator.geolocation.getCurrentPosition(onSuccessMap, onErrorMap, optionsmaps); } var myinterval; $scope.isStart = false; $scope.isVerifying = true; $scope.canAccessLocation = true; $scope.startMode = false; $scope.verifyGpsAuthority = function () { $scope.openFenceModal(); if (!cordova || !cordova.plugins || !cordova.plugins.diagnostic || !cordova.plugins.locationAccuracy) { $scope.startMode = true; $scope.canAccessLocation = true; $scope.isVerifying = true; $scope.gpsTurnedOff = true; console.log('cordova.plugins.diagnostic not available'); } else { cordovaLocationServices.isLocationAuthorized().then(function (locationStatus) { $scope.isVerifying = false; $scope.helpText = ''; if (!locationStatus) { $scope.canAccessLocation = false; $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_ACCESS_LOCATION'); } else { $scope.canAccessLocation = true; $scope.checkGpsStatus(); } }); } }; $scope.checkGpsStatus = function () { $scope.isVerifying = true; cordovaLocationServices.isLocationEnabled().then(function (status) { $scope.isVerifying = false; if (status) { $scope.startMode = true; $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_START_FENCE'); $scope.gpsTurnedOff = false; } else { $scope.gpsTurnedOff = true; $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_ENABLE_GPS'); } }); }; $scope.getMyCurrentPositionTime = function () { $scope.isStart = true; $scope.count = 0; $scope.buttonText = "FETCHING"; $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_STOP_FENCE'); $scope.getLocation(); } $scope.allowKagudiToAccessLocation = function () { cordovaLocationServices.requestForAccessLocation().then(function (response) { console.log(response); if (response == 'GRANTED') { $scope.canAccessLocation = true; $scope.checkGpsStatus(); } }); }; $scope.requestForTurnOnGPS = function () { cordovaLocationServices.requestForTurnOnGPS().then(function (response) { if (response) { $scope.startMode = true; $scope.gpsTurnedOff = false; $scope.helpText = $scope.geoFenceLiterals.searchByKey('GEO_START_FENCE'); } }); }; $scope.confirmResetFence = function () { var confirmPopup = $ionicPopup.confirm({ title: $scope.geoFenceLiterals.searchByKey('GEO_CONFIRM_TEXT'), template: $scope.geoFenceLiterals.searchByKey('GEO_CONFIRM_FENCE') }); confirmPopup.then(function (res) { if (res) { $scope.resetMapDetails(); $scope.closfenceonmapmodal(); } }); }; var getText = function () { navigator.geolocation.getCurrentPosition(onSuccessMap, onErrorMap, optionsmaps); if (($scope.count % 2) == 0) { // $scope.buttonText = "Tap to STOP"; $("#multiBtnTxt").text("STOP"); } else { $("#multiBtnTxt").text("FETCHING"); // $scope.buttonText = "FETCHING"; } } $scope.getLocation = function () { $scope.errorCount = 0; $scope.alertIcon = false; navigator.geolocation.getCurrentPosition(successCallback, errorCallback, optionsmaps); function successCallback(position) { $scope.errorCount = 0; console.log('sucess ' + position); myinterval = setInterval(function () { navigator.geolocation.getCurrentPosition(onSuccessMap, onErrorMap, optionsmaps); $scope.count += 1; }, 2000); } function errorCallback(error) { console.log('Error ' + error); $scope.errorCount += 1; if ($scope.errorCount > 3) { $scope.errorCount = 0; $scope.$apply(function () { $scope.resetTapPoints(); }); if (error.code == 3) { $scope.alertIcon = true; $scope.helpText = 'Error fetching your location. Try again.'; } else { $scope.helpText = error.message; } } else { $timeout(function () { navigator.geolocation.getCurrentPosition(successCallback, errorCallback, optionsmaps); }, 400); } }; } $scope.alertIcon = false; $scope.endGeoLocationTime = function () { $scope.isStart = false; console.log('length of latlag Array is ' + $scope.landDetails.geoFencelatlngs.length); if ($scope.landDetails.geoFencelatlngs.length > 2) { $scope.closFenceeModal(); $scope.openfenceonmapmodal(); } else { $scope.alertIcon = true; $scope.helpText = "Error fetching your location. Try again."; } clearInterval(myinterval); } $scope.openGeoFencemodal = function (data, landDetails) { if (landDetails && landDetails.markerGeofence) { $scope.lat = landDetails.markerGeofence[0]; $scope.lng = landDetails.markerGeofence[1]; } var userDetails = { "profileKey": $rootScope.loggedInUserBusinessProfile.profileKey, "businessKey": $rootScope.loggedInUserCurrentBussinessInfo.businessKey } $scope.geoFencelatlngs = []; var geoFenceModalInstance = $uibModal.open({ templateUrl: 'webapp/themes/html/shared/geofence_modal.html', controller: 'geofenceController', size: 'lg', windowClass: 'sized-model', resolve: { latlng: function () { var latlng = { "lat": $scope.lat, "lng": $scope.lng, "draw_view_polygon": data, "landDetailsToshow": landDetails, "userDetails": userDetails } return latlng; } } }); geoFenceModalInstance.result.then(function (selectedItem) { if (!selectedItem.$value.landDetailsForEdit && landDetails) { landDetails.geoFencelatlngs = selectedItem.$value.geoFencelatlngs; landDetails.geoFencelatlngsArray = selectedItem.$value.geoFencelatlngsArray; landDetails.areaOfGeoFence = (0.000247105 * selectedItem.$value.areaOfGeoFence).toFixed(3) + " acres"; landDetails.markerGeofence = selectedItem.$value.markerGeofence; landDetails.locationOfGeoFence = selectedItem.$value.locationOfGeoFence; }else{ $scope.landDetails.geoFencelatlngs = selectedItem.$value.geoFencelatlngs; $scope.landDetails.geoFencelatlngsArray = selectedItem.$value.geoFencelatlngsArray; $scope.landDetails.areaOfGeoFence = (0.000247105 * selectedItem.$value.areaOfGeoFence).toFixed(3) + " acres"; $scope.landDetails.markerGeofence = selectedItem.$value.markerGeofence; $scope.landDetails.locationOfGeoFence = selectedItem.$value.locationOfGeoFence; } }, function (error) { }); }; //Edit landDe $scope.editLandInformation = function(details){ $scope.landDetailsTobeEdit = details; $scope.documents = details.documents; } $scope.submitEditLandDetails = function(details,index){ if(details){ if ($scope.documents) { details.documents = $scope.documents; $scope.documents = []; } $scope.callUpdateLandDetailService(details); } } $scope.callUpdateLandDetailService = function(landDetails){ $rootScope.spinerisActive = true; newProfileService.updateUserLandDetails($rootScope.loggedInUserBusinessProfile.profileKey, $rootScope.loggedInUserCurrentBussinessInfo.businessKey,landDetails).then(function(result) { $rootScope.spinerisActive = false; console.log(result); }); }; $scope.deleteItemByIndex = function(array,index){ array.splice(index, 1); }; $scope.addAttachmentInObject = function(object){ array.splice(index, 1); }; $scope.addAttachmentInArray = function (array) { if($scope.document.title){ array.push($scope.document); $scope.enableDocument(); $scope.resetDocument(); }else{ $scope.docTitleEmpty = true; } } $scope.attachmentsByIndex = function (documents,uploadType) { var tempObj = { uploadType: uploadType } var modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue + 'shared/uploadMultimedia.html', controller: 'uploadMultimediaController', windowClass: 'app-modal-window', size: 'lg', resolve: { items: function () { return tempObj; } } }); modalInstance.result.then(function (uploadedMedia) { $scope.showFloatButtons(); if (uploadedMedia.length) { for (i in uploadedMedia) { if (uploadedMedia[i].msgType == 'IMAGE') { documents.images.push(uploadedMedia[i]); } else if (uploadedMedia[i].msgType == 'DOCUMENT') { documents.attachments.push(uploadedMedia[i]); } } } }); } $scope.hideDoc = function(index){ if(index > -1){ $scope.hideDocIndex = index; }else{ $scope.hideDocIndex = -1; } } $scope.hideLand = function(index){ if(index > -1){ $scope.hideLandIndex = index; }else{ $scope.hideLandIndex = -1; } } /** -----------------------------upload Attachments Starts-----------------*/ if (IS_MOBILE_DEVICE) { $rootScope.$on("uploadedS3URL", function (event, objectS3URL) { if(objectS3URL) { if(objectS3URL.msgType == 'IMAGE'){ $scope.document.images.push(objectS3URL); console.log("Image=="+objectS3URL); } else if(objectS3URL.msgType == 'DOCUMENT') { $scope.document.attachments.push(objectS3URL); console.log("Image=="+objectS3URL); } } }); } /** -----------------------------upload Attachments ends-----------------*/ }]);