angular.module('appWrapperDemo') .controller('appWrapperDemoController', [ '$scope', '$rootScope', '$timeout', 'focaSqliteService', 'API_ENDPOINT', 'focaModalService', function($scope, $rootScope, $timeout, focaSqliteService, API_ENDPOINT, focaModalService) { document.addEventListener('deviceready', function() { focaSqliteService.openDataBase(); }); if(!API_ENDPOINT.URL) { API_ENDPOINT.getUrl().then(success, error); } function success(res) { API_ENDPOINT.setUrl(res.data); } function error() { focaModalService.alert('La terminal no esta configurada correctamente'); } $scope.usarTeclado = false; $rootScope.$broadcast('usarTeclado', false); $scope.mostrarTeclado = false; //Envía broadcast para avisar que el teclado está en funcionamiento o no //para su uso cambiar ng-click del boton por esta función $scope.cambioUsoTeclado = function() { if($scope.usarTeclado) { $scope.usarTeclado = false; $rootScope.$broadcast('usarTeclado', false); return; } $scope.usarTeclado = true; $rootScope.$broadcast('usarTeclado', true); }; $rootScope.$on('focus', function() { if(!$scope.usarTeclado) { return; } $scope.mostrarTeclado = true; $timeout.cancel($scope.timeout); if(!$scope.$$phase) { $scope.$apply(); } }); $rootScope.$on('blur', function() { $scope.timeout = $timeout(function() { $scope.mostrarTeclado = false; if(!$scope.$$phase) { $scope.$apply(); } }, 150); }); } ]);