Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var name = 'Name';
- window.angular.module('city.controllers', ['starter.services', 'repository', 'ionic'])
- .controller('CTRL', ['cityLocalStorage', 'tokenLocalStorage', "emailLocalStorage", "$window", "$state", "alert", "$scope", "$http", "Dados", "$rootScope", '$cordovaNetwork', 'cityRepository', 'AccountsSrv', 'md5', "Loading", function (cityLocalStorage, tokenLocalStorage, emailLocalStorage, $window, $state, alert, $scope, $http, Dados, $rootScope, $cordovaNetwork, cityRepository, AccountsSrv, md5, Loading) {
- function setCredentialUser(email) {
- window.credential.userName = email;
- window.credential.password = md5.createHash('egt' + window.credential.userName); // MD5
- window.credential.password = btoa(window.credential.password); // Base64
- window.credential.authorizationBasic = btoa(window.credential.userName + ':' + window.credential.password);
- }
- window.networkOnline = true;
- var isIOS, isAndroid, count = 0;
- isIOS = window.ionic.Platform.isIOS();
- isAndroid = window.ionic.Platform.isAndroid();
- window.networkOnline = true;
- loadCities();
- $rootScope.cityList = [];
- $scope.triggerCall = function (number) {
- document.location.href = 'tel:' + number;
- }
- /*
- * Add listener that receive status network online or offline:
- */
- document.addEventListener("deviceready", function () {
- // Check if network is online open app:
- try {
- window.networkOnline = $cordovaNetwork.isOnline();
- window.logManager.info('Cordova network is online = ' + window.networkOnline);
- loadCities();
- } catch (exception) {
- window.logManager.error(exception.message);
- window.networkOnline = false;
- }
- // Listener for Online event
- $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
- window.networkOnline = true;
- $rootScope.closePopover();
- $rootScope.changeMap();
- fillCitiesComponent();
- $rootScope.enableClickEvents();
- window.logManager.info('Network event online initialized');
- });
- // Listener for Offline event
- $rootScope.$on('$cordovaNetwork:offline', function (event, networkState) {
- $rootScope.closePopover();
- if(!$rootScope.isCityOffline){
- $rootScope.disableClickEvents();
- }
- if (window.networkOnline && alertOpened == 0) {
- alert.networkWarning(function () {
- });
- }
- alertOpened = 0;
- window.networkOnline = false;
- fillCitiesComponent();
- window.logManager.info('Network event offline initialized');
- });
- }, false);
- // Listener for Online event
- $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
- window.networkOnline = true;
- fillCitiesComponent();
- window.logManager.info('Network event online initialized');
- });
- $rootScope.disableClickEvents = function (){
- window.$(".linkgastronomiadetalhes").css("pointer-events","none");
- // window.$(".tab-nav.tabs").css("pointer-events","none");
- }
- $rootScope.enableClickEvents = function (){
- window.$(".linkgastronomiadetalhes").css("pointer-events","auto");
- window.$(".tab-nav.tabs").css("pointer-events","auto");
- }
- function fillCitiesComponent(){
- if ($window.location.hash === '#/')
- loadCities();
- if (window.ionic.Platform.isAndroid() && $window.location.hash !== '#/')
- $scope.clickToggleCidade();
- }
- $scope.clickToggleCidade = function () {
- var cityListTemp, varTemp = 0;
- Loading.show();
- cityRepository.getListAll(function (response) {
- try {
- cityListTemp = response.result;
- cityListTemp.forEach(function (item) {
- if (item.city_id === $rootScope.selecao.city_id) {
- $rootScope.cityList = cityListTemp;
- varTemp = 1;
- Loading.hide();
- }
- });
- if (!varTemp) {
- //window.alert("Esta cidade atualmente não esta em modo offline, conecte-se a rede e reabra o aplicativo");
- //window.ionic.Platform.exitApp();
- Loading.hide();
- }
- } catch (erro) {
- console.log(erro);
- };
- }, function (response) {
- Loading.hide();
- window.logManager.info('Error: ' + JSON.stringify(response));
- });
- };
- function loadCities() {
- Loading.show();
- cityRepository.getListAll(function (response) {
- $rootScope.cityList = response.result;
- Loading.hide();
- }, function (response) {
- Loading.hide();
- window.logManager.info('Error: ' + JSON.stringify(response));
- });
- }
- /*if (cityId) {
- loadCity(cityId);
- }*/
- function loadCity(cityId) {
- Loading.show();
- cityRepository.getCity(cityId, function (response) {
- try {
- Loading.hide();
- Dados = response;
- $rootScope.selecao = Dados;
- $scope.selecao = Dados;
- window.name = response.name;
- window.signal = 1;
- setTimeout(function () {
- $state.go('menu-android.city', {}, { reload: false, cache: false });
- var mapOptions = {
- center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
- scrollwheel: true,
- zoom: 14,
- clickableIcons: false
- };
- if ($rootScope.manageSwitch) {
- var offline = Dados.offline_mode;
- console.log("OFFLINEMODE: " + offline);
- $rootScope.manageSwitch(offline);
- }
- if ($rootScope.loadGallery) {
- $rootScope.loadGallery(cityId);
- }
- if ($rootScope.fly)
- $rootScope.fly(mapOptions);
- }, 200);
- $ionicSideMenuDelegate.toggleLeft();
- $scope.cidade = { city_id: $rootScope.selecao.city_id };
- } catch (exception) {
- Loading.hide();
- window.logManager.error(exception);
- console.log(exception);
- }
- }, function (response) {
- Loading.hide();
- window.logManager.info(JSON.stringify(response));
- });
- }
- $scope.templates = [{ name: 'template-select', url: 'templates/select/_select_menu_inicial.html' }];
- $scope.template_select = $scope.templates[0];
- $scope.mostrarModoOffline = true;
- }])
- .controller('lista-cidade-menu', ["$scope", "$rootScope", "cityRepository", function ($scope, $rootScope, cityRepository) {
- 'use strict';
- $scope.templates = [{ name: 'template-select', url: 'templates/select/_select-cidade-menu.html' }];
- $scope.template_select = $scope.templates[0];
- }])
- .controller('ControllBackPage', ["$scope", "$state", "$rootScope", "$ionicHistory", "$stateParams", function ($scope, $state, $rootScope, $ionicHistory, $stateParams) {
- 'use strict';
- $scope.getURL = function () {
- if ($ionicHistory.currentView().url === "/app-ios/atracoes" || $ionicHistory.currentView().url === "/app-ios/pontos-turisticos" || $ionicHistory.currentView().url === "/app-ios/info/" + $rootScope.selecao.city_id || $ionicHistory.currentView().url === "/app-ios/atracoes" || $ionicHistory.currentView().url === "/app-ios/gastronomia-submenu" || $ionicHistory.currentView().url === "/app-ios/hospedagem-submenu" || $ionicHistory.currentView().url === "/app-ios/purchase-submenu") {
- return true;
- }
- else {
- return false;
- }
- };
- $scope.showIconInfo = function () {
- return ($ionicHistory.currentView().url === "/app-ios/city" || $state.current.name === 'menu-ios.city');
- };
- $scope.showIconCategories = function () {
- return ($ionicHistory.currentView().url !== "/app-ios/city" || $state.current.name !== 'menu-ios.city');
- };
- $scope.showIconSearch = function () {
- if ($ionicHistory.currentView().url === "/app-ios/city" || $state.current.name === 'menu-ios.city' || $state.current.name === 'menu-android.infoUtils') {
- window.$('.hideIcon').css({ "display": 'none' });
- return true;
- } else {
- window.$('.hideIcon').css({ "display": 'block' });
- return false;
- }
- };
- $scope.hideIconSearch = function () {
- if ($ionicHistory.currentView().url !== "/app-ios/city" || $state.current.name !== 'menu-ios.city') {
- window.$('.hideIcon').css({ "display": 'none' });
- return true;
- } else {
- window.$('.hideIcon').css({ "display": 'none' });
- return false;
- }
- };
- $scope.showSubmenu = function () {
- if ($state.current.name === 'menu-ios.gastronomia')
- $state.go('menu-ios.gastronomia-submenu');
- if ($state.current.name === 'menu-ios.hospedagem')
- $state.go('menu-ios.hospedagem-submenu');
- if ($state.current.name === 'menu-ios.compras_presentes')
- $state.go('menu-ios.compra-submenu');
- };
- $scope.back = function () {
- if (($state.current.name === 'menu-ios.hospedagem-submenu' || $state.current.name === 'menu-ios.gastronomia-submenu' || $state.current.name === 'menu-ios.compra-submenu')) {
- $ionicHistory.goBack();
- } else if ($state.current.name === 'menu-ios.city') {
- document.location.href = 'index.html';
- }
- else if ($ionicHistory.backView().stateName === 'menu-ios.hospedagem-submenu' || $ionicHistory.backView().stateName === 'menu-ios.gastronomia-submenu' || $ionicHistory.backView().stateName === 'menu-ios.compra-submenu') {
- $ionicHistory.goBack(-2);
- } else if($state.current.name === "menu-ios.infoUtils"){
- $ionicHistory.goBack(-1);
- return;
- }
- else {
- $state.go('menu-ios.city', {}, {});
- var mapOptions = {
- center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
- scrollwheel: true,
- zoom: 14,
- clickableIcons: false
- };
- setTimeout(function () {
- if ($rootScope.fly)
- $rootScope.fly(mapOptions);
- $rootScope.reloadMap();
- },500);
- }
- };
- }])
- .controller('tabsControl', ["$rootScope", "$state", function ($rootScope, $state) {
- $rootScope.$on('$ionicView.beforeEnter', function () {
- $rootScope.hideTabs = false;
- if ($state.current.name === 'menu-ios.gastronomia-item' || $state.current.name === 'menu-ios.hospedagem-item' || $state.current.name === 'menu-ios.atracoes-item' || $state.current.name === 'menu-ios.compra_item' || $state.current.name === 'menu-ios.pontosTuristicos-item') {
- $rootScope.hideTabs = true;
- }
- });
- }])
- .controller('ControllEventsMenu', ["alert", "$scope", "locale", "$state", "$rootScope", "$ionicHistory", "$element", 'Loading', 'cityRepository','$cordovaNetwork',"$window","$ionicTabsDelegate", function (alert, $scope, locale, $state, $rootScope, $ionicHistory, $element, Loading, cityRepository, $cordovaNetwork, $window,$ionicTabsDelegate) {
- 'use strict';
- $scope.searchBarModel = '';
- $scope.emailFormValidation = function (input) {
- // this.input.user_email. = /^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$/;
- }
- $scope.mapInit = function() {
- console.log("Map loaded");
- me.showMap();
- me.enableMap();
- };
- document.addEventListener("deviceready", function () {
- // Check if network is online open app:
- try {
- window.networkOnline = $cordovaNetwork.isOnline();
- window.logManager.info('Cordova network is online = ' + window.networkOnline);
- } catch (exception) {
- window.logManager.error(exception.message);
- window.networkOnline = true;
- }
- // Listener for Online event
- $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
- window.networkOnline = true;
- google.maps.event.trigger( map, 'resize' );
- if ($window.location.hash === '#/')
- loadCities();
- window.logManager.info('Network event online initialized');
- });
- // Listener for Offline event
- $rootScope.$on('$cordovaNetwork:offline', function (event, networkState) {
- $rootScope.closePopover();
- if (window.networkOnline) {
- alert.networkWarning(function () {
- //window.ionic.Platform.exitApp();
- });
- }
- window.networkOnline = false;
- if ($window.location.hash === '#/')
- loadCities();
- window.logManager.info('Network event offline initialized');
- });
- }, false);
- $scope.clickToggleCidade = function () {
- var cityListTemp = [];
- Loading.show();
- cityRepository.getListAll(function (response) {
- try {
- cityListTemp = response.result;
- if(cityListTemp.length !== 0) {
- cityListTemp.forEach(function (item) {
- if (item.city_id === $rootScope.selecao.city_id) {
- $rootScope.cityList = cityListTemp;
- Loading.hide();
- }
- });
- }else {
- Loading.hide();
- //alert.networkWarning(function () {});
- }
- Loading.hide();
- } catch (erro) {
- console.log(erro);
- };
- }, function (response) {
- Loading.hide();
- window.logManager.info('Error: ' + JSON.stringify(response));
- });
- };
- $scope.showMenuTabsIOS = function () {
- if ($ionicHistory.currentView().url === "/app-ios/gastronomia-item/" + $stateParams.idG)
- return 'ng-hide';
- else return '';
- };
- $scope.showIconShared = function () {
- if ($ionicHistory.currentView().url === "/app/city" || $state.current.name === 'menu-android.city') {
- return true;
- } else {
- return false;
- }
- };
- $scope.showIconSearch = function () {
- if ($state.current.name === 'menu-android.infoUtils') {
- return false;
- }
- if (($ionicHistory.currentView().url !== "/app/city" || $state.current.name !== 'menu-android.city') && ($ionicHistory.currentView().url !== "/app/comment" || $state.current.name !== 'menu-android.comment')) {
- return true;
- } else {
- return false;
- }
- };
- $scope.getQuery = function (event, query) {
- if(window.networkOnline || $rootScope.isCityOffline){
- // if (!$rootScope.isCityOffline || w) {
- var nameState = $ionicHistory.currentStateName();
- window.executeSearch = true;
- $rootScope.$broadcast(nameState + '-updated', {
- query: query
- });
- if (event != undefined && window.cordova) {
- event.preventDefault();
- if(cordova.plugins.Keyboard.isVisible()){
- cordova.plugins.Keyboard.close();
- }
- }
- // } else {
- //$state.go($state.current, {}, { reload: false });
- }else{
- alert.networkWarning(function () {});
- }
- };
- $scope.clearInputSearch = function () {
- window.$('#inputSearch').val('');
- };
- $scope.search = function () {
- cordova.plugins.Keyboard.show();
- window.$('#searchInput').css({
- "display": "block",
- "background": "#0097F6"
- }).animate({ 'left': '10' }, 'fast',function(){
- window.$('#inputSearch').focus();
- });
- };
- $scope.hideSearch = function () {
- if (window.cordova.plugins.Keyboard.isVisible) {
- window.cordova.plugins.Keyboard.close();
- }
- window.$('#searchInput').animate({ 'left': '100%' }, 'fast', function () {
- $(this).hide();
- });
- $("#inputSearch").val('');
- }
- $rootScope.$on('menu-android.hide-search', function (event) {
- $scope.hideSearch();
- })
- $scope.back = function (index, id) {
- if($window.networkOnline || $rootScope.isCityOffline){
- if ($ionicHistory.currentView().url !== "/app/city") {
- if (index === 1) {
- $state.go('menu-ios.gastronomia-item', { idG: id }, { location: 'replace', reload: true });
- } else if (index === 2) {
- } else if (index === 3) {
- } else if (index === 5) {
- } else {
- if(index == 10){
- $ionicHistory.goBack();
- setTimeout( function() {
- $ionicTabsDelegate.$getByHandle('tabInfoIOS').select(1);
- },100);
- }else{
- setTimeout(function () {
- $rootScope.refreshItems();
- $ionicHistory.goBack();
- }, 500);
- }
- }
- } else {
- document.location.href = 'index.html';
- }
- }else{
- alert.networkWarning(function () {});
- }
- };
- }])
- .controller('controllerCity', ["Loading", "$scope", "$rootScope", "$ionicModal", "Dados", "$state", "$ionicSideMenuDelegate", "cityRepository", "alert", 'networkService', 'confirm','$ionicScrollDelegate','$timeout', function (Loading, $scope, $rootScope, $ionicModal, Dados, $state, $ionicSideMenuDelegate, cityRepository, alert, networkService, confirm,$ionicScrollDelegate,$timeout) {
- 'use strict';
- var cityId;
- $ionicScrollDelegate.resize();
- cityId = $scope.selecao.city_id;
- $scope.offlineMode = $scope.selecao.offline_mode;
- $rootScope.isCityOffline = $scope.offlineMode;
- if ($scope.selecao.updateCity && $rootScope.isCityOffline) {
- window.logManager.info('Cidade desatualizada');
- $rootScope.showWarnUpdateCity = true;
- } else {
- $rootScope.showWarnUpdateCity = false;
- }
- $scope.$on("$ionicView.enter", function(event, data){
- $rootScope.reloadMap();
- });
- $scope.getClassDevice = function () {
- var isIOS, isAndroid;
- isIOS = window.ionic.Platform.isIOS();
- isAndroid = window.ionic.Platform.isAndroid();
- if (isIOS) {
- window.$('#mapPosition').removeClass('mapAndroid').addClass('mapiOS');
- window.$('#fontsApp').removeClass('fontsAndroid').addClass('fontsiOS');
- window.$('#selectPosition').removeClass('selectPositionAndroid').addClass('selectPositioniOS');
- window.$('#listCity').removeClass('selectCitysAndroid').addClass('selectCitysiOS');
- window.$('#cityTitle').removeClass('cityTitleAndroid').addClass('cityTitleiOS');
- window.$('#descriptionColor').removeClass('descriptionColorAndroid').addClass('descriptionColoriOS');
- window.$('#offlineArea').removeClass('offlineAreaAndroid').addClass('offlineAreaiOS');
- window.$('#offlineTextMode').removeClass('offlineTextModeAndroid').addClass('offlineTextModeiOS');
- return 'descriptionColoriOS ';
- }
- else {
- window.$('#mapPosition').removeClass('mapiOS').addClass('mapAndroid');
- window.$('#fontsApp').removeClass('fontsiOS').addClass('fontsAndroid');
- window.$('#selectPosition').removeClass('selectPositioniOS').addClass('selectPositionAndroid');
- window.$('#listCity').removeClass('selectCitysiOS').addClass('selectCitysAndroid');
- window.$('#cityTitle').removeClass('cityTitleiOS').addClass('cityTitleAndroid');
- window.$('#descriptionColor').removeClass('descriptionColoriOS').addClass('descriptionColorAndroid');
- window.$('#offlineArea').removeClass('offlineAreaiOS').addClass('offlineAreaAndroid');
- window.$('#offlineTextMode').removeClass('offlineTextModeiOS').addClass('offlineTextModeAndroid');
- return 'descriptionColorAndroid';
- }
- };
- $scope.getName = function () {
- return name;
- };
- $ionicModal.fromTemplateUrl('templates/modal-galeria/_galeria.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $scope.modal = modal;
- });
- $scope.showModal = function (image) {
- $( '#imageWorkaround' ).css( "overflow-x","hidden");
- $( '#imageWorkaround' ).css( "overflow-y","hidden");
- $scope.img = image;
- $scope.modal.show();
- };
- $scope.closeModal = function () {
- $( '#imageWorkaround' ).css( "overflow-x","auto");
- $( '#imageWorkaround' ).css( "overflow-y","hidden");
- $scope.modal.hide();
- };
- $scope.isIOS = function () {
- return window.ionic.Platform.isIOS();
- }
- $rootScope.changeMap = function () {
- if (networkService.isOnline()) {
- $scope.templates = [{ name: 'template-select_map', url: 'templates/mapa/_googleMaps.html' }];
- $scope.template_select_map = $scope.templates[0];
- } else {
- $scope.templates = [{ name: 'template-select_map', url: 'templates/mapa/_offlineMap.html' }];
- $scope.template_select_map = $scope.templates[0];
- }
- }
- $rootScope.changeMap();
- $scope.getIconPlatform = function () {
- if (window.ionic.Platform.isIOS()) return 'ios-small';
- return 'android';
- }
- if ($rootScope.map) {
- $rootScope.reloadMap($rootScope.map, mapOptions);
- }
- if ($rootScope.fly) {
- var mapOptions = {
- center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
- scrollwheel: true,
- zoom: 14
- };
- $rootScope.fly(mapOptions);
- }
- $rootScope.loadGallery = function (cityId) {
- if ((window.ionic.Platform.isIOS() || window.ionic.Platform.isAndroid()) ? !$rootScope.galeriaIOS : !$rootScope.galeria) {
- $scope.isLoadingImages = true;
- $rootScope.galeria = [];
- $rootScope.galeriaIOS = [];
- cityRepository.getImageGallery(cityId, function (response) {
- $scope.isLoadingImages = false;
- if (window.ionic.Platform.isAndroid()) {
- $rootScope.galeria = response.result;
- } else {
- $rootScope.galeriaIOS = response.result;
- $('.image-list').css('width', (response.result.length * 2200) + 'px');
- }
- }, function (response) {
- Loading.hide();
- logManager.error('Error: ' + JSON.stringify(response));
- });
- } else if ((window.ionic.Platform.isIOS() || window.ionic.Platform.isAndroid()) ? !$rootScope.galeriaIOS.length : !$rootScope.galeria.length) {
- $scope.isLoadingImages = true;
- $rootScope.galeria = [];
- $rootScope.galeriaIOS = [];
- cityRepository.getImageGallery(cityId, function (response) {
- $scope.isLoadingImages = false;
- if (window.ionic.Platform.isAndroid()) {
- $rootScope.galeria = response.result;
- } else {
- $rootScope.galeriaIOS = response.result;
- $('.image-list').css('width', (response.result.length * 2200) + 'px');
- }
- }, function (response) {
- Loading.hide();
- });
- } else if (window.ionic.Platform.isIOS()) {
- $('.image-list').css('width', ($rootScope.galeriaIOS.length * 2200) + 'px');
- }
- }
- $rootScope.loadGallery(cityId);
- $scope.resizeScroll = function() {
- $scope.contentView = document.getElementById('conteudo');
- var contentHeight = $scope.contentView.clientHeight + 180;
- $scope.contentView.style.height = contentHeight + 'px';
- $ionicScrollDelegate.resize();
- }
- $scope.getOfflineMode = function () {
- if ($scope.offlineMode && !window.ionic.Platform.isIOS()) {
- return 'changed';
- } else if ($scope.offlineMode && window.ionic.Platform.isIOS()) {
- return 'changed';
- } else {
- return 'notChanged';
- }
- };
- $rootScope.manageSwitch = function (offline) {
- if ($scope.offlineMode != offline) {
- $scope.offlineMode = offline;
- window.$(".lever").toggleClass("changed");
- }
- }
- $scope.setOff = function () {
- // window.alert("haha");
- $scope.offlineMode2 = true;
- };
- $scope.setOfflineMode = function (offlineMode, cityId) {
- if (networkService.isOnline()) {
- if ((!$scope.offlineMode && !offlineMode) || (!$scope.offlineMode && offlineMode)) {
- confirm.offlineModeActive(function () {
- Loading.show();
- cityRepository.setOfflineMode(cityId, !offlineMode, function () {
- Loading.hide();
- alert.offlineModeActiveSucess();
- $scope.getOfflineMode();
- window.$(".lever").toggleClass("changed");
- $rootScope.showWarnUpdateCity = false;
- $scope.offlineMode = true;
- $rootScope.isCityOffline = true;
- }, function () {
- Loading.hide();
- alert.offlineModeActiveError();
- });
- }, function () {
- $scope.offlineMode = false;
- });
- } else if ((offlineMode && $scope.offlineMode) || (!offlineMode && $scope.offlineMode)) {
- confirm.offlineModeDisable(function () {
- Loading.show();
- cityRepository.setOfflineMode(cityId, !offlineMode, function () {
- Loading.hide();
- alert.offlineModeDisableSucess();
- $scope.getOfflineMode();
- $scope.offlineMode = false;
- $rootScope.isCityOffline = false;
- }, function () {
- Loading.hide();
- alert.offlineModeDisableError();
- });
- }, function () {
- $scope.offlineMode = true;
- });
- } else {
- }
- } else {
- Loading.hide();
- alert.offlineModeWithoutConnection();
- }
- };
- $scope.$on('$ionicView.afterEnter', function () {
- $scope.resizeScroll();
- });
- }])
- .controller('menu-ios-controller', ["$scope", "$state", function ($state, $scope) {
- 'use strict';
- $scope.back = function () {
- $state.go('menu-android.city');
- };
- }])
- .controller("CtrlDevice", ["$scope", "$rootScope", "$state", "Dados", "networkService", "$ionicPopover", function ($scope, $rootScope, $state, Dados, networkService, $ionicPopover) {
- 'use strict';
- var isIOS, isAndroid;
- $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
- console.log('Exiting state ' + fromState.name + ' to ' + toState.name);
- if (angular.equals(fromState.name, 'menu-android.comment') || angular.equals(fromState.name, 'menu-android.hospedagemComment')
- || angular.equals(fromState.name, 'menu-android.pontosTuristicosComment') || angular.equals(fromState.name, 'menu-android.compraComment')
- || angular.equals(fromState.name, 'menu-android.atracaoComment'))
- $rootScope.changeTab = true;
- });
- isIOS = window.ionic.Platform.isIOS();
- isAndroid = window.ionic.Platform.isAndroid();
- if (isIOS) {
- window.$('#mapPosition').removeClass('mapAndroid').addClass('mapiOS');
- window.$('#fontsApp').removeClass('fontsAndroid').addClass('fontsiOS');
- window.$('#selectPosition').removeClass('selectPositionAndroid').addClass('selectPositioniOS');
- window.$('#listCity').removeClass('selectCitysAndroid').addClass('selectCitysiOS');
- window.$('#cityTitle').removeClass('cityTitleAndroid').addClass('cityTitleiOS');
- window.$('#descriptionColor').removeClass('descriptionColorAndroid').addClass('descriptionColoriOS');
- window.$('#offlineArea').removeClass('offlineAreaAndroid').addClass('offlineAreaiOS');
- window.$('#offlineTextMode').removeClass('offlineTextModeAndroid').addClass('offlineTextModeiOS');
- } else {
- window.$('#mapPosition').removeClass('mapiOS').addClass('mapAndroid');
- window.$('#fontsApp').removeClass('fontsiOS').addClass('fontsAndroid');
- window.$('#selectPosition').removeClass('selectPositioniOS').addClass('selectPositionAndroid');
- window.$('#listCity').removeClass('selectCitysiOS').addClass('selectCitysAndroid');
- window.$('#cityTitle').removeClass('cityTitleiOS').addClass('cityTitleAndroid');
- window.$('#descriptionColor').removeClass('descriptionColoriOS').addClass('descriptionColorAndroid');
- window.$('#offlineArea').removeClass('offlineAreaiOS').addClass('offlineAreaAndroid');
- window.$('#offlineTextMode').removeClass('offlineTextModeiOS').addClass('offlineTextModeAndroid');
- }
- }])
- .controller('menu-inicio-controller', ["alert","Loading", "$ionicPlatform", "$rootScope", "$scope", "$ionicHistory", "Dados", "$ionicSideMenuDelegate", "$state", "cityRepository", "$ionicPopover", 'options','$cordovaNetwork', function (alert, Loading, $ionicPlatform, $rootScope, $scope, $ionicHistory, Dados, $ionicSideMenuDelegate, $state, cityRepository, $ionicPopover, options,$cordovaNetwork) {
- 'use strict';
- //Aqui está o bug 6165.
- var template = "<ion-popover-view style='height: {{(70 * cityList.length) + 'px'}};'><ion-content><ion-list><ion-item id='itemCityList' ng-click='selectedCityService(city);closePopover()' ng-repeat='city in cityList' >{{city.name}}</ion-item></ion-list></ion-content></ion-popover-view>";
- $scope.popover = $ionicPopover.fromTemplate(template, {
- scope: $scope
- });
- $scope.closePopover = function () {
- $scope.popover.hide();
- }
- $ionicPlatform.registerBackButtonAction(function (event) {
- event.preventDefault();
- event.stopPropagation();
- if ($state.current.name == 'menu-inicio' || $state.current.name == '') {
- window.ionic.Platform.exitApp();
- } else if ($state.current.name === 'menu-android.city') {
- window.ionic.Platform.exitApp();
- } else if ($state.current.name.toLowerCase().indexOf('comment') > -1) {
- $rootScope.refreshItems();
- $ionicHistory.goBack();
- } else if ($state.current.name.indexOf('menu-android.') > -1 && !$state.current.name.indexOf('-item') > -1) {
- $ionicHistory.goBack();
- if($state.current.name === "menu-android.gastronomia" || $state.current.name === "menu-android.hospedagem" || $state.current.name === "menu-android.compras_presentes" || $state.current.name === "menu-android.pontosTuristicos" || $state.current.name === "menu-android.atracoes" || $state.current.name === "menu-android.infoUtils"){
- $state.go("menu-android.city");
- }
- } else if ($state.current.name.indexOf('menu-android.') > -1) {
- $state.go('menu-android.' + $state.current.name.split('.')[1].split('-')[0]);
- } else {
- $ionicHistory.goBack();
- }
- }, 100);
- $scope.openPopover = function ($event) {
- if(window.networkOnline){
- Loading.show();
- cityRepository.getListAll(function (response){
- $rootScope.cityList = response.result;
- Loading.hide();
- });
- }
- if($rootScope.cityList.length != 0){
- $scope.popover.show($event);
- }else{
- alert.networkWarning(function () {});
- }
- };
- $scope.openCitiesMenu = function ($event) {
- Loading.show();
- cityRepository.getListAll(function (response){
- $rootScope.cityList = response.result;
- Loading.hide();
- });
- if($rootScope.cityList.length != 0){
- $scope.popover.show($event);
- }else{
- alert.networkWarning(function () {});
- }
- };
- $rootScope.closePopover = function () {
- $scope.popover.hide();
- };
- //Cleanup the popover when we're done with it!
- $scope.$on('$destroy', function () {
- $scope.popover.remove();
- });
- // Execute action on hide popover
- $scope.$on('popover.hidden', function () {
- // Execute action
- });
- // Execute action on remove popover
- $scope.$on('popover.removed', function () {
- // Execute action
- });
- $scope.cidade = $rootScope.selecao;
- $scope.selectedCityService = function (cidadeSelecionada) {
- var cityId;
- if (cidadeSelecionada !== undefined && cidadeSelecionada !== "undefined" && (window.networkOnline || cidadeSelecionada.offline_mode)) {
- Loading.show();
- cityId = cidadeSelecionada.city_id;
- options.registerCity(cityId);
- cityRepository.getCity(cityId, function (response) {
- try {
- Loading.hide();
- Dados = response;
- $rootScope.selecao = Dados;
- $scope.selecao = Dados;
- window.name = response.name;
- window.signal = 1;
- setTimeout(function () {
- $state.go('menu-android.city', {}, { reload: false, cache: false });
- var mapOptions = {
- center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
- scrollwheel: true,
- zoom: 14,
- clickableIcons: false
- };
- if ($rootScope.manageSwitch) {
- var offline = Dados.offline_mode;
- $rootScope.isCityOffline = offline;
- console.log("OFFLINEMODE: " + offline);
- if(!offline || !cidadeSelecionada.updateCity){
- $rootScope.showWarnUpdateCity = false;
- }else{
- $rootScope.showWarnUpdateCity = true;
- }
- $rootScope.manageSwitch(offline);
- }
- $rootScope.closePopover();
- $rootScope.enableClickEvents();
- if($rootScope.loadGallery){
- $rootScope.loadGallery(cityId);
- }
- if ($rootScope.fly)
- $rootScope.fly(mapOptions);
- $rootScope.reloadMap();
- }, 200);
- $ionicSideMenuDelegate.toggleLeft();
- $scope.cidade = { city_id: $rootScope.selecao.city_id };
- } catch (exception) {
- Loading.hide();
- window.logManager.error(exception);
- console.log(exception);
- }
- }, function (response) {
- Loading.hide();
- window.logManager.info(JSON.stringify(response));
- });
- }else{
- alert.networkWarning(function(){});
- }
- };
- }]);
Add Comment
Please, Sign In to add comment