Guest User

Untitled

a guest
Nov 18th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.06 KB | None | 0 0
  1. var name = 'Name';
  2. window.angular.module('city.controllers', ['starter.services', 'repository', 'ionic'])
  3.  
  4. .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) {
  5.  
  6. function setCredentialUser(email) {
  7. window.credential.userName = email;
  8. window.credential.password = md5.createHash('egt' + window.credential.userName); // MD5
  9. window.credential.password = btoa(window.credential.password); // Base64
  10. window.credential.authorizationBasic = btoa(window.credential.userName + ':' + window.credential.password);
  11. }
  12.  
  13. window.networkOnline = true;
  14.  
  15. var isIOS, isAndroid, count = 0;
  16. isIOS = window.ionic.Platform.isIOS();
  17. isAndroid = window.ionic.Platform.isAndroid();
  18. window.networkOnline = true;
  19. loadCities();
  20. $rootScope.cityList = [];
  21.  
  22. $scope.triggerCall = function (number) {
  23. document.location.href = 'tel:' + number;
  24. }
  25.  
  26. /*
  27. * Add listener that receive status network online or offline:
  28. */
  29. document.addEventListener("deviceready", function () {
  30. // Check if network is online open app:
  31. try {
  32. window.networkOnline = $cordovaNetwork.isOnline();
  33. window.logManager.info('Cordova network is online = ' + window.networkOnline);
  34. loadCities();
  35. } catch (exception) {
  36. window.logManager.error(exception.message);
  37. window.networkOnline = false;
  38. }
  39.  
  40. // Listener for Online event
  41. $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
  42. window.networkOnline = true;
  43.  
  44. $rootScope.closePopover();
  45.  
  46. $rootScope.changeMap();
  47.  
  48. fillCitiesComponent();
  49. $rootScope.enableClickEvents();
  50.  
  51. window.logManager.info('Network event online initialized');
  52. });
  53.  
  54. // Listener for Offline event
  55. $rootScope.$on('$cordovaNetwork:offline', function (event, networkState) {
  56.  
  57.  
  58. $rootScope.closePopover();
  59.  
  60.  
  61. if(!$rootScope.isCityOffline){
  62. $rootScope.disableClickEvents();
  63. }
  64.  
  65. if (window.networkOnline && alertOpened == 0) {
  66. alert.networkWarning(function () {
  67. });
  68. }
  69. alertOpened = 0;
  70. window.networkOnline = false;
  71. fillCitiesComponent();
  72. window.logManager.info('Network event offline initialized');
  73. });
  74. }, false);
  75.  
  76. // Listener for Online event
  77. $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
  78. window.networkOnline = true;
  79.  
  80. fillCitiesComponent();
  81.  
  82. window.logManager.info('Network event online initialized');
  83. });
  84.  
  85. $rootScope.disableClickEvents = function (){
  86. window.$(".linkgastronomiadetalhes").css("pointer-events","none");
  87. // window.$(".tab-nav.tabs").css("pointer-events","none");
  88.  
  89. }
  90.  
  91. $rootScope.enableClickEvents = function (){
  92. window.$(".linkgastronomiadetalhes").css("pointer-events","auto");
  93. window.$(".tab-nav.tabs").css("pointer-events","auto");
  94. }
  95.  
  96. function fillCitiesComponent(){
  97.  
  98. if ($window.location.hash === '#/')
  99. loadCities();
  100.  
  101. if (window.ionic.Platform.isAndroid() && $window.location.hash !== '#/')
  102. $scope.clickToggleCidade();
  103.  
  104. }
  105.  
  106.  
  107. $scope.clickToggleCidade = function () {
  108.  
  109. var cityListTemp, varTemp = 0;
  110. Loading.show();
  111.  
  112. cityRepository.getListAll(function (response) {
  113. try {
  114.  
  115. cityListTemp = response.result;
  116.  
  117. cityListTemp.forEach(function (item) {
  118.  
  119. if (item.city_id === $rootScope.selecao.city_id) {
  120. $rootScope.cityList = cityListTemp;
  121. varTemp = 1;
  122. Loading.hide();
  123. }
  124.  
  125. });
  126. if (!varTemp) {
  127. //window.alert("Esta cidade atualmente não esta em modo offline, conecte-se a rede e reabra o aplicativo");
  128. //window.ionic.Platform.exitApp();
  129. Loading.hide();
  130. }
  131. } catch (erro) {
  132. console.log(erro);
  133. };
  134. }, function (response) {
  135. Loading.hide();
  136. window.logManager.info('Error: ' + JSON.stringify(response));
  137. });
  138. };
  139.  
  140. function loadCities() {
  141.  
  142. Loading.show();
  143. cityRepository.getListAll(function (response) {
  144.  
  145. $rootScope.cityList = response.result;
  146. Loading.hide();
  147. }, function (response) {
  148. Loading.hide();
  149. window.logManager.info('Error: ' + JSON.stringify(response));
  150. });
  151. }
  152.  
  153. /*if (cityId) {
  154. loadCity(cityId);
  155. }*/
  156.  
  157. function loadCity(cityId) {
  158. Loading.show();
  159. cityRepository.getCity(cityId, function (response) {
  160. try {
  161. Loading.hide();
  162. Dados = response;
  163. $rootScope.selecao = Dados;
  164. $scope.selecao = Dados;
  165. window.name = response.name;
  166. window.signal = 1;
  167. setTimeout(function () {
  168. $state.go('menu-android.city', {}, { reload: false, cache: false });
  169. var mapOptions = {
  170. center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
  171. scrollwheel: true,
  172. zoom: 14,
  173. clickableIcons: false
  174. };
  175. if ($rootScope.manageSwitch) {
  176. var offline = Dados.offline_mode;
  177. console.log("OFFLINEMODE: " + offline);
  178.  
  179. $rootScope.manageSwitch(offline);
  180. }
  181.  
  182. if ($rootScope.loadGallery) {
  183. $rootScope.loadGallery(cityId);
  184. }
  185. if ($rootScope.fly)
  186. $rootScope.fly(mapOptions);
  187. }, 200);
  188. $ionicSideMenuDelegate.toggleLeft();
  189. $scope.cidade = { city_id: $rootScope.selecao.city_id };
  190. } catch (exception) {
  191. Loading.hide();
  192. window.logManager.error(exception);
  193. console.log(exception);
  194. }
  195. }, function (response) {
  196. Loading.hide();
  197. window.logManager.info(JSON.stringify(response));
  198. });
  199. }
  200.  
  201. $scope.templates = [{ name: 'template-select', url: 'templates/select/_select_menu_inicial.html' }];
  202. $scope.template_select = $scope.templates[0];
  203. $scope.mostrarModoOffline = true;
  204. }])
  205.  
  206. .controller('lista-cidade-menu', ["$scope", "$rootScope", "cityRepository", function ($scope, $rootScope, cityRepository) {
  207.  
  208. 'use strict';
  209.  
  210. $scope.templates = [{ name: 'template-select', url: 'templates/select/_select-cidade-menu.html' }];
  211. $scope.template_select = $scope.templates[0];
  212. }])
  213.  
  214. .controller('ControllBackPage', ["$scope", "$state", "$rootScope", "$ionicHistory", "$stateParams", function ($scope, $state, $rootScope, $ionicHistory, $stateParams) {
  215. 'use strict';
  216.  
  217.  
  218.  
  219. $scope.getURL = function () {
  220. 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") {
  221. return true;
  222. }
  223. else {
  224. return false;
  225. }
  226. };
  227.  
  228. $scope.showIconInfo = function () {
  229. return ($ionicHistory.currentView().url === "/app-ios/city" || $state.current.name === 'menu-ios.city');
  230. };
  231.  
  232. $scope.showIconCategories = function () {
  233. return ($ionicHistory.currentView().url !== "/app-ios/city" || $state.current.name !== 'menu-ios.city');
  234. };
  235.  
  236. $scope.showIconSearch = function () {
  237. if ($ionicHistory.currentView().url === "/app-ios/city" || $state.current.name === 'menu-ios.city' || $state.current.name === 'menu-android.infoUtils') {
  238. window.$('.hideIcon').css({ "display": 'none' });
  239. return true;
  240. } else {
  241. window.$('.hideIcon').css({ "display": 'block' });
  242. return false;
  243. }
  244. };
  245. $scope.hideIconSearch = function () {
  246. if ($ionicHistory.currentView().url !== "/app-ios/city" || $state.current.name !== 'menu-ios.city') {
  247. window.$('.hideIcon').css({ "display": 'none' });
  248. return true;
  249. } else {
  250. window.$('.hideIcon').css({ "display": 'none' });
  251. return false;
  252. }
  253. };
  254.  
  255.  
  256. $scope.showSubmenu = function () {
  257.  
  258. if ($state.current.name === 'menu-ios.gastronomia')
  259. $state.go('menu-ios.gastronomia-submenu');
  260.  
  261. if ($state.current.name === 'menu-ios.hospedagem')
  262. $state.go('menu-ios.hospedagem-submenu');
  263.  
  264. if ($state.current.name === 'menu-ios.compras_presentes')
  265. $state.go('menu-ios.compra-submenu');
  266.  
  267.  
  268.  
  269. };
  270.  
  271. $scope.back = function () {
  272. if (($state.current.name === 'menu-ios.hospedagem-submenu' || $state.current.name === 'menu-ios.gastronomia-submenu' || $state.current.name === 'menu-ios.compra-submenu')) {
  273.  
  274.  
  275.  
  276. $ionicHistory.goBack();
  277.  
  278. } else if ($state.current.name === 'menu-ios.city') {
  279.  
  280. document.location.href = 'index.html';
  281.  
  282. }
  283. else if ($ionicHistory.backView().stateName === 'menu-ios.hospedagem-submenu' || $ionicHistory.backView().stateName === 'menu-ios.gastronomia-submenu' || $ionicHistory.backView().stateName === 'menu-ios.compra-submenu') {
  284. $ionicHistory.goBack(-2);
  285. } else if($state.current.name === "menu-ios.infoUtils"){
  286. $ionicHistory.goBack(-1);
  287. return;
  288. }
  289. else {
  290.  
  291. $state.go('menu-ios.city', {}, {});
  292.  
  293. var mapOptions = {
  294. center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
  295. scrollwheel: true,
  296. zoom: 14,
  297. clickableIcons: false
  298. };
  299.  
  300. setTimeout(function () {
  301. if ($rootScope.fly)
  302. $rootScope.fly(mapOptions);
  303. $rootScope.reloadMap();
  304. },500);
  305.  
  306. }
  307. };
  308. }])
  309.  
  310. .controller('tabsControl', ["$rootScope", "$state", function ($rootScope, $state) {
  311.  
  312. $rootScope.$on('$ionicView.beforeEnter', function () {
  313.  
  314. $rootScope.hideTabs = false;
  315.  
  316. 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') {
  317. $rootScope.hideTabs = true;
  318. }
  319. });
  320. }])
  321.  
  322. .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) {
  323.  
  324. 'use strict';
  325.  
  326. $scope.searchBarModel = '';
  327.  
  328. $scope.emailFormValidation = function (input) {
  329. // this.input.user_email. = /^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$/;
  330. }
  331.  
  332. $scope.mapInit = function() {
  333. console.log("Map loaded");
  334. me.showMap();
  335. me.enableMap();
  336. };
  337.  
  338. document.addEventListener("deviceready", function () {
  339.  
  340. // Check if network is online open app:
  341. try {
  342. window.networkOnline = $cordovaNetwork.isOnline();
  343. window.logManager.info('Cordova network is online = ' + window.networkOnline);
  344. } catch (exception) {
  345. window.logManager.error(exception.message);
  346. window.networkOnline = true;
  347. }
  348.  
  349. // Listener for Online event
  350. $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
  351. window.networkOnline = true;
  352.  
  353. google.maps.event.trigger( map, 'resize' );
  354.  
  355. if ($window.location.hash === '#/')
  356. loadCities();
  357.  
  358. window.logManager.info('Network event online initialized');
  359.  
  360. });
  361.  
  362.  
  363.  
  364.  
  365. // Listener for Offline event
  366. $rootScope.$on('$cordovaNetwork:offline', function (event, networkState) {
  367.  
  368. $rootScope.closePopover();
  369. if (window.networkOnline) {
  370. alert.networkWarning(function () {
  371. //window.ionic.Platform.exitApp();
  372. });
  373. }
  374.  
  375. window.networkOnline = false;
  376.  
  377.  
  378. if ($window.location.hash === '#/')
  379. loadCities();
  380.  
  381. window.logManager.info('Network event offline initialized');
  382. });
  383.  
  384. }, false);
  385.  
  386. $scope.clickToggleCidade = function () {
  387.  
  388. var cityListTemp = [];
  389. Loading.show();
  390.  
  391. cityRepository.getListAll(function (response) {
  392. try {
  393.  
  394. cityListTemp = response.result;
  395. if(cityListTemp.length !== 0) {
  396. cityListTemp.forEach(function (item) {
  397.  
  398. if (item.city_id === $rootScope.selecao.city_id) {
  399. $rootScope.cityList = cityListTemp;
  400.  
  401. Loading.hide();
  402. }
  403.  
  404. });
  405. }else {
  406. Loading.hide();
  407. //alert.networkWarning(function () {});
  408. }
  409. Loading.hide();
  410.  
  411.  
  412. } catch (erro) {
  413. console.log(erro);
  414. };
  415. }, function (response) {
  416. Loading.hide();
  417. window.logManager.info('Error: ' + JSON.stringify(response));
  418. });
  419. };
  420.  
  421. $scope.showMenuTabsIOS = function () {
  422. if ($ionicHistory.currentView().url === "/app-ios/gastronomia-item/" + $stateParams.idG)
  423. return 'ng-hide';
  424. else return '';
  425.  
  426. };
  427.  
  428. $scope.showIconShared = function () {
  429. if ($ionicHistory.currentView().url === "/app/city" || $state.current.name === 'menu-android.city') {
  430. return true;
  431. } else {
  432. return false;
  433. }
  434. };
  435.  
  436. $scope.showIconSearch = function () {
  437.  
  438. if ($state.current.name === 'menu-android.infoUtils') {
  439. return false;
  440. }
  441.  
  442. if (($ionicHistory.currentView().url !== "/app/city" || $state.current.name !== 'menu-android.city') && ($ionicHistory.currentView().url !== "/app/comment" || $state.current.name !== 'menu-android.comment')) {
  443. return true;
  444. } else {
  445. return false;
  446. }
  447. };
  448.  
  449.  
  450. $scope.getQuery = function (event, query) {
  451.  
  452. if(window.networkOnline || $rootScope.isCityOffline){
  453.  
  454. // if (!$rootScope.isCityOffline || w) {
  455. var nameState = $ionicHistory.currentStateName();
  456.  
  457. window.executeSearch = true;
  458. $rootScope.$broadcast(nameState + '-updated', {
  459. query: query
  460. });
  461.  
  462.  
  463. if (event != undefined && window.cordova) {
  464. event.preventDefault();
  465. if(cordova.plugins.Keyboard.isVisible()){
  466. cordova.plugins.Keyboard.close();
  467. }
  468. }
  469. // } else {
  470. //$state.go($state.current, {}, { reload: false });
  471.  
  472. }else{
  473. alert.networkWarning(function () {});
  474. }
  475.  
  476.  
  477. };
  478.  
  479. $scope.clearInputSearch = function () {
  480. window.$('#inputSearch').val('');
  481.  
  482. };
  483.  
  484. $scope.search = function () {
  485. cordova.plugins.Keyboard.show();
  486.  
  487. window.$('#searchInput').css({
  488. "display": "block",
  489. "background": "#0097F6"
  490. }).animate({ 'left': '10' }, 'fast',function(){
  491. window.$('#inputSearch').focus();
  492.  
  493. });
  494. };
  495.  
  496. $scope.hideSearch = function () {
  497. if (window.cordova.plugins.Keyboard.isVisible) {
  498. window.cordova.plugins.Keyboard.close();
  499. }
  500. window.$('#searchInput').animate({ 'left': '100%' }, 'fast', function () {
  501. $(this).hide();
  502. });
  503. $("#inputSearch").val('');
  504. }
  505.  
  506. $rootScope.$on('menu-android.hide-search', function (event) {
  507. $scope.hideSearch();
  508. })
  509.  
  510. $scope.back = function (index, id) {
  511.  
  512. if($window.networkOnline || $rootScope.isCityOffline){
  513.  
  514. if ($ionicHistory.currentView().url !== "/app/city") {
  515. if (index === 1) {
  516.  
  517. $state.go('menu-ios.gastronomia-item', { idG: id }, { location: 'replace', reload: true });
  518. } else if (index === 2) {
  519.  
  520. } else if (index === 3) {
  521.  
  522. } else if (index === 5) {
  523.  
  524. } else {
  525. if(index == 10){
  526. $ionicHistory.goBack();
  527. setTimeout( function() {
  528. $ionicTabsDelegate.$getByHandle('tabInfoIOS').select(1);
  529.  
  530. },100);
  531. }else{
  532. setTimeout(function () {
  533. $rootScope.refreshItems();
  534. $ionicHistory.goBack();
  535.  
  536. }, 500);
  537. }
  538.  
  539. }
  540. } else {
  541. document.location.href = 'index.html';
  542. }
  543. }else{
  544. alert.networkWarning(function () {});
  545.  
  546. }
  547.  
  548. };
  549.  
  550. }])
  551.  
  552. .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) {
  553.  
  554. 'use strict';
  555.  
  556. var cityId;
  557.  
  558. $ionicScrollDelegate.resize();
  559.  
  560.  
  561. cityId = $scope.selecao.city_id;
  562. $scope.offlineMode = $scope.selecao.offline_mode;
  563. $rootScope.isCityOffline = $scope.offlineMode;
  564.  
  565. if ($scope.selecao.updateCity && $rootScope.isCityOffline) {
  566. window.logManager.info('Cidade desatualizada');
  567. $rootScope.showWarnUpdateCity = true;
  568. } else {
  569. $rootScope.showWarnUpdateCity = false;
  570. }
  571.  
  572. $scope.$on("$ionicView.enter", function(event, data){
  573. $rootScope.reloadMap();
  574. });
  575.  
  576. $scope.getClassDevice = function () {
  577.  
  578. var isIOS, isAndroid;
  579.  
  580. isIOS = window.ionic.Platform.isIOS();
  581. isAndroid = window.ionic.Platform.isAndroid();
  582.  
  583. if (isIOS) {
  584. window.$('#mapPosition').removeClass('mapAndroid').addClass('mapiOS');
  585. window.$('#fontsApp').removeClass('fontsAndroid').addClass('fontsiOS');
  586. window.$('#selectPosition').removeClass('selectPositionAndroid').addClass('selectPositioniOS');
  587. window.$('#listCity').removeClass('selectCitysAndroid').addClass('selectCitysiOS');
  588. window.$('#cityTitle').removeClass('cityTitleAndroid').addClass('cityTitleiOS');
  589. window.$('#descriptionColor').removeClass('descriptionColorAndroid').addClass('descriptionColoriOS');
  590. window.$('#offlineArea').removeClass('offlineAreaAndroid').addClass('offlineAreaiOS');
  591. window.$('#offlineTextMode').removeClass('offlineTextModeAndroid').addClass('offlineTextModeiOS');
  592. return 'descriptionColoriOS ';
  593.  
  594. }
  595. else {
  596. window.$('#mapPosition').removeClass('mapiOS').addClass('mapAndroid');
  597. window.$('#fontsApp').removeClass('fontsiOS').addClass('fontsAndroid');
  598. window.$('#selectPosition').removeClass('selectPositioniOS').addClass('selectPositionAndroid');
  599. window.$('#listCity').removeClass('selectCitysiOS').addClass('selectCitysAndroid');
  600. window.$('#cityTitle').removeClass('cityTitleiOS').addClass('cityTitleAndroid');
  601. window.$('#descriptionColor').removeClass('descriptionColoriOS').addClass('descriptionColorAndroid');
  602. window.$('#offlineArea').removeClass('offlineAreaiOS').addClass('offlineAreaAndroid');
  603. window.$('#offlineTextMode').removeClass('offlineTextModeiOS').addClass('offlineTextModeAndroid');
  604.  
  605. return 'descriptionColorAndroid';
  606. }
  607. };
  608.  
  609. $scope.getName = function () {
  610. return name;
  611. };
  612.  
  613. $ionicModal.fromTemplateUrl('templates/modal-galeria/_galeria.html', {
  614. scope: $scope,
  615. animation: 'slide-in-up'
  616. }).then(function (modal) {
  617. $scope.modal = modal;
  618. });
  619.  
  620. $scope.showModal = function (image) {
  621. $( '#imageWorkaround' ).css( "overflow-x","hidden");
  622. $( '#imageWorkaround' ).css( "overflow-y","hidden");
  623. $scope.img = image;
  624. $scope.modal.show();
  625. };
  626.  
  627. $scope.closeModal = function () {
  628. $( '#imageWorkaround' ).css( "overflow-x","auto");
  629. $( '#imageWorkaround' ).css( "overflow-y","hidden");
  630. $scope.modal.hide();
  631. };
  632.  
  633. $scope.isIOS = function () {
  634. return window.ionic.Platform.isIOS();
  635. }
  636.  
  637. $rootScope.changeMap = function () {
  638. if (networkService.isOnline()) {
  639.  
  640. $scope.templates = [{ name: 'template-select_map', url: 'templates/mapa/_googleMaps.html' }];
  641. $scope.template_select_map = $scope.templates[0];
  642. } else {
  643. $scope.templates = [{ name: 'template-select_map', url: 'templates/mapa/_offlineMap.html' }];
  644. $scope.template_select_map = $scope.templates[0];
  645. }
  646. }
  647.  
  648. $rootScope.changeMap();
  649.  
  650. $scope.getIconPlatform = function () {
  651. if (window.ionic.Platform.isIOS()) return 'ios-small';
  652. return 'android';
  653. }
  654.  
  655.  
  656. if ($rootScope.map) {
  657. $rootScope.reloadMap($rootScope.map, mapOptions);
  658. }
  659.  
  660.  
  661. if ($rootScope.fly) {
  662. var mapOptions = {
  663. center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
  664. scrollwheel: true,
  665. zoom: 14
  666. };
  667. $rootScope.fly(mapOptions);
  668. }
  669.  
  670. $rootScope.loadGallery = function (cityId) {
  671.  
  672. if ((window.ionic.Platform.isIOS() || window.ionic.Platform.isAndroid()) ? !$rootScope.galeriaIOS : !$rootScope.galeria) {
  673. $scope.isLoadingImages = true;
  674.  
  675. $rootScope.galeria = [];
  676. $rootScope.galeriaIOS = [];
  677. cityRepository.getImageGallery(cityId, function (response) {
  678.  
  679. $scope.isLoadingImages = false;
  680. if (window.ionic.Platform.isAndroid()) {
  681. $rootScope.galeria = response.result;
  682. } else {
  683.  
  684. $rootScope.galeriaIOS = response.result;
  685. $('.image-list').css('width', (response.result.length * 2200) + 'px');
  686. }
  687.  
  688. }, function (response) {
  689. Loading.hide();
  690. logManager.error('Error: ' + JSON.stringify(response));
  691. });
  692.  
  693. } else if ((window.ionic.Platform.isIOS() || window.ionic.Platform.isAndroid()) ? !$rootScope.galeriaIOS.length : !$rootScope.galeria.length) {
  694. $scope.isLoadingImages = true;
  695. $rootScope.galeria = [];
  696. $rootScope.galeriaIOS = [];
  697.  
  698. cityRepository.getImageGallery(cityId, function (response) {
  699.  
  700. $scope.isLoadingImages = false;
  701. if (window.ionic.Platform.isAndroid()) {
  702.  
  703. $rootScope.galeria = response.result;
  704. } else {
  705.  
  706. $rootScope.galeriaIOS = response.result;
  707. $('.image-list').css('width', (response.result.length * 2200) + 'px');
  708. }
  709.  
  710. }, function (response) {
  711. Loading.hide();
  712. });
  713.  
  714. } else if (window.ionic.Platform.isIOS()) {
  715. $('.image-list').css('width', ($rootScope.galeriaIOS.length * 2200) + 'px');
  716. }
  717. }
  718.  
  719. $rootScope.loadGallery(cityId);
  720.  
  721. $scope.resizeScroll = function() {
  722. $scope.contentView = document.getElementById('conteudo');
  723. var contentHeight = $scope.contentView.clientHeight + 180;
  724. $scope.contentView.style.height = contentHeight + 'px';
  725. $ionicScrollDelegate.resize();
  726. }
  727.  
  728. $scope.getOfflineMode = function () {
  729. if ($scope.offlineMode && !window.ionic.Platform.isIOS()) {
  730. return 'changed';
  731.  
  732. } else if ($scope.offlineMode && window.ionic.Platform.isIOS()) {
  733. return 'changed';
  734. } else {
  735. return 'notChanged';
  736. }
  737.  
  738. };
  739.  
  740. $rootScope.manageSwitch = function (offline) {
  741. if ($scope.offlineMode != offline) {
  742. $scope.offlineMode = offline;
  743.  
  744. window.$(".lever").toggleClass("changed");
  745. }
  746. }
  747.  
  748. $scope.setOff = function () {
  749. // window.alert("haha");
  750.  
  751. $scope.offlineMode2 = true;
  752. };
  753. $scope.setOfflineMode = function (offlineMode, cityId) {
  754.  
  755. if (networkService.isOnline()) {
  756.  
  757. if ((!$scope.offlineMode && !offlineMode) || (!$scope.offlineMode && offlineMode)) {
  758. confirm.offlineModeActive(function () {
  759. Loading.show();
  760. cityRepository.setOfflineMode(cityId, !offlineMode, function () {
  761. Loading.hide();
  762. alert.offlineModeActiveSucess();
  763. $scope.getOfflineMode();
  764. window.$(".lever").toggleClass("changed");
  765. $rootScope.showWarnUpdateCity = false;
  766. $scope.offlineMode = true;
  767. $rootScope.isCityOffline = true;
  768.  
  769. }, function () {
  770. Loading.hide();
  771. alert.offlineModeActiveError();
  772. });
  773. }, function () {
  774. $scope.offlineMode = false;
  775. });
  776. } else if ((offlineMode && $scope.offlineMode) || (!offlineMode && $scope.offlineMode)) {
  777. confirm.offlineModeDisable(function () {
  778. Loading.show();
  779. cityRepository.setOfflineMode(cityId, !offlineMode, function () {
  780. Loading.hide();
  781. alert.offlineModeDisableSucess();
  782. $scope.getOfflineMode();
  783. $scope.offlineMode = false;
  784. $rootScope.isCityOffline = false;
  785. }, function () {
  786. Loading.hide();
  787. alert.offlineModeDisableError();
  788. });
  789.  
  790. }, function () {
  791. $scope.offlineMode = true;
  792. });
  793. } else {
  794.  
  795. }
  796. } else {
  797.  
  798. Loading.hide();
  799. alert.offlineModeWithoutConnection();
  800. }
  801. };
  802. $scope.$on('$ionicView.afterEnter', function () {
  803. $scope.resizeScroll();
  804. });
  805.  
  806.  
  807. }])
  808.  
  809. .controller('menu-ios-controller', ["$scope", "$state", function ($state, $scope) {
  810. 'use strict';
  811. $scope.back = function () {
  812. $state.go('menu-android.city');
  813. };
  814. }])
  815.  
  816. .controller("CtrlDevice", ["$scope", "$rootScope", "$state", "Dados", "networkService", "$ionicPopover", function ($scope, $rootScope, $state, Dados, networkService, $ionicPopover) {
  817.  
  818. 'use strict';
  819.  
  820. var isIOS, isAndroid;
  821.  
  822. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  823. console.log('Exiting state ' + fromState.name + ' to ' + toState.name);
  824. if (angular.equals(fromState.name, 'menu-android.comment') || angular.equals(fromState.name, 'menu-android.hospedagemComment')
  825. || angular.equals(fromState.name, 'menu-android.pontosTuristicosComment') || angular.equals(fromState.name, 'menu-android.compraComment')
  826. || angular.equals(fromState.name, 'menu-android.atracaoComment'))
  827. $rootScope.changeTab = true;
  828. });
  829.  
  830.  
  831. isIOS = window.ionic.Platform.isIOS();
  832. isAndroid = window.ionic.Platform.isAndroid();
  833. if (isIOS) {
  834. window.$('#mapPosition').removeClass('mapAndroid').addClass('mapiOS');
  835. window.$('#fontsApp').removeClass('fontsAndroid').addClass('fontsiOS');
  836. window.$('#selectPosition').removeClass('selectPositionAndroid').addClass('selectPositioniOS');
  837. window.$('#listCity').removeClass('selectCitysAndroid').addClass('selectCitysiOS');
  838. window.$('#cityTitle').removeClass('cityTitleAndroid').addClass('cityTitleiOS');
  839. window.$('#descriptionColor').removeClass('descriptionColorAndroid').addClass('descriptionColoriOS');
  840. window.$('#offlineArea').removeClass('offlineAreaAndroid').addClass('offlineAreaiOS');
  841. window.$('#offlineTextMode').removeClass('offlineTextModeAndroid').addClass('offlineTextModeiOS');
  842. } else {
  843. window.$('#mapPosition').removeClass('mapiOS').addClass('mapAndroid');
  844. window.$('#fontsApp').removeClass('fontsiOS').addClass('fontsAndroid');
  845. window.$('#selectPosition').removeClass('selectPositioniOS').addClass('selectPositionAndroid');
  846. window.$('#listCity').removeClass('selectCitysiOS').addClass('selectCitysAndroid');
  847. window.$('#cityTitle').removeClass('cityTitleiOS').addClass('cityTitleAndroid');
  848. window.$('#descriptionColor').removeClass('descriptionColoriOS').addClass('descriptionColorAndroid');
  849. window.$('#offlineArea').removeClass('offlineAreaiOS').addClass('offlineAreaAndroid');
  850. window.$('#offlineTextMode').removeClass('offlineTextModeiOS').addClass('offlineTextModeAndroid');
  851.  
  852. }
  853. }])
  854.  
  855.  
  856. .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) {
  857.  
  858. 'use strict';
  859.  
  860. //Aqui está o bug 6165.
  861. 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>";
  862.  
  863. $scope.popover = $ionicPopover.fromTemplate(template, {
  864. scope: $scope
  865. });
  866.  
  867. $scope.closePopover = function () {
  868. $scope.popover.hide();
  869. }
  870.  
  871. $ionicPlatform.registerBackButtonAction(function (event) {
  872. event.preventDefault();
  873. event.stopPropagation();
  874.  
  875. if ($state.current.name == 'menu-inicio' || $state.current.name == '') {
  876. window.ionic.Platform.exitApp();
  877. } else if ($state.current.name === 'menu-android.city') {
  878. window.ionic.Platform.exitApp();
  879. } else if ($state.current.name.toLowerCase().indexOf('comment') > -1) {
  880. $rootScope.refreshItems();
  881. $ionicHistory.goBack();
  882. } else if ($state.current.name.indexOf('menu-android.') > -1 && !$state.current.name.indexOf('-item') > -1) {
  883. $ionicHistory.goBack();
  884. 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"){
  885. $state.go("menu-android.city");
  886. }
  887. } else if ($state.current.name.indexOf('menu-android.') > -1) {
  888. $state.go('menu-android.' + $state.current.name.split('.')[1].split('-')[0]);
  889. } else {
  890. $ionicHistory.goBack();
  891. }
  892.  
  893. }, 100);
  894.  
  895. $scope.openPopover = function ($event) {
  896.  
  897. if(window.networkOnline){
  898. Loading.show();
  899. cityRepository.getListAll(function (response){
  900.  
  901. $rootScope.cityList = response.result;
  902.  
  903. Loading.hide();
  904. });
  905. }
  906.  
  907. if($rootScope.cityList.length != 0){
  908. $scope.popover.show($event);
  909. }else{
  910. alert.networkWarning(function () {});
  911. }
  912.  
  913.  
  914. };
  915.  
  916. $scope.openCitiesMenu = function ($event) {
  917.  
  918.  
  919. Loading.show();
  920. cityRepository.getListAll(function (response){
  921.  
  922. $rootScope.cityList = response.result;
  923.  
  924. Loading.hide();
  925. });
  926.  
  927.  
  928. if($rootScope.cityList.length != 0){
  929. $scope.popover.show($event);
  930. }else{
  931. alert.networkWarning(function () {});
  932. }
  933.  
  934.  
  935. };
  936.  
  937. $rootScope.closePopover = function () {
  938. $scope.popover.hide();
  939. };
  940. //Cleanup the popover when we're done with it!
  941. $scope.$on('$destroy', function () {
  942. $scope.popover.remove();
  943. });
  944. // Execute action on hide popover
  945. $scope.$on('popover.hidden', function () {
  946. // Execute action
  947. });
  948. // Execute action on remove popover
  949. $scope.$on('popover.removed', function () {
  950. // Execute action
  951. });
  952.  
  953.  
  954. $scope.cidade = $rootScope.selecao;
  955.  
  956.  
  957. $scope.selectedCityService = function (cidadeSelecionada) {
  958. var cityId;
  959. if (cidadeSelecionada !== undefined && cidadeSelecionada !== "undefined" && (window.networkOnline || cidadeSelecionada.offline_mode)) {
  960. Loading.show();
  961. cityId = cidadeSelecionada.city_id;
  962. options.registerCity(cityId);
  963. cityRepository.getCity(cityId, function (response) {
  964. try {
  965. Loading.hide();
  966. Dados = response;
  967. $rootScope.selecao = Dados;
  968. $scope.selecao = Dados;
  969. window.name = response.name;
  970. window.signal = 1;
  971. setTimeout(function () {
  972. $state.go('menu-android.city', {}, { reload: false, cache: false });
  973. var mapOptions = {
  974. center: { lat: parseFloat($rootScope.selecao.latitude.replace(",", ".")), lng: parseFloat($rootScope.selecao.longitude.replace(",", ".")) },
  975. scrollwheel: true,
  976. zoom: 14,
  977. clickableIcons: false
  978. };
  979. if ($rootScope.manageSwitch) {
  980. var offline = Dados.offline_mode;
  981. $rootScope.isCityOffline = offline;
  982. console.log("OFFLINEMODE: " + offline);
  983. if(!offline || !cidadeSelecionada.updateCity){
  984. $rootScope.showWarnUpdateCity = false;
  985. }else{
  986. $rootScope.showWarnUpdateCity = true;
  987. }
  988. $rootScope.manageSwitch(offline);
  989. }
  990.  
  991. $rootScope.closePopover();
  992.  
  993. $rootScope.enableClickEvents();
  994.  
  995. if($rootScope.loadGallery){
  996.  
  997. $rootScope.loadGallery(cityId);
  998. }
  999. if ($rootScope.fly)
  1000. $rootScope.fly(mapOptions);
  1001.  
  1002. $rootScope.reloadMap();
  1003. }, 200);
  1004. $ionicSideMenuDelegate.toggleLeft();
  1005. $scope.cidade = { city_id: $rootScope.selecao.city_id };
  1006. } catch (exception) {
  1007. Loading.hide();
  1008. window.logManager.error(exception);
  1009. console.log(exception);
  1010. }
  1011. }, function (response) {
  1012. Loading.hide();
  1013. window.logManager.info(JSON.stringify(response));
  1014. });
  1015. }else{
  1016. alert.networkWarning(function(){});
  1017. }
  1018. };
  1019. }]);
Add Comment
Please, Sign In to add comment