Commit 9181cef41fef812f390d3074319c7af51e5da240
1 parent
c693d2155e
Exists in
master
espacio
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
src/js/controller.js
1 | angular.module('appWrapperDemo') | 1 | angular.module('appWrapperDemo') |
2 | .controller('appWrapperDemoController', [ | 2 | .controller('appWrapperDemoController', [ |
3 | '$scope', | 3 | '$scope', |
4 | '$rootScope', | 4 | '$rootScope', |
5 | '$timeout', | 5 | '$timeout', |
6 | 'focaSqliteService', | 6 | 'focaSqliteService', |
7 | 'API_ENDPOINT', | 7 | 'API_ENDPOINT', |
8 | 'focaModalService', | 8 | 'focaModalService', |
9 | function($scope, $rootScope, $timeout, focaSqliteService, API_ENDPOINT, focaModalService) { | 9 | function($scope, $rootScope, $timeout, focaSqliteService, API_ENDPOINT, focaModalService) { |
10 | document.addEventListener('deviceready', function() { | 10 | document.addEventListener('deviceready', function() { |
11 | focaSqliteService.openDataBase(); | 11 | focaSqliteService.openDataBase(); |
12 | }); | 12 | }); |
13 | 13 | ||
14 | if(!API_ENDPOINT.URL) { | 14 | if (!API_ENDPOINT.URL) { |
15 | API_ENDPOINT.getUrl().then(success, error); | 15 | API_ENDPOINT.getUrl().then(success, error); |
16 | } | 16 | } |
17 | 17 | ||
18 | function success(res) { | 18 | function success(res) { |
19 | API_ENDPOINT.setUrl(res.data); | 19 | API_ENDPOINT.setUrl(res.data); |
20 | } | 20 | } |
21 | function error() { | 21 | function error() { |
22 | focaModalService.alert('La terminal no esta configurada correctamente'); | 22 | focaModalService.alert('La terminal no esta configurada correctamente'); |
23 | } | 23 | } |
24 | 24 | ||
25 | $scope.usarTeclado = false; | 25 | $scope.usarTeclado = false; |
26 | $rootScope.$broadcast('usarTeclado', false); | 26 | $rootScope.$broadcast('usarTeclado', false); |
27 | $scope.mostrarTeclado = false; | 27 | $scope.mostrarTeclado = false; |
28 | //Envía broadcast para avisar que el teclado está en funcionamiento o no | 28 | //Envía broadcast para avisar que el teclado está en funcionamiento o no |
29 | //para su uso cambiar ng-click del boton por esta función | 29 | //para su uso cambiar ng-click del boton por esta función |
30 | $scope.cambioUsoTeclado = function() { | 30 | $scope.cambioUsoTeclado = function() { |
31 | if($scope.usarTeclado) { | 31 | if($scope.usarTeclado) { |
32 | $scope.usarTeclado = false; | 32 | $scope.usarTeclado = false; |
33 | $rootScope.$broadcast('usarTeclado', false); | 33 | $rootScope.$broadcast('usarTeclado', false); |
34 | return; | 34 | return; |
35 | } | 35 | } |
36 | $scope.usarTeclado = true; | 36 | $scope.usarTeclado = true; |
37 | $rootScope.$broadcast('usarTeclado', true); | 37 | $rootScope.$broadcast('usarTeclado', true); |
38 | }; | 38 | }; |
39 | 39 | ||
40 | $rootScope.$on('focus', function() { | 40 | $rootScope.$on('focus', function() { |
41 | if(!$scope.usarTeclado) { | 41 | if(!$scope.usarTeclado) { |
42 | return; | 42 | return; |
43 | } | 43 | } |
44 | $scope.mostrarTeclado = true; | 44 | $scope.mostrarTeclado = true; |
45 | $timeout.cancel($scope.timeout); | 45 | $timeout.cancel($scope.timeout); |
46 | if(!$scope.$$phase) { | 46 | if(!$scope.$$phase) { |
47 | $scope.$apply(); | 47 | $scope.$apply(); |
48 | } | 48 | } |
49 | }); | 49 | }); |
50 | $rootScope.$on('blur', function() { | 50 | $rootScope.$on('blur', function() { |
51 | $scope.timeout = $timeout(function() { | 51 | $scope.timeout = $timeout(function() { |
52 | $scope.mostrarTeclado = false; | 52 | $scope.mostrarTeclado = false; |
53 | if(!$scope.$$phase) { | 53 | if(!$scope.$$phase) { |
54 | $scope.$apply(); | 54 | $scope.$apply(); |
55 | } | 55 | } |
56 | }, 150); | 56 | }, 150); |
57 | }); | 57 | }); |
58 | } | 58 | } |
59 | ]); | 59 | ]); |
60 | 60 |