controller.js
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
angular.module('appWrapperDemo')
.controller('appWrapperDemoController', [
'$scope',
'$rootScope',
'$timeout',
'focaSqliteService',
'focaModalService',
'API_ENDPOINT',
'$localStorage',
function($scope, $rootScope, $timeout, focaSqliteService, focaModalService, API_ENDPOINT, $localStorage) {
document.addEventListener('deviceready', function() {
focaSqliteService.openDataBase();
});
if (!API_ENDPOINT.URL) {
API_ENDPOINT.getUrl().then(success, err);
}
function success(res) {
API_ENDPOINT.setUrl(res.data);
}
function err() {
$timeout(function() {
focaModalService.alert('Terminal no configurada: \n' + $localStorage.terminalKey);
}, 1000);
}
$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);
});
}
]);