angular.module("kalgudiApp.config",["restangular"]) .constant("themeBasePath",'app/themes/mobile_app/') .constant("restBasePath",SERVICES_CONSTRUCTED_URL) .constant("SERVER_IP",SERVER_IP) .config(["RestangularProvider","$httpProvider", function(restangular,$httpProvider) { //initialize get if not there if (!$httpProvider.defaults.headers.get) { $httpProvider.defaults.headers.get = {}; } $httpProvider.interceptors.push(function() { return { 'request': function(config) { var countryId= window.localStorage['countryId']; var username= countryId + window.localStorage['username']; var password= window.localStorage['password']; var appVersion = window.localStorage['APP_VERSION']; config.headers['userName'] = username; config.headers['password'] = password; config.headers['appversion'] = appVersion; return config; } }; }); //disable IE ajax request caching $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; /* to make cros domain ajax calls */ $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; restangular.setBaseUrl(SERVICES_CONSTRUCTED_URL); restangular.setDefaultHeaders({ "Content-Type": "application/json" }); } ]); var kalgudiapp=angular.module("kalgudiApp",["ionic","ngIOS9UIWebViewPatch","ngMap","ngAudio","exceptionOverride","ionic-datepicker","ionic-timepicker","restangular","kalgudiApp.config","kalgudiApp.myconnects","kalgudiApp.mybusiness","kalgudiApp.basicApp","kalgudiApp.agriInput","kalgudiApp.farmer","kalgudiApp.coApp","kalgudiApp.intermediaryApp","kalgudiApp.agencyApp","kalgudiApp.mytransporter","kalgudiApp.mywarehouse","kalgudiApp.myaccounts","kalgudiApp.mycontent", "angularFileUpload","kalgudiApp.profile","kalgudiApp.shareqa","kalgudiApp.groups","kalgudiApp.pages", "kalgudiApp.programs", "monospaced.elastic","kalgudiApp.chat","kalgudiApp.surveys", "kalgudiApp.meetings", "kalgudiApp.eCommerce", "angularRipple",'focus-if','ngFileUpload']) kalgudiapp.config(["$stateProvider","$urlRouterProvider","$ionicConfigProvider","themeBasePath","RestangularProvider","$controllerProvider", "$compileProvider", "$filterProvider", "$provide", function($stateProvider,$urlRouterProvider,$ionicConfigProvider,themeBasePath,restangular,$controllerProvider, $compileProvider, $filterProvider, $provide) { kalgudiapp.controllerProvider = $controllerProvider; kalgudiapp.compileProvider = $compileProvider; kalgudiapp.filterProvider = $filterProvider; kalgudiapp.provide = $provide; kalgudiapp.factory = $provide.factory; kalgudiapp.service = $provide.service; $ionicConfigProvider.views.swipeBackEnabled(false); $ionicConfigProvider.views.transition('none'); // Disable ion view cache $ionicConfigProvider.views.maxCache(0); $stateProvider.state('home', { url: "/home", templateUrl: 'app/core/html/empty.html', data:{ action : "home", moduleAction : "home", currentmodule : "home", title:"COMMON_KALGUDI", module: "content", screenId: "home-page" } }) .state('kalgudi404', { url: '/404Error', templateUrl: themeBasePath+'shared/error.html', data:{ action : "404Error", moduleAction : "404Error", currentmodule : "myprofile" } }) .state('weatherfullview', { url: "/weatherfullview", templateUrl: themeBasePath+'mycontent/weatherfullview.html', data : { action : "weatherfullview", module : "weatherfullview", currentmodule : "weatherfullview", screenId : "weatherfullview", title:"Weather" } }) .state('forexfullview', { url: "/forexfullview", templateUrl: themeBasePath+'mycontent/forexfullview.html', data : { action : "forexfullview", module : "forexfullview", currentmodule : "forexfullview", screenId : "forexfullview", title:"Forex" } }) .state('searchincontent', { url: '/searchincontent', templateUrl: themeBasePath+'shared/searchincontent.html', controller : "searchController", data:{ action : "searchincontent", moduleAction : "searchincontent", currentmodule : "searchincontent" } }) .state('helpandlegal', { url: "/helpandlegal", templateUrl: themeBasePath+'shared/helpandlegal.html', data : { action : "helpandlegal", module : "help&legal", currentmodule : "helpandlegal", screenId : "helpandlegal", /*title:"COMMON_TITLE_ABOUT"*/ } }) .state('mobile_about', { url: "/mobile_about", templateUrl: themeBasePath+'shared/mobile_about.html', data : { action : "mobile_about", module : "mobile_about", currentmodule : "mobile_about", screenId : "mobile_about", title:"" } }) .state('mobile_disclaimer', { url: "/mobile_disclaimer", templateUrl: themeBasePath+'shared/mobile_aboutUs.html', controller : "aboutusController", data : { action : "mobile_disclaimer", module : "mobile_disclaimer", currentmodule : "mobile_disclaimer", screenId : "mobile_disclaimer", title:"COMMON_TITLE_DISCLAIMER" } }) .state('mobile_faq', { url: "/mobile_faq", templateUrl: themeBasePath+'shared/mobile_faq.html', data : { action : "mobile_faq", module : "mobile_faq", currentmodule : "mobile_faq", screenId : "mobile_faq", title:"COMMON_TITLE_FAQ" } }) .state('mobile_contact', { url: "/mobile_contact", templateUrl: themeBasePath+'shared/mobile_contactus.html', data : { action : "mobile_contact", module : "mobile_contact", currentmodule : "mobile_contact", screenId : "mobile_contact", title:"COMMON_TITLE_CONTACT_US" } }) .state('mobile_termsconditions', { url: "/mobile_termsconditions", templateUrl: themeBasePath+'shared/mobile_aboutUs.html', controller : "aboutusController", data : { action : "mobile_termsconditions", module : "mobile_termsconditions", currentmodule : "mobile_termsconditions", screenId : "mobile_termsconditions", title:"" } }) .state('mobile_privacy', { url: "/mobile_privacy", templateUrl: themeBasePath+'shared/mobile_aboutUs.html', controller : "aboutusController", data : { action : "mobile_privacy", module : "mobile_privacy", currentmodule : "mobile_privacy", screenId : "mobile_privacy", title:"" } }) .state('mobile_copyright', { url: "/mobile_copyright", templateUrl: themeBasePath+'shared/mobile_aboutUs.html', controller : "aboutusController", data : { action : "mobile_copyright", module : "mobile_copyright", currentmodule : "mobile_copyright", screenId : "mobile_copyright", title:"COMMON_TITLE_COPYRIGHT" } }) .state('mobile_postrules', { url: "/mobile_postrules", templateUrl: themeBasePath+'shared/mobile_postingrules.html', data : { action : "mobile_postrules", module : "mobile_postrules", currentmodule : "mobile_postrules", screenId : "mobile_postrules", title:"COMMON_TITLE_POSTING_RULE" } }) .state('faq', { url: "/faq", templateUrl: themeBasePath+'shared/faq.html', controller : "helpandlegalController", data : { action : "faq", module : "faq", currentmodule : "faq", screenId : "faq" } }) .state('privacypolicy', { url: "/privacypolicy", templateUrl: themeBasePath+'shared/privacypolicy.html', controller : "helpandlegalController", data : { action : "privacypolicy", module : "privacypolicy", currentmodule : "privacypolicy", screenId : "privacypolicy", title:"COMMON_TITLE_PRIVACY_POLICY" } }) .state('termsandconditions', { url: "/termsandconditions", templateUrl: themeBasePath+'shared/termsandconditions.html', controller : "helpandlegalController", data : { action : "termsandconditions", module : "termsandconditions", currentmodule : "termsandconditions", screenId : "termsandconditions", title:"COMMON_TITLE_TERM_OF_USE" } }) .state('About', { url: "/About", templateUrl: themeBasePath+'shared/About.html', controller : "helpandlegalController", data : { action : "About", module : "About", currentmodule : "About", screenId : "About", title:"COMMON_TITLE_ABOUT" } }) /*.state('Console', { url: "/Console", templateUrl: themeBasePath+'shared/Console.html', data : { action : "Console", module : "Console", currentmodule : "Console", screenId : "Console" } })*/ .state('contactus', { url: "/contactus", templateUrl: themeBasePath+'shared/contactus.html', controller : "helpandlegalController", data : { action : "contactus", module : "contactus", currentmodule : "contactus", screenId : "contactus", title:"COMMON_TITLE_CONTACT_US" } }) .state('Disclaimer', { url: "/Disclaimer", templateUrl: themeBasePath+'shared/Disclaimer.html', controller : "helpandlegalController", data : { action : "Disclaimer", module : "Disclaimer", currentmodule : "Disclaimer", screenId : "Disclaimer", title:"COMMON_TITLE_DISCLAIMER" } }) .state('searchpage', { url: '/searchpage', templateUrl: themeBasePath+'shared/searchpage.html', controller : "searchController", cache:false, data:{ action : "searchpage", moduleAction : "searchpage", currentmodule : "searchpage", screenId : "searchpage", title:"COMMON_TITLE_SEARCH" } }) .state('advanceSearch', { url : '/advanceSearch', templateUrl : themeBasePath+'shared/advance-search.html', cache : false, data : { action : "advance-search-options", moduleAction : "advance-search", currentmodule : "search", screenId : "advance-search-options", title:"Advance search" } }) .state('searchall', { url: '/searchall/:paramkey', templateUrl: themeBasePath+'shared/searchall.html', controller : "searchController", cache:false, data:{ action : "searchall", moduleAction : "searchall", currentmodule : "searchall", screenId : "searchall", title:"COMMON_TITLE_SEARCH" } }) .state('setpin', { url: "/setpin", templateUrl: themeBasePath+'myprofile/setpin.html', controller : "advanceSettingsController", data : { action : "setpin", module : "setpin", currentmodule : "setpin", screenId : "setpin", title:"COMMON_TITLE_SETTINGS" } }) .state('changePassword', { url: "/changePassword", templateUrl: themeBasePath+'myprofile/changePassword.html', controller : "advanceSettingsController", data : { action : "changePassword", module : "changePassword", currentmodule : "changePassword", title:"COMMON_TITLE_CHANGE_PASSWORD" } }) .state('switchLanguage', { url: "/switchLanguage", templateUrl: themeBasePath+'myprofile/languageSwitch.html', controller : "advanceSettingsController", data : { action : "languageSwitch", module : "languageSwitch", currentmodule : "languageSwitch", title:"COMMON_TITLE_LANGUAGE_SWITCH" } }) .state('kalgudiDownloads', { url: "/kalgudiDownloads", templateUrl: themeBasePath+'shared/downloadall.html', cache:false, controller : "downloadsController", data : { action : "kalgudiDownloads", module : "kalgudiDownloads", currentmodule : "kalgudiDownloads", title:"COMMON_TITLE_KALGUDI_DOWNLOADS" } }) .state('share', { url: "/share", templateUrl: themeBasePath+'shared/quickShare.html', cache:false, controller : "shareViaController", data : { action : "quickShare", module : "quickShare", currentmodule : "quickShare", screenId : "quickShare" } }) .state('shareVia', { url: '/shareVia/:shareType/:subject/:link', templateUrl: themeBasePath+'shared/shareVia.html', cache:false, controller : "shareViaController", data : { action : "shareVia", module : "shareVia", currentmodule : "shareVia", screenId : "shareVia" } }) .state('referUs', { url: "/referUs/:id/:token", templateUrl: themeBasePath+'shared/refercontacts.html', cache:false, controller : "referContactsController", data : { action : "refercontacts", module : "refercontacts", currentmodule : "refercontacts", screenId : "refercontacts" } }) .state('referContacts', { url: "/referContacts", templateUrl: themeBasePath+'shared/refercontacts.html', controller : "advanceSettingsController", data : { action : "referContacts", module : "referContacts", currentmodule : "referContacts" } }) /*.state('pendingActions', { url: "/pendingActions/:state", templateUrl: themeBasePath+'shared/pendingActions.html', controller : "pendingActionsController", data : { action : "pendingActions", module : "pendingActions", currentmodule : "pendingActions" } })*/ .state('qaRecommendation', { url: '/qaRecommendation', templateUrl: themeBasePath+'shared/qaRecommendation.html', controller : "qaRecommendationController", data:{ action : "qaRecommendation", currentmodule : "qaRecommendation", module : "qaRecommendation" } }) .state('kalgudiMessages', { url: "/kalgudiMessages", templateUrl: themeBasePath+'shared/kalgudiMessages.html', controller : "kalgudiMessagesController", data : { action : "kalgudiMessages", module : "kalgudiMessages", currentmodule : "kalgudiMessages" } }) .state('alerts', { url: '/alerts', templateUrl: themeBasePath+'shared/alerts.html', controller : "alertsAndOpportunityController", data:{ action : "alertList", currentmodule : "alert", module : "recommendation", title: "HOME_FEED_ALERTS" } }) .state('fullviewsNew', { url: '/fullview/:key', templateUrl: themeBasePath+'dashboard/fullview.html', controller : "alertController", data:{ action : "fullview", currentmodule : "newsFeed", module : "newsFeed" } }) .state('priceUpdateFullView', { // Price recommendation state definition url : '/price-updates/:productId', templateUrl : themeBasePath + 'dashboard/fullViewTemplate/price-update-fullview.html', controller : 'pricesRecommendationController', data : { action : 'fullview', currentmodule : 'priceUpdate', module : 'newsFeed', title : 'PRICE_UPDATES' } }).state('helperText', { url: '/helper', templateUrl: themeBasePath+'dashboard/helper.html', controller : "helperController", data:{ action : "help", currentmodule : "helper", module : "help", title : "HELP_TITLE" } }).state('smsCreditSetting', { url: "/smsCreditSetting", templateUrl: themeBasePath+'myprofile/smsSetting.html', controller : "smsSettingController", data : { action : '', module : 'profile', currentmodule : '', title:'HOME_HEADER_SMS_CREDITS' } }); restangular.setFullRequestInterceptor(function (element, operation, route, url, headers, params) { if (operation == 'remove') { //restangular.setDefaultHeaders({ "Content-Type": "application/json" }); element = params; //headers=''; params=''; } return { headers: headers, params: params, element: element, httpConfig: {} }; }); $urlRouterProvider.otherwise( function($injector, $location) { var $state = $injector.get("$state"); $state.go("home"); }); //$urlRouterProvider.otherwise("/home"); } ]); kalgudiapp.run(["$rootScope","$state","$timeout","$ionicModal","$ionicPopup","$http","$interval","kalgudiLiterals","themeBasePath","profileService","$q","dashboardFactory","setPinFactory","$ionicPopover","commonFactory", 'lazysync', function($rootScope,$state,$timeout,$ionicModal,$ionicPopup,$http,$interval,kalgudiLiterals,themeBasePath,profileService,$q,dashboardFactory,setPinFactory,$ionicPopover,commonFactory, lazysync) { $rootScope.$state = $state; /** * Constant to check dev or production env. */ $rootScope.isDevKalgudi = env.enviorment.includes(ENV_DEV); if(detectmob()){ $rootScope.currentPlatform = "mobile"; } else{ $rootScope.currentPlatform = "Desktop"; } window.localStorage['APP_VERSION'] = APP_VERSION; screen.orientation.lock('portrait').catch(function(error) { // console.log('Screen orientation is failed for this device'); }); //loading all literals data kalgudiLiterals.fetchAllDataFromPropertyFile(LITERALSDATA); $rootScope.loginpinliteral = LITERALSDATA; $rootScope.themebasepathvalue = themeBasePath; $rootScope.globalConfig = globalConfig; $rootScope.bussinessList = []; $rootScope.profileBusinessIncompleteInfo = false; //zoom $rootScope.zoomheight = window.innerHeight + 'px'; if(window.localStorage['userdata']!=undefined) $rootScope.loggedInUserBusinessProfile = JSON.parse(window.localStorage['userdata']); else window.location.href = "mobile_login.html"; $rootScope.s3fileUploadUrl = SERVICE_FACTORY_URLS.S3UPLOAD; $rootScope.s3picUploadUrl = SERVICE_FACTORY_URLS.S3PICUPLOAD; $rootScope.contentBucketRaikKey = "/buckets/crawledContent/keys/"; /*Spiner - for loading symbol*/ $rootScope.spinerisActive = false; /* Alert - info on Search bar */ $rootScope.validationTopErrorAlertFlag = false; $rootScope.commonTopInfoAlertFlag = false; $rootScope.commonTopInfoAlertMessage = ""; //SHOULD REMOVE THIS $rootScope.totalUnreadCounts = {}; $rootScope.inbox_sink_flag = false; $rootScope.windowsflag = false; $rootScope.platformFlag = false; $rootScope.platformMobile = detectmob(); if(platform_Flag!="Desktop"){ if (cordova.platformId == 'windows' || cordova.platformId == 'windows8') { $rootScope.windowsflag = true; }else{ $rootScope.windowsflag = false; } if (cordova.platformId == 'ios') { $rootScope.platformFlag = true; }else{ $rootScope.platformFlag = false; } } if(networkAvaliable()) { $rootScope.networkAvaliable = true; } else { $rootScope.networkAvaliable = false; } if($rootScope.loggedInUserBusinessProfile.hasOwnProperty('lstOfBusinessInfo')){ $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo = $rootScope.loggedInUserBusinessProfile.lstOfBusinessInfo; } if($rootScope.loggedInUserBusinessProfile.hasOwnProperty('lstOfUserBusinessDetailsInfo')){ $rootScope.loggedInUserCurrentBussinessInfo = _.find($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo, function(rw){ return rw.businessUUID == $rootScope.globalConfig.currentBussinessId }); } //loading all dynamic jsfiles $rootScope.load_dynamicJs = function(jsfile) { var deferred = $q.defer(); var dependencies = [ jsfile ]; $script(dependencies, function() { // all dependencies have now been loaded by $script.js so resolve the promise $rootScope.$apply(function() { deferred.resolve(); }); }); return deferred.promise; } //keyboard plugin $rootScope.keyboard = false; window.addEventListener('native.keyboardshow', keyboardShowHandler); function keyboardShowHandler(e){ $timeout(function(){ $rootScope.keyboard = true; },0); } window.addEventListener('native.keyboardhide', keyboardHideHandler); function keyboardHideHandler(e){ $timeout(function(){ $rootScope.keyboard = false; },0); } //Handling logout option in left menu $rootScope.signout = function() { if($rootScope.networkAvaliable){ window.localStorage.removeItem('mobileNumber'); //removedataStorage(); if(platform_Flag!="Desktop"){ var logout_req= { method: 'GET', url: SERVICE_FACTORY_URLS.PROFILE +'mobilelogout', headers: { 'deviceId': registrationId } } var device_deregistration_req = { method : 'GET', url : SERVICE_FACTORY_URLS.PROFILE + "mobileregid?q1=" + PUSH_NOTIFICATION_ID + "&q2=" + cordova.platformId + "&q3=logout", headers : { 'userName' : localStorage['countryId'] + localStorage['username'], 'password' : localStorage['password'] } } console.log(PUSH_NOTIFICATION_ID); $http(logout_req).success(function(resp) { $http(device_deregistration_req).success(function(resp) { window.location.href = "mobile_login.html"; removedataStorage(); }, function(err) { window.location.href = "mobile_login.html"; removedataStorage(); }); }, function(err) { // err.status will contain the status code }); } else{ window.location.href = "mobile_login.html"; removedataStorage(); } } else{ window.plugins.toast.show(' No network ', 'long', 'bottom'); } }; $rootScope.goToState = function(state,params) { if(params!=undefined) $state.go(state,params); else $state.go(state); } /** * Navigates to an angular state with a transition of 300ms, so that * any transition animation can be rendered. */ $rootScope.goToStateTransition = function(state, params) { setTimeout(function() { // Call already defined state navigation function $rootScope.goToState(state, params); }, 300); } $rootScope.enableOffline = function() { $rootScope.$broadcast('enableOffline', true); } /** * Global function to download and open a PDF file. * * @fileUrl Url of file to open. */ $rootScope.downloadAndOpenPDF = function(fileUrl) { if(IS_MOBILE_DEVICE && window.env.buildFor) { // For desktop browser mobile devices window.open(fileUrl,'_blank'); } else if(IS_MOBILE_DEVICE) { // For mobile device $rootScope.spinerisActive = true; // Get filename from file path var fileName = fileUrl.split('/').pop(); showInGallery(fileUrl, fileName, true, function() { // On success $rootScope.spinerisActive = false; }, function() { // On error $rootScope.spinerisActive = false; }); } else { window.open(fileUrl,'_system', 'location=yes'); } } $rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams){ console.log('$stateChangeError - fired when an error occurs during transition.'); console.log(arguments); }); $rootScope.$on('$stateNotFound',function(event, unfoundState, fromState, fromParams){ console.log('$stateNotFound '+unfoundState.name +' - fired when a state cannot be found by its name.'); console.log(unfoundState, fromState, fromParams); }); var tempPassword = window.localStorage['password']; if(tempPassword.length > 29){ $rootScope.logoutFlag = true; }else { $rootScope.logoutFlag = false; } // state change $rootScope.$on('$stateChangeStart', function(event, toState, toParams,fromState,fromParams){ if(!networkAvaliable() && fromState.url!="^")//{ window.plugins.toast.show(' No network ', 'long', 'bottom'); //event.preventDefault(); //event.stopPropagation; /* }else{*/ $rootScope.flip_menu =0; $rootScope.righMenuflaginternal = false; $rootScope.dosomegoodmodule = false; $rootScope.profilemodule = false; $rootScope.isAdminOfThePage = false; $rootScope.contentFullviewHeaderFlag = false; $rootScope.stateName = angular.copy(toState.data.currentmodule); $rootScope.moduleStateName = toState.data.action; $rootScope.moduleName = toState.data && toState.data.module || ''; $rootScope.screenId = toState.data.screenId; $rootScope.searchScreen = toState.name; $rootScope.closebottomPopover(); //$rootScope.slide_index=parseInt(toParams.slideindex); var currentmodulemobile=toState.data.currentmodule; commonFactory.StateName(toState,toParams); if($rootScope.stateName=='home'){ $rootScope.left_RightscreenId=""; } if(currentmodulemobile == "mycontent"){ $rootScope.left_RightscreenId = "Content"; if(toState.name=="mycontent.viewMessage" || toState.name=="mycontent.allContentSearchFullView" || toState.name=="mycontent.sharedMessageFullView" || toState.name=="mycontent.postShareViewMessage"){ $rootScope.currentstatemodule = ""; $rootScope.contentFullviewHeaderFlag = true; } else if(toState.name=="mycontent.viewSharedMessage"){ $rootScope.currentstatemodule = ""; } else{ $rootScope.currentstatemodule = "Content"; } } else if(currentmodulemobile == "myconnects" && toParams.inboxType=="MARKETPLACE"){ $rootScope.currentstatemodule = "Marketplace"; $rootScope.left_RightscreenId = "Marketplace"; } else if(currentmodulemobile == "myconnects" && toParams.inboxType=="CSM"){ $rootScope.currentstatemodule = "network"; $rootScope.left_RightscreenId = "network"; } else if(currentmodulemobile == "mybusiness" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000000")){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "basicApp" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000012" || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000015" || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000016" || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000017" || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000018" || $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId=="BT000019")){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "farmer" && $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000002"){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "coApp" && $rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000010"){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "CA" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000001")){ $rootScope.currentstatemodule = "ca"; $rootScope.left_RightscreenId="ca"; } else if(currentmodulemobile == "basicbroker" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000013")){ $rootScope.currentstatemodule = "basicbroker"; $rootScope.left_RightscreenId="basicbroker"; } else if(currentmodulemobile == "agency" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000014")){ $rootScope.currentstatemodule = "agency"; $rootScope.left_RightscreenId="agency"; } else if(currentmodulemobile == "agriInput" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000008")){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "mywarehouse" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000006")){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "mytransporter" && ($rootScope.loggedInUserCurrentBussinessInfo.businessTypeId == "BT000003")){ $rootScope.currentstatemodule = "transactions"; $rootScope.left_RightscreenId="transactions"; } else if(currentmodulemobile == "myaccounts"){ $rootScope.currentstatemodule = "accounts"; $rootScope.left_RightscreenId="accounts"; } else if(currentmodulemobile == "myprofile"){ $rootScope.currentstatemodule = "Profile"; $rootScope.left_RightscreenId = "Profile"; $rootScope.profilemodule = true; } else if(currentmodulemobile == "ccp"){ $rootScope.currentstatemodule = "Do some good"; $rootScope.left_RightscreenId = "ccp"; $rootScope.dosomegoodmodule = true; } else if(currentmodulemobile == "changePassword") { $rootScope.currentstatemodule = "changePassword"; $rootScope.left_RightscreenId = "changePassword"; } else { $rootScope.currentstatemodule = ""; } $rootScope.fromState=angular.copy(fromState.name); $rootScope.myconnectsPostMessageDataLoseFlag =false; $rootScope.advanceSettingsDataLoseFlag = false; $rootScope.mycontentPostMessageDataLossFlag = false; $rootScope.commentValidationFlag = false; $rootScope.ccpDataLossFlag = false; /*}*/ }); // Success alert $rootScope.showCommonTopInfoAlert = function(messageToBeShown,closeManuallyFlag) { $rootScope.commonTopInfoAlertFlag = true; $rootScope.commonTopInfoAlertMessage = messageToBeShown; if(closeManuallyFlag){ }else{ // Disapper in 5 seconds $timeout(function(){ $rootScope.commonTopInfoAlertFlag = false; $rootScope.commonTopInfoAlertMessage = ""; },10000); } }; $rootScope.commonTopInfoAlertFlagClose = function(){ $rootScope.commonTopInfoAlertFlag = false; }; // Error alert $rootScope.commonTopErrorAlert = function(messageToBeShown,closeManuallyFlag,flagtype) { /*if(flagtype == "informationalert"){ $rootScope.informationalertflag=true; $rootScope.dowloadAlertflag=false; } else { $rootScope.informationalertflag=false; } $rootScope.commonTopErrorAlertFlag = true; $rootScope.commonTopErrorAlertMessage = messageToBeShown; if(closeManuallyFlag){ }else{ // Disapper in 5 seconds $timeout(function(){ $rootScope.commonTopErrorAlertFlag = false; $rootScope.commonTopErrorAlertMessage = ""; },10000); }*/ $rootScope.showAlertBox(messageToBeShown); }; $rootScope.commonTopErrorAlertFlagClose = function(){ $rootScope.commonTopErrorAlertFlag = false; }; $rootScope.handlingBadWord = function(abuseString){ var alertPopup = $ionicPopup.alert({ template :abuseString, cssClass: "", }); alertPopup.then(function(res) { }); }; // To show common alert messages $rootScope.showAlertBox = function(message, title, icon, expires, notify) { icon = icon || 'info_outline'; title = title || 'Info'; expires = expires || 5000; var confirmPopup = $ionicPopup.alert({ title: title, template: '
'+ '' + icon + '
' + '
'+ message + '
' }); confirmPopup.then(function(res) { if(typeof notify == 'function') { notify(res); } }); setTimeout(function() { confirmPopup.close(); if(typeof notify == 'function') { notify(false); } }, expires); } // To close attachements alert $rootScope.dowloadAlertFlagClose = function(){ document.getElementById("downloadFileSuccessAlert").style.display = 'none'; document.getElementById("downloadFileSuccessAlert").classList.remove("fadeInUp"); document.getElementById("downloadFileSuccessAlert").classList.add("fadeOutDown"); } $rootScope.validationTopErrorAlertFlagfun = function(closeManuallyFlag) { $rootScope.validationTopErrorAlertFlag = true; if(closeManuallyFlag){ }else{ // Disapper in 5 seconds $timeout(function(){ $rootScope.validationTopErrorAlertFlag = false; },10000); } }; $rootScope.validationTopErrorAlertFlagClose = function(){ $rootScope.validationTopErrorAlertFlag = false; }; //online and offline window events listeners window.addEventListener("offline", function(e) { $rootScope.networkAvaliable = false; }, false); window.addEventListener("online", function(e) { $rootScope.networkAvaliable = true; }, false); //end // function to enter pin $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue+'shared/resumePINmodal.html', { scope: $rootScope, animation: 'slide-in-up', hardwareBackButtonClose: false }).then(function(pinsetmodal) { $rootScope.pinmodal = pinsetmodal; }); $rootScope.pinopenModal = function() { //After killing the app it is becoming undefined so checking the condition if($rootScope.pinmodal!=undefined){ $rootScope.pinmodal.show(); } else { $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue+'shared/resumePINmodal.html', { scope: $rootScope, animation: 'slide-in-up', hardwareBackButtonClose: false }).then(function(pinsetmodal) { $rootScope.pinmodal = pinsetmodal; $rootScope.pinmodal.show(); }); } }; $rootScope.notification =function() { try { push = PushNotification.init({ "android": {"senderID": "781086678566","sound": "true","vibrate":"true"}, "ios": {}, "windows": {} } ); // push.on('registration', function(data) { // registrationId = data.registrationId; // if ( data.registrationId.length > 0 ) // { // var xmlhttp; // if (window.XMLHttpRequest) // {// code for IE7+, Firefox, Chrome, Opera, Safari // xmlhttp=new XMLHttpRequest(); // } // else // {// code for IE6, IE5 // xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // } // xmlhttp.onreadystatechange=function() // { // if (xmlhttp.readyState==4 && xmlhttp.status==200) // { // } // } // xmlhttp.open("GET",SERVICE_FACTORY_URLS.PROFILE +"mobileregid?q1="+data.registrationId+"&q2="+cordova.platformId,true); // var countryId= window.localStorage['countryId']; // var username= countryId + window.localStorage['username']; // var password= window.localStorage['password']; // xmlhttp.setRequestHeader("userName", username); // xmlhttp.setRequestHeader("password", password); // xmlhttp.send(); // } // }); // if we click on pop-up notification in mobile push.on('notification', function(notification_data) { console.log("notification_data",notification_data); var notifiedmessage=notification_data.message; var foreground = notification_data.additionalData.foreground; $rootScope.PushNotification(); if(!foreground){ if(cordova.platformId == 'android'){ /*if(notification_data.additionalData.hasOwnProperty('locationURL')){ window.location.hash = notification_data.additionalData.locationURL; } */ setTimeout( function() { if(notification_data.additionalData.info == "NETWORK" && notification_data.additionalData.hasOwnProperty('locationURL')){ window.location.hash = notification_data.additionalData.locationURL; } if(notification_data.additionalData.info == "CSM" && notification_data.additionalData.hasOwnProperty('locationURL')) { window.location.hash = notification_data.additionalData.locationURL; } else if(notification_data.additionalData.info == "GROUPS") { window.location.hash = notification_data.additionalData.locationURL; } else if(notification_data.additionalData.info == "SHAREATHOUGHT" && notification_data.additionalData.hasOwnProperty('locationURL')){ window.location.hash = notification_data.additionalData.locationURL; } else if(notification_data.additionalData.info == "BUS" && notification_data.additionalData.hasOwnProperty('locationURL')){ window.location.hash = notification_data.additionalData.locationURL; } else if(notification_data.additionalData.info == "QA" && notification_data.additionalData.hasOwnProperty('locationURL')) { window.location.hash = notification_data.additionalData.locationURL; } else if(notification_data.additionalData.info == "NET") { /*window.location.hash = "#/myconnects/home/MARKETPLACE/321";*/ var profileData = JSON.parse(window.localStorage["userdata"]); switch(profileData.lstOfUserBusinessDetailsInfo[0].businessTypeId){ case "BT000000": window.location.hash = "#/mybusiness/streamInbox"; break; case "BT000001": window.location.hash = "#/CA/streamInbox"; break; case "BT000002": window.location.hash = "#/farmer/streamInbox"; break; case "BT000003": window.location.hash = "#/mytransporter/streamInbox"; break; case "BT000006": window.location.hash = "#/mywarehouse/streamInbox"; break; case "BT000008": window.location.hash = "#/agriInput/streamInbox"; break; case "BT000010": window.location.hash = "#/coApp/streamInbox"; break; default: window.location.hash = "#/basicApp/streamInbox"; } } else if(notification_data.additionalData.info == "APP" && notification_data.additionalData.hasOwnProperty('locationURL')) { window.location.hash = notification_data.additionalData.locationURL; } else if(notification_data.additionalData.info == "ACC") { window.location.hash = "#/myaccounts/home"; } else if(notification_data.additionalData.info == "MSZ") { window.location.hash = "#/mycontent/home"; } }, 500); } else{ var title = notification_data.message.substring(0, 3); if(title == "CSM") { window.location.hash = "#/myconnects/home/CSM/123"; } else if(title == "NET") { window.location.hash = "#/myconnects/home/MARKETPLACE/321"; } else if(title == "APP") { var profileData = JSON.parse(window.localStorage["userdata"]); if(profileData.lstOfBusinessInfo[0].businessTypeId == "BT000001"){ window.location.hash = "#/CA/home"; }else if(profileData.lstOfBusinessInfo[0].businessTypeId == "BT000002"){ window.location.hash = "#/farmer/home"; } else if(profileData.lstOfBusinessInfo[0].businessTypeId == "BT000010"){ window.location.hash = "#/coApp/home"; } else if(profileData.lstOfBusinessInfo[0].businessTypeId == "BT000008"){ window.location.hash = "#/agriInput/home"; } else if(profileData.lstOfBusinessInfo[0].businessTypeId == "BT000003"){ window.location.hash = "#/mytransporter/home"; } else if(profileData.lstOfBusinessInfo[0].businessTypeId == "BT000006"){ window.location.hash = "#/mywarehouse/home"; } else{ window.location.hash = "#/mybusiness/home"; } } else if(title == "ACC") { window.location.hash = "#/myaccounts/home"; } else if(title == "MSZ") { window.location.hash = "#/mycontent/home"; } } } // data.message,data.title, data.count,data.sound,data.image,data.additionalData }); push.on('error', function(e) { // e.message }); } catch(err){ } } $rootScope.notification(); function onResume(){ setPinFactory.pinDetails(); } // To enable advance search for kalgudi users var user = $rootScope.loggedInUserBusinessProfile; $rootScope.isKalgudiMember = !! user.emailId && ( user.emailId.includes('@vasudhaika.net') || user.emailId.includes('@kalgudi.com') || user.emailId.includes('@ai.com') ); //popover right menu $ionicPopover.fromTemplateUrl($rootScope.themebasepathvalue+'shared/popover.html', { scope: $rootScope, }).then(function(popover) { $rootScope.popover = popover; }); $rootScope.openPopover = function($event) { if($rootScope.popover != undefined){ $rootScope.popover.show($event); } }; $rootScope.closePopover = function() { if($rootScope.popover != undefined){ $rootScope.popover.hide(); } }; //sub popover /* $rootScope.opensubpopover = function($event) { $ionicPopover.fromTemplateUrl($rootScope.themebasepathvalue+'shared/opensubpopover.html', { scope: $rootScope, }).then(function(popover) { $rootScope.popover = popover; $rootScope.popover.show($event); }); }; $rootScope.closeSubPopover = function() { if($rootScope.popover != undefined){ $rootScope.popover.hide(); } };*/ //bottom + menu popover initialization $rootScope.searchicon = true; $ionicPopover.fromTemplateUrl($rootScope.themebasepathvalue + 'shared/bottompopover.html', { scope: $rootScope, }).then(function (popover) { $rootScope.bottomPopover = popover; }); //Open bottom + menu popover $rootScope.bottomopenPopover = function ($event) { if ($rootScope.searchicon) { $rootScope.searchicon = false; $rootScope.bottomPopover.show($event); } else { // $state.go("searchpage"); $rootScope.searchicon = true; $rootScope.closebottomPopover(); } }; //Close bottom + menu popover $rootScope.closebottomPopover = function () { // console.log("closeflag"); if ($rootScope.bottomPopover != undefined) { $rootScope.bottomPopover.hide(); $rootScope.searchicon = true; } }; $rootScope.isWebAppFeature = function(){ $rootScope.commonTopErrorAlert($rootScope.loginpinliteral.COMMON_WEBAPP_FEATURE_ERR); } $rootScope.$on('popover.hidden', function() { $rootScope.searchicon = true; }); //In survey threedot menu clear Offline Storage Function clearOfflineStorage() $rootScope.clearOfflineStorage = function(){ // Delete cached survey data for (key in window.localStorage) { if (key.includes('survey')) window.localStorage.removeItem(key); } $rootScope.showAlertBox('Offline surveys cleared', 'Cleared offline surveys', 'done'); } //Killing the app and opening it should show pin if is set if(window.localStorage['pin']!=undefined){ onResume(); } //Coming back to app after sometime should show pin if it is set //document.addEventListener("resume", onResume, false); function onPause(){ $rootScope.pauseWorker(); } //document.addEventListener("pause", onPause, false); //end pin /*-------------------------------------WEBWORKER---------------------------------------*/ serviceObj= { "urls" : { "constructedUrl" : SERVICES_CONSTRUCTED_URL, "moduleUrl" : SERVICE_FACTORY_URLS }, "configData" : { "userName" : window.localStorage['countryId'] + window.localStorage['username'], "password" : window.localStorage['password'] }, "type" : "", "profilekey" : $rootScope.loggedInUserBusinessProfile.profileKey, "businessTypeId" : $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessTypeId, "data":{}, "contacts":{} }; globalLimit=GLOBAL_LIMIT; /*-------------------------------------WEBWORKER---------------------------------------*/ //Check for APK update $rootScope.checkForUpdate = function(type){ if(env.plateForm == 'APK' && device && device.platform === 'Android') { console.log('inside checkForUpdate function'); var url = 'https://s3.amazonaws.com/kalgudi.com/WebsiteJSON/apkDetails.json'; $http.get(url).success(function(data) { if(APK_VERSION != data.apkVersion){ if(navigator && navigator.notification){ navigator.notification.confirm( kalgudiLiterals.searchByKey('APK_UPDATE_MSG'), // message onConfirm, // callback to invoke with index of button pressed kalgudiLiterals.searchByKey('APK_UPDATE_TITLE'), // title [kalgudiLiterals.searchByKey('COMMON_UPDATE'),kalgudiLiterals.searchByKey('NETWORK_CANCEL')] // buttonLabels ); function onConfirm(buttonIndex) { // console.log("Update confirmation " + buttonIndex); if(buttonIndex == 1){ window.open('https://play.google.com/store/apps/details?id=com.vasudhaika.kalgudi','_system'); } } } }else if(type == 'MENUAL'){ if(navigator && navigator.notification){ function alertDismissed() { // Nothing to do } navigator.notification.alert( kalgudiLiterals.searchByKey('APK_UPDATED'), // message alertDismissed, // callback kalgudiLiterals.searchByKey('APK_UPDATE_TITLE'), // title kalgudiLiterals.searchByKey('COMMON_OK') // buttonName ); } } }).error(function(error) { console.log('Error while getting APK details from s3'); }); } } if(env.plateForm == 'APK') $rootScope.checkForUpdate('AUTO'); } ]);