Commit ccf0901ea06bc1415d503f911df9177edcf670c9
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !5
Showing
1 changed file
Show diff stats
src/js/controller.js
... | ... | @@ -7,18 +7,28 @@ angular.module('focaAgendarVisita') |
7 | 7 | $uibModal, focaBotoneraLateralService, $filter, |
8 | 8 | focaModalService, focaSeguimientoService |
9 | 9 | ) { |
10 | - $scope.focused = 0; | |
11 | - $scope.rol = 1; | |
12 | - $scope.visita = {}; | |
13 | - $scope.now = new Date(); | |
14 | - $scope.botonera = focaAgendarVisitaService.getBotonera(); | |
15 | - $timeout(function() { | |
16 | - focaBotoneraLateralService.showSalir(true); | |
17 | - focaBotoneraLateralService.showPausar(true); | |
18 | - focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
19 | - }); | |
20 | 10 | |
21 | - $timeout(function() {getLSVisita();}); | |
11 | + config(); | |
12 | + init(); | |
13 | + | |
14 | + function config() { | |
15 | + $scope.focused = 0; | |
16 | + $scope.rol = 1; | |
17 | + $scope.visita = {}; | |
18 | + $scope.now = new Date(); | |
19 | + } | |
20 | + | |
21 | + function init() { | |
22 | + $scope.botonera = focaAgendarVisitaService.getBotonera(); | |
23 | + $timeout(function() { | |
24 | + focaBotoneraLateralService.showSalir(false); | |
25 | + focaBotoneraLateralService.showPausar(true); | |
26 | + focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
27 | + focaBotoneraLateralService.addCustomButton('Salir', salir); | |
28 | + }); | |
29 | + | |
30 | + $timeout(function() {getLSVisita();}); | |
31 | + } | |
22 | 32 | |
23 | 33 | $scope.seleccionarCliente = function() { |
24 | 34 | var modalInstance = $uibModal.open( |
... | ... | @@ -44,19 +54,19 @@ angular.module('focaAgendarVisita') |
44 | 54 | ); |
45 | 55 | }; |
46 | 56 | function setearVisita(visita){ |
47 | - $scope.visita = visita; | |
57 | + $scope.visita = visita; | |
48 | 58 | $scope.$broadcast('addCabecera', { |
49 | 59 | label: 'Cliente:', |
50 | 60 | valor: $filter('rellenarDigitos')(visita.cliente.cod, 3) + ' - ' + |
51 | 61 | visita.cliente.nom |
52 | - }); | |
62 | + }); | |
53 | 63 | } |
54 | 64 | function getLSVisita(){ |
55 | - var visita= JSON.parse($localStorage.visita || null); | |
65 | + var visita = JSON.parse($localStorage.visita || null); | |
56 | 66 | if (visita) { |
57 | 67 | setearVisita(visita); |
58 | 68 | delete $localStorage.visita; |
59 | - } | |
69 | + } | |
60 | 70 | } |
61 | 71 | |
62 | 72 | $scope.seleccionarVisitante = function() { |
... | ... | @@ -158,6 +168,19 @@ angular.module('focaAgendarVisita') |
158 | 168 | $location.path('/'); |
159 | 169 | }); |
160 | 170 | }; |
171 | + function salir() { | |
172 | + var confirmar = angular.equals($scope.visita, {}); | |
173 | + | |
174 | + if (!confirmar) { | |
175 | + focaModalService.confirm( | |
176 | + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
177 | + ).then(function(data) { | |
178 | + if (data) $location.path('/'); | |
179 | + }); | |
180 | + } else { | |
181 | + $location.path('/'); | |
182 | + } | |
183 | + } | |
161 | 184 | } |
162 | 185 | ]) |
163 | 186 | .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope', |