Commit 8b7191751b070a83149d1c07c544239ae2eee5cf

Authored by Luigi
1 parent c4a826fa48
Exists in master

Cambio boton "cancelar" por "salir"

Showing 1 changed file with 2 additions and 2 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(false); 123 focaBotoneraLateralService.showCancelar(false);
124 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 124 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
125 focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); 125 focaBotoneraLateralService.addCustomButton('Salir', salir);
126 126
127 }); 127 });
128 128
129 $timeout(function() {getLSChofer();}); 129 $timeout(function() {getLSChofer();});
130 130
131 if ($scope.nuevo) { 131 if ($scope.nuevo) {
132 focaAbmChoferService 132 focaAbmChoferService
133 .getTransportistaPorId($routeParams.idTransportista) 133 .getTransportistaPorId($routeParams.idTransportista)
134 .then(function(res) { 134 .then(function(res) {
135 var codigo = ('00000' + res.data.COD).slice(-5); 135 var codigo = ('00000' + res.data.COD).slice(-5);
136 $scope.chofer.idTransportista = res.data.COD; 136 $scope.chofer.idTransportista = res.data.COD;
137 $scope.chofer.transportista = res.data; 137 $scope.chofer.transportista = res.data;
138 $scope.$broadcast('addCabecera', { 138 $scope.$broadcast('addCabecera', {
139 label: 'Transportista:', 139 label: 'Transportista:',
140 valor: codigo + ' - ' + res.data.NOM 140 valor: codigo + ' - ' + res.data.NOM
141 }); 141 });
142 }); 142 });
143 } 143 }
144 144
145 focaAbmChoferService.getChofer($routeParams.id).then(function(res) { 145 focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
146 if (res.data) { 146 if (res.data) {
147 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 147 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
148 $scope.chofer = res.data; 148 $scope.chofer = res.data;
149 $scope.$broadcast('addCabecera', { 149 $scope.$broadcast('addCabecera', {
150 label: 'Transportista:', 150 label: 'Transportista:',
151 valor: codigo + ' - ' + res.data.transportista.NOM 151 valor: codigo + ' - ' + res.data.transportista.NOM
152 }); 152 });
153 } 153 }
154 }); 154 });
155 155
156 focaAbmChoferService.getTransportistas().then(function(res) { 156 focaAbmChoferService.getTransportistas().then(function(res) {
157 $scope.transportistas = res.data; 157 $scope.transportistas = res.data;
158 }); 158 });
159 159
160 function setearChofer(chofer) { 160 function setearChofer(chofer) {
161 $scope.chofer = chofer; 161 $scope.chofer = chofer;
162 $scope.$broadcast('addCabecera', { 162 $scope.$broadcast('addCabecera', {
163 label: 'Transportista:', 163 label: 'Transportista:',
164 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - ' 164 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - '
165 }); 165 });
166 } 166 }
167 function getLSChofer() { 167 function getLSChofer() {
168 var chofer = JSON.parse($localStorage.chofer || null); 168 var chofer = JSON.parse($localStorage.chofer || null);
169 169
170 if (chofer) { 170 if (chofer) {
171 setearChofer(chofer); 171 setearChofer(chofer);
172 delete $localStorage.chofer; 172 delete $localStorage.chofer;
173 } 173 }
174 } 174 }
175 175
176 $scope.cancelar = function() { 176 $scope.cancelar = function() {
177 $location.path('/chofer'); 177 $location.path('/chofer');
178 }; 178 };
179 179
180 $scope.guardar = function(key) { 180 $scope.guardar = function(key) {
181 181
182 if (!$scope.chofer.nombre) { 182 if (!$scope.chofer.nombre) {
183 focaModalService.alert('Ingrese nombre'); 183 focaModalService.alert('Ingrese nombre');
184 return; 184 return;
185 } else if (!$scope.chofer.idTipoDocumento) { 185 } else if (!$scope.chofer.idTipoDocumento) {
186 focaModalService.alert('Seleccione tipo de documento'); 186 focaModalService.alert('Seleccione tipo de documento');
187 return; 187 return;
188 } else if (!$scope.chofer.dni) { 188 } else if (!$scope.chofer.dni) {
189 focaModalService.alert('Ingrese DNI'); 189 focaModalService.alert('Ingrese DNI');
190 return; 190 return;
191 } 191 }
192 192
193 key = (typeof key === 'undefined') ? 13 : key; 193 key = (typeof key === 'undefined') ? 13 : key;
194 if (key === 13) { 194 if (key === 13) {
195 validaDni().then(function() { 195 validaDni().then(function() {
196 $scope.chofer.idTransportista = $routeParams.idTransportista; 196 $scope.chofer.idTransportista = $routeParams.idTransportista;
197 delete $scope.chofer.transportista; 197 delete $scope.chofer.transportista;
198 focaAbmChoferService.guardarChofer($scope.chofer).then(function() { 198 focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
199 $location.path('/chofer'); 199 $location.path('/chofer');
200 }); 200 });
201 }, function() { 201 }, function() {
202 focaModalService.alert('Dni existente'); 202 focaModalService.alert('Dni existente');
203 }); 203 });
204 } 204 }
205 }; 205 };
206 206
207 $scope.$watch('chofer', function(newValue) { 207 $scope.$watch('chofer', function(newValue) {
208 focaBotoneraLateralService.setPausarData({ 208 focaBotoneraLateralService.setPausarData({
209 label: 'chofer', 209 label: 'chofer',
210 val: { 210 val: {
211 dni: newValue.dni, 211 dni: newValue.dni,
212 idTransportista: newValue.idTransportista, 212 idTransportista: newValue.idTransportista,
213 nombre: newValue.nombre, 213 nombre: newValue.nombre,
214 telefono: newValue.telefono, 214 telefono: newValue.telefono,
215 idTipoDocumento: newValue.idTipoDocumento, 215 idTipoDocumento: newValue.idTipoDocumento,
216 id: newValue.id 216 id: newValue.id
217 } 217 }
218 }); 218 });
219 }, true); 219 }, true);
220 220
221 function cancelar() { 221 function salir() {
222 if ($scope.formChofer.$pristine == false) { 222 if ($scope.formChofer.$pristine == false) {
223 focaModalService.confirm( 223 focaModalService.confirm(
224 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 224 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
225 ).then(function(data) { 225 ).then(function(data) {
226 if (data) { 226 if (data) {
227 $location.path('/chofer'); 227 $location.path('/chofer');
228 } 228 }
229 }); 229 });
230 } else { 230 } else {
231 $location.path('/chofer'); 231 $location.path('/chofer');
232 } 232 }
233 } 233 }
234 234
235 function validaDni() { 235 function validaDni() {
236 return new Promise(function(resolve, reject) { 236 return new Promise(function(resolve, reject) {
237 focaAbmChoferService 237 focaAbmChoferService
238 .getChoferPorDni($scope.chofer.dni) 238 .getChoferPorDni($scope.chofer.dni)
239 .then(function(res) { 239 .then(function(res) {
240 if (res.data.id && 240 if (res.data.id &&
241 $scope.chofer.id !== res.data.id) { 241 $scope.chofer.id !== res.data.id) {
242 reject(res.data); 242 reject(res.data);
243 } else { 243 } else {
244 resolve(); 244 resolve();
245 } 245 }
246 }); 246 });
247 }); 247 });
248 } 248 }
249 } 249 }
250 ]); 250 ]);
251 251