Commit c4a826fa483731c7688a940dc1f8301fa4f42168

Authored by Luigi
1 parent 299f288f1d
Exists in master

Modal Cancelar

Showing 1 changed file with 31 additions and 19 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaAbmChofer') 1 angular.module('focaAbmChofer')
2 .controller('focaAbmChoferesController', [ 2 .controller('focaAbmChoferesController', [
3 '$scope', 'focaAbmChoferService', '$location', '$uibModal', 3 '$scope', 'focaAbmChoferService', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
6 focaBotoneraLateralService, $timeout, $localStorage) { 6 focaBotoneraLateralService, $timeout, $localStorage) {
7 7
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.filters = ''; 9 $scope.filters = '';
10 $scope.choferes = []; 10 $scope.choferes = [];
11 $scope.botonera = [{ 11 $scope.botonera = [{
12 label: 'Transportista', 12 label: 'Transportista',
13 image: 'cliente.png' 13 image: 'cliente.png'
14 }]; 14 }];
15 15
16 //SETEO BOTONERA LATERAL 16 //SETEO BOTONERA LATERAL
17 $timeout(function() { 17 $timeout(function() {
18 focaBotoneraLateralService.showSalir(false); 18 focaBotoneraLateralService.showSalir(false);
19 focaBotoneraLateralService.showPausar(false); 19 focaBotoneraLateralService.showPausar(false);
20 focaBotoneraLateralService.showCancelar(false); 20 focaBotoneraLateralService.showCancelar(false);
21 focaBotoneraLateralService.showGuardar(false); 21 focaBotoneraLateralService.showGuardar(false);
22 focaBotoneraLateralService.addCustomButton('Salir', salir); 22 focaBotoneraLateralService.addCustomButton('Salir', salir);
23 }); 23 });
24 24
25 if (focaAbmChoferService.transportistaSeleccionado.COD) { 25 if (focaAbmChoferService.transportistaSeleccionado.COD) {
26 elegirTransportista(focaAbmChoferService.transportistaSeleccionado); 26 elegirTransportista(focaAbmChoferService.transportistaSeleccionado);
27 } 27 }
28 28
29 $scope.editar = function(id) { 29 $scope.editar = function(id) {
30 $location.path('/chofer/' + id + '/' + $scope.idTransportista); 30 $location.path('/chofer/' + id + '/' + $scope.idTransportista);
31 }; 31 };
32 32
33 $scope.solicitarConfirmacion = function(chofer) { 33 $scope.solicitarConfirmacion = function(chofer) {
34 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' + 34 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
35 chofer.nombre + ' ?').then(function(confirmed) { 35 chofer.nombre + ' ?').then(function(confirmed) {
36 if (confirmed) { 36 if (confirmed) {
37 focaAbmChoferService.deleteChofer(chofer.id); 37 focaAbmChoferService.deleteChofer(chofer.id);
38 $scope.choferes.splice($scope.choferes.indexOf(chofer), 1); 38 $scope.choferes.splice($scope.choferes.indexOf(chofer), 1);
39 } 39 }
40 }); 40 });
41 }; 41 };
42 42
43 $scope.seleccionarTransportista = function() { 43 $scope.seleccionarTransportista = function() {
44 var parametrosModal = { 44 var parametrosModal = {
45 titulo: 'Búsqueda de Transportista', 45 titulo: 'Búsqueda de Transportista',
46 query: '/transportista', 46 query: '/transportista',
47 columnas: [ 47 columnas: [
48 { 48 {
49 nombre: 'Código', 49 nombre: 'Código',
50 propiedad: 'COD' 50 propiedad: 'COD'
51 }, 51 },
52 { 52 {
53 nombre: 'Nombre', 53 nombre: 'Nombre',
54 propiedad: 'NOM' 54 propiedad: 'NOM'
55 }, 55 },
56 { 56 {
57 nombre: 'CUIT', 57 nombre: 'CUIT',
58 propiedad: 'CUIT' 58 propiedad: 'CUIT'
59 } 59 }
60 ] 60 ]
61 }; 61 };
62 focaModalService.modal(parametrosModal).then( 62 focaModalService.modal(parametrosModal).then(
63 function(transportista) { 63 function(transportista) {
64 elegirTransportista(transportista); 64 elegirTransportista(transportista);
65 focaAbmChoferService.transportistaSeleccionado = transportista; 65 focaAbmChoferService.transportistaSeleccionado = transportista;
66 }, function() {} 66 }, function() {}
67 ); 67 );
68 }; 68 };
69 69
70 function elegirTransportista(transportista) { 70 function elegirTransportista(transportista) {
71 buscar(transportista.COD); 71 buscar(transportista.COD);
72 var codigo = ('00000' + transportista.COD).slice(-5); 72 var codigo = ('00000' + transportista.COD).slice(-5);
73 $scope.idTransportista = transportista.COD; 73 $scope.idTransportista = transportista.COD;
74 $timeout(function() { 74 $timeout(function() {
75 $scope.$broadcast('addCabecera', { 75 $scope.$broadcast('addCabecera', {
76 label: 'Transportista:', 76 label: 'Transportista:',
77 valor: codigo + ' - ' + transportista.NOM 77 valor: codigo + ' - ' + transportista.NOM
78 }); 78 });
79 }); 79 });
80 } 80 }
81 81
82 function buscar(id) { 82 function buscar(id) {
83 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { 83 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
84 $scope.choferes = res.data; 84 $scope.choferes = res.data;
85 }); 85 });
86 } 86 }
87 87
88 function salir() { 88 function salir() {
89 focaAbmChoferService.transportistaSeleccionado = {}; 89 focaAbmChoferService.transportistaSeleccionado = {};
90 $location.path('/'); 90 $location.path('/');
91 } 91 }
92 92
93 if ($localStorage.chofer) { 93 if ($localStorage.chofer) {
94 var chofer = JSON.parse($localStorage.chofer); 94 var chofer = JSON.parse($localStorage.chofer);
95 if (!chofer.id) { chofer.id = 0; } 95 if (!chofer.id) { chofer.id = 0; }
96 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); 96 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista);
97 } 97 }
98 } 98 }
99 ]) 99 ])
100 .controller('focaAbmChoferController', [ 100 .controller('focaAbmChoferController', [
101 '$scope', 'focaAbmChoferService', '$routeParams', '$localStorage', '$filter', 101 '$scope', 'focaAbmChoferService', '$routeParams', '$localStorage', '$filter',
102 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', '$window', 102 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', '$window',
103 function($scope, focaAbmChoferService, $routeParams, $localStorage, $filter, 103 function($scope, focaAbmChoferService, $routeParams, $localStorage, $filter,
104 $location, focaBotoneraLateralService, $timeout, focaModalService){ 104 $location, focaBotoneraLateralService, $timeout, focaModalService){
105 105
106 $scope.focused = 1; 106 $scope.focused = 1;
107 $scope.nuevo = $routeParams.id === '0'; 107 $scope.nuevo = $routeParams.id === '0';
108 $scope.chofer = {}; 108 $scope.chofer = {};
109 $scope.transportistas = []; 109 $scope.transportistas = [];
110 $scope.now = new Date(); 110 $scope.now = new Date();
111 $scope.next = function(key) { 111 $scope.next = function(key) {
112 if (key === 13) $scope.focused++; 112 if (key === 13) $scope.focused++;
113 }; 113 };
114 114
115 focaAbmChoferService.getTiposDocumento().then(function(res) { 115 focaAbmChoferService.getTiposDocumento().then(function(res) {
116 $scope.tiposDocumento = res.data; 116 $scope.tiposDocumento = res.data;
117 }); 117 });
118 118
119 //SETEO BOTONERA LATERAL 119 //SETEO BOTONERA LATERAL
120 $timeout(function() { 120 $timeout(function() {
121 focaBotoneraLateralService.showSalir(false); 121 focaBotoneraLateralService.showSalir(false);
122 focaBotoneraLateralService.showPausar(true); 122 focaBotoneraLateralService.showPausar(true);
123 focaBotoneraLateralService.showCancelar(true); 123 focaBotoneraLateralService.showCancelar(false);
124 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 124 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
125 focaBotoneraLateralService.addCustomButton('Cancelar', cancelar);
126
125 }); 127 });
126 128
127 $timeout(function() {getLSChofer();}); 129 $timeout(function() {getLSChofer();});
128 130
129 if ($scope.nuevo) { 131 if ($scope.nuevo) {
130 focaAbmChoferService 132 focaAbmChoferService
131 .getTransportistaPorId($routeParams.idTransportista) 133 .getTransportistaPorId($routeParams.idTransportista)
132 .then(function(res) { 134 .then(function(res) {
133 var codigo = ('00000' + res.data.COD).slice(-5); 135 var codigo = ('00000' + res.data.COD).slice(-5);
134 $scope.chofer.idTransportista = res.data.COD; 136 $scope.chofer.idTransportista = res.data.COD;
135 $scope.chofer.transportista = res.data; 137 $scope.chofer.transportista = res.data;
136 $scope.$broadcast('addCabecera', { 138 $scope.$broadcast('addCabecera', {
137 label: 'Transportista:', 139 label: 'Transportista:',
138 valor: codigo + ' - ' + res.data.NOM 140 valor: codigo + ' - ' + res.data.NOM
139 }); 141 });
140 }); 142 });
141 } 143 }
142 144
143 focaAbmChoferService.getChofer($routeParams.id).then(function(res) { 145 focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
144 if (res.data) { 146 if (res.data) {
145 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 147 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
146 $scope.chofer = res.data; 148 $scope.chofer = res.data;
147 $scope.$broadcast('addCabecera', { 149 $scope.$broadcast('addCabecera', {
148 label: 'Transportista:', 150 label: 'Transportista:',
149 valor: codigo + ' - ' + res.data.transportista.NOM 151 valor: codigo + ' - ' + res.data.transportista.NOM
150 }); 152 });
151 } 153 }
152 }); 154 });
153 155
154 focaAbmChoferService.getTransportistas().then(function(res) { 156 focaAbmChoferService.getTransportistas().then(function(res) {
155 $scope.transportistas = res.data; 157 $scope.transportistas = res.data;
156 }); 158 });
157 159
158 function setearChofer(chofer) { 160 function setearChofer(chofer) {
159 $scope.chofer = chofer; 161 $scope.chofer = chofer;
160 $scope.$broadcast('addCabecera', { 162 $scope.$broadcast('addCabecera', {
161 label: 'Transportista:', 163 label: 'Transportista:',
162 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - ' 164 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - '
163 }); 165 });
164 } 166 }
165 function getLSChofer() { 167 function getLSChofer() {
166 var chofer = JSON.parse($localStorage.chofer || null); 168 var chofer = JSON.parse($localStorage.chofer || null);
167 169
168 if (chofer) { 170 if (chofer) {
169 setearChofer(chofer); 171 setearChofer(chofer);
170 delete $localStorage.chofer; 172 delete $localStorage.chofer;
171 } 173 }
172 } 174 }
173 175
174 $scope.cancelar = function() { 176 $scope.cancelar = function() {
175 $location.path('/chofer'); 177 $location.path('/chofer');
176 };
177
178 $scope.pausar = function() {
179 focaBotoneraLateralService.pausar();
180 }; 178 };
181 179
182 $scope.guardar = function(key) { 180 $scope.guardar = function(key) {
183 181
184 if (!$scope.chofer.nombre) { 182 if (!$scope.chofer.nombre) {
185 focaModalService.alert('Ingrese nombre'); 183 focaModalService.alert('Ingrese nombre');
186 return; 184 return;
187 } else if (!$scope.chofer.idTipoDocumento) { 185 } else if (!$scope.chofer.idTipoDocumento) {
188 focaModalService.alert('Seleccione tipo de documento'); 186 focaModalService.alert('Seleccione tipo de documento');
189 return; 187 return;
190 } else if (!$scope.chofer.dni) { 188 } else if (!$scope.chofer.dni) {
191 focaModalService.alert('Ingrese DNI'); 189 focaModalService.alert('Ingrese DNI');
192 return; 190 return;
193 } 191 }
194 192
195 key = (typeof key === 'undefined') ? 13 : key; 193 key = (typeof key === 'undefined') ? 13 : key;
196 if (key === 13) { 194 if (key === 13) {
197 validaDni().then(function() { 195 validaDni().then(function() {
198 $scope.chofer.idTransportista = $routeParams.idTransportista; 196 $scope.chofer.idTransportista = $routeParams.idTransportista;
199 delete $scope.chofer.transportista; 197 delete $scope.chofer.transportista;
200 focaAbmChoferService.guardarChofer($scope.chofer).then(function() { 198 focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
201 $location.path('/chofer'); 199 $location.path('/chofer');
202 }); 200 });
203 }, function() { 201 }, function() {
204 focaModalService.alert('Dni existente'); 202 focaModalService.alert('Dni existente');
205 }); 203 });
206 } 204 }
207 }; 205 };
208 206
209 $scope.$watch('chofer', function(newValue) { 207 $scope.$watch('chofer', function(newValue) {
210 focaBotoneraLateralService.setPausarData({ 208 focaBotoneraLateralService.setPausarData({
211 label: 'chofer', 209 label: 'chofer',
212 val: { 210 val: {
213 dni: newValue.dni, 211 dni: newValue.dni,
214 idTransportista: newValue.idTransportista, 212 idTransportista: newValue.idTransportista,
215 nombre: newValue.nombre, 213 nombre: newValue.nombre,
216 telefono: newValue.telefono, 214 telefono: newValue.telefono,
217 idTipoDocumento: newValue.idTipoDocumento, 215 idTipoDocumento: newValue.idTipoDocumento,
218 id: newValue.id 216 id: newValue.id
219 } 217 }
220 }); 218 });
221 }, true); 219 }, true);
222 220
221 function cancelar() {
222 if ($scope.formChofer.$pristine == false) {
223 focaModalService.confirm(
224 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
225 ).then(function(data) {
226 if (data) {
227 $location.path('/chofer');
228 }
229 });
230 } else {
231 $location.path('/chofer');
232 }
233 }
234
223 function validaDni() { 235 function validaDni() {
224 return new Promise(function(resolve, reject) { 236 return new Promise(function(resolve, reject) {
225 focaAbmChoferService 237 focaAbmChoferService
226 .getChoferPorDni($scope.chofer.dni) 238 .getChoferPorDni($scope.chofer.dni)
227 .then(function(res) { 239 .then(function(res) {
228 if(res.data.id && 240 if (res.data.id &&
229 $scope.chofer.id !== res.data.id) { 241 $scope.chofer.id !== res.data.id) {
230 reject(res.data); 242 reject(res.data);
231 }else { 243 } else {
232 resolve(); 244 resolve();
233 } 245 }
234 }); 246 });
235 }); 247 });