Commit 1f9869ff74ea4bcfd431f83054ad5d09a2555799
1 parent
fd4384d16b
Exists in
master
and in
2 other branches
Agregar Choferes
Showing
3 changed files
with
264 additions
and
138 deletions
Show diff stats
src/js/controller.js
... | ... | @@ -2,40 +2,137 @@ angular.module('focaAbmChofer') |
2 | 2 | .controller('focaAbmChoferesController', [ |
3 | 3 | '$scope', 'focaAbmChoferService', '$location', '$uibModal', |
4 | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
5 | + '$routeParams', '$filter', | |
5 | 6 | function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, |
6 | - focaBotoneraLateralService, $timeout, $localStorage) { | |
7 | + focaBotoneraLateralService, $timeout, $localStorage, $routeParams, $filter) { | |
7 | 8 | |
9 | + $scope.focused = 1; | |
8 | 10 | $scope.now = new Date(); |
11 | + $scope.nuevo = $routeParams.id === '0'; | |
9 | 12 | $scope.filters = ''; |
10 | 13 | $scope.choferes = []; |
14 | + $scope.creando = false; | |
15 | + $scope.crear = false; | |
16 | + $scope.transportistas = []; | |
11 | 17 | $scope.botonera = [{ |
12 | 18 | label: 'Transportista', |
13 | 19 | image: 'cliente.png' |
14 | 20 | }]; |
21 | + $scope.next = function(key) { | |
22 | + if (key === 13) $scope.focused++; | |
23 | + }; | |
15 | 24 | |
16 | 25 | //SETEO BOTONERA LATERAL |
17 | 26 | $timeout(function() { |
18 | 27 | focaBotoneraLateralService.showSalir(false); |
19 | 28 | focaBotoneraLateralService.showPausar(false); |
20 | 29 | focaBotoneraLateralService.showCancelar(false); |
21 | - focaBotoneraLateralService.showGuardar(false); | |
30 | + focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
22 | 31 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
23 | 32 | }); |
24 | - | |
33 | + | |
25 | 34 | if (focaAbmChoferService.transportistaSeleccionado.COD) { |
26 | 35 | elegirTransportista(focaAbmChoferService.transportistaSeleccionado); |
27 | 36 | } |
28 | 37 | |
29 | - $scope.editar = function(id) { | |
30 | - $location.path('/chofer/' + id + '/' + $scope.idTransportista); | |
38 | + focaAbmChoferService.getTiposDocumento().then(function(res) { | |
39 | + $scope.tiposDocumento = res.data; | |
40 | + }); | |
41 | + | |
42 | + $scope.crearChofer = function () { | |
43 | + var chofer = { | |
44 | + id: 0, | |
45 | + nombre: '', | |
46 | + telefono: '', | |
47 | + editando: true, | |
48 | + }; | |
49 | + $scope.choferes.unshift(chofer); | |
50 | + $scope.crear = false; | |
51 | + }; | |
52 | + | |
53 | + $scope.editar = function(chofer) { | |
54 | + $scope.choferes.forEach(function(chofer) { | |
55 | + chofer.editando = false; | |
56 | + $scope.crear = false; | |
57 | + }); | |
58 | + chofer.editando = true; | |
59 | + $scope.inicial = angular.copy(chofer); | |
60 | + }; | |
61 | + | |
62 | + $scope.agregarChofer = function (chofer) { | |
63 | + if (!chofer) { | |
64 | + focaModalService.alert('Ingrese nombre'); | |
65 | + return; | |
66 | + } else if (!chofer.idTipoDocumento) { | |
67 | + focaModalService.alert('Ingrese tipo documento'); | |
68 | + return; | |
69 | + } else if (!chofer.dni) { | |
70 | + focaModalService.alert('Ingrese DNI'); | |
71 | + return; | |
72 | + } else if (!chofer.telefono) { | |
73 | + focaModalService.alert('Ingrese telรฉfono'); | |
74 | + return; | |
75 | + } | |
76 | + | |
77 | + validaDni(chofer).then(function() { | |
78 | + chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD; | |
79 | + delete chofer.transportista; | |
80 | + }, function() { | |
81 | + focaModalService.alert('Dni existente'); | |
82 | + $scope.editando = true; | |
83 | + }); | |
84 | + $scope.crear = true; | |
85 | + chofer.editando = false; | |
86 | + }; | |
87 | + | |
88 | + $scope.tipoDocumento = function (idTipoDocumento) { | |
89 | + var value = ''; | |
90 | + switch (parseInt(idTipoDocumento)) { | |
91 | + case 96 : | |
92 | + value = 'DNI'; | |
93 | + break; | |
94 | + case 80 : | |
95 | + value = 'CUIT'; | |
96 | + break; | |
97 | + case 86 : | |
98 | + value = 'CUIL'; | |
99 | + break; | |
100 | + default: | |
101 | + value = ''; | |
102 | + break; | |
103 | + } | |
104 | + return value; | |
105 | + }; | |
106 | + | |
107 | + $scope.volver = function (chofer, key) { | |
108 | + if (chofer.idTransportista === undefined) { | |
109 | + $scope.choferes.shift(); | |
110 | + $scope.crear = true; | |
111 | + chofer.editando = false; | |
112 | + return; | |
113 | + } else if (chofer.id !== 0 || !$scope.crear) { | |
114 | + $scope.choferes[key] = $scope.inicial; | |
115 | + $scope.choferes[key].editando = false; | |
116 | + } | |
117 | + $scope.crear = true; | |
118 | + }; | |
119 | + | |
120 | + $scope.guardar = function() { | |
121 | + $scope.choferes.forEach( function (chofer) { | |
122 | + if (chofer.id === 0) { | |
123 | + delete chofer.id; | |
124 | + } | |
125 | + delete chofer.transportista; | |
126 | + delete chofer.editando; | |
127 | + }); | |
128 | + focaAbmChoferService.guardarChoferes($scope.choferes); | |
31 | 129 | }; |
32 | 130 | |
33 | 131 | $scope.solicitarConfirmacion = function(chofer) { |
34 | 132 | focaModalService.confirm('ยฟEstรก seguro que desea borrar el chofer ' + |
35 | 133 | chofer.nombre + ' ?').then(function(confirmed) { |
36 | 134 | if (confirmed) { |
37 | - focaAbmChoferService.deleteChofer(chofer.id); | |
38 | - $scope.choferes.splice($scope.choferes.indexOf(chofer), 1); | |
135 | + chofer.desactivado = true; | |
39 | 136 | } |
40 | 137 | }); |
41 | 138 | }; |
... | ... | @@ -61,6 +158,7 @@ angular.module('focaAbmChofer') |
61 | 158 | }; |
62 | 159 | focaModalService.modal(parametrosModal).then( |
63 | 160 | function(transportista) { |
161 | + $scope.crear = true; | |
64 | 162 | elegirTransportista(transportista); |
65 | 163 | focaAbmChoferService.transportistaSeleccionado = transportista; |
66 | 164 | }, function() {} |
... | ... | @@ -90,72 +188,28 @@ angular.module('focaAbmChofer') |
90 | 188 | $location.path('/'); |
91 | 189 | } |
92 | 190 | |
191 | + function validaDni(chofer) { | |
192 | + return new Promise(function(resolve, reject) { | |
193 | + focaAbmChoferService | |
194 | + .getChoferPorDni(chofer.dni) | |
195 | + .then(function(res) { | |
196 | + if (res.data.id && | |
197 | + chofer.id !== res.data.id) { | |
198 | + reject(res.data); | |
199 | + } else { | |
200 | + resolve(); | |
201 | + } | |
202 | + }); | |
203 | + }); | |
204 | + } | |
205 | + | |
93 | 206 | if ($localStorage.chofer) { |
94 | 207 | var chofer = JSON.parse($localStorage.chofer); |
95 | 208 | if (!chofer.id) { chofer.id = 0; } |
96 | 209 | $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); |
97 | 210 | } |
98 | - } | |
99 | - ]) | |
100 | - .controller('focaAbmChoferController', [ | |
101 | - '$scope', 'focaAbmChoferService', '$routeParams', '$localStorage', '$filter', | |
102 | - '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', '$window', | |
103 | - function($scope, focaAbmChoferService, $routeParams, $localStorage, $filter, | |
104 | - $location, focaBotoneraLateralService, $timeout, focaModalService){ | |
105 | 211 | |
106 | - $scope.focused = 1; | |
107 | - $scope.nuevo = $routeParams.id === '0'; | |
108 | - $scope.chofer = {}; | |
109 | - $scope.transportistas = []; | |
110 | - $scope.now = new Date(); | |
111 | - $scope.next = function(key) { | |
112 | - if (key === 13) $scope.focused++; | |
113 | - }; | |
114 | - | |
115 | - focaAbmChoferService.getTiposDocumento().then(function(res) { | |
116 | - $scope.tiposDocumento = res.data; | |
117 | - }); | |
118 | - | |
119 | - //SETEO BOTONERA LATERAL | |
120 | - $timeout(function() { | |
121 | - focaBotoneraLateralService.showSalir(false); | |
122 | - focaBotoneraLateralService.showPausar(true); | |
123 | - focaBotoneraLateralService.showCancelar(false); | |
124 | - focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
125 | - focaBotoneraLateralService.addCustomButton('Salir', salir); | |
126 | - | |
127 | - }); | |
128 | - | |
129 | - $timeout(function() {getLSChofer();}); | |
130 | - | |
131 | - if ($scope.nuevo) { | |
132 | - focaAbmChoferService | |
133 | - .getTransportistaPorId($routeParams.idTransportista) | |
134 | - .then(function(res) { | |
135 | - var codigo = ('00000' + res.data.COD).slice(-5); | |
136 | - $scope.chofer.idTransportista = res.data.COD; | |
137 | - $scope.chofer.transportista = res.data; | |
138 | - $scope.$broadcast('addCabecera', { | |
139 | - label: 'Transportista:', | |
140 | - valor: codigo + ' - ' + res.data.NOM | |
141 | - }); | |
142 | - }); | |
143 | - } | |
144 | - | |
145 | - focaAbmChoferService.getChofer($routeParams.id).then(function(res) { | |
146 | - if (res.data) { | |
147 | - var codigo = ('00000' + res.data.transportista.COD).slice(-5); | |
148 | - $scope.chofer = res.data; | |
149 | - $scope.$broadcast('addCabecera', { | |
150 | - label: 'Transportista:', | |
151 | - valor: codigo + ' - ' + res.data.transportista.NOM | |
152 | - }); | |
153 | - } | |
154 | - }); | |
155 | - | |
156 | - focaAbmChoferService.getTransportistas().then(function(res) { | |
157 | - $scope.transportistas = res.data; | |
158 | - }); | |
212 | + /*$timeout(function() {getLSChofer();}); | |
159 | 213 | |
160 | 214 | function setearChofer(chofer) { |
161 | 215 | $scope.chofer = chofer; |
... | ... | @@ -164,6 +218,7 @@ angular.module('focaAbmChofer') |
164 | 218 | valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - ' |
165 | 219 | }); |
166 | 220 | } |
221 | + | |
167 | 222 | function getLSChofer() { |
168 | 223 | var chofer = JSON.parse($localStorage.chofer || null); |
169 | 224 | |
... | ... | @@ -173,40 +228,6 @@ angular.module('focaAbmChofer') |
173 | 228 | } |
174 | 229 | } |
175 | 230 | |
176 | - $scope.cancelar = function() { | |
177 | - $location.path('/chofer'); | |
178 | - }; | |
179 | - | |
180 | - $scope.guardar = function(key) { | |
181 | - | |
182 | - key = (typeof key === 'undefined') ? 13 : key; | |
183 | - if (key === 13) { | |
184 | - if (!$scope.chofer.nombre) { | |
185 | - focaModalService.alert('Ingrese nombre'); | |
186 | - return; | |
187 | - } else if (!$scope.chofer.idTipoDocumento) { | |
188 | - focaModalService.alert('Seleccione tipo de documento'); | |
189 | - return; | |
190 | - } else if (!$scope.chofer.dni) { | |
191 | - focaModalService.alert('Ingrese DNI'); | |
192 | - return; | |
193 | - } else if (!$scope.chofer.telefono) { | |
194 | - focaModalService.alert('Ingrese nรบmero de telรฉfono'); | |
195 | - return; | |
196 | - } | |
197 | - | |
198 | - validaDni().then(function() { | |
199 | - $scope.chofer.idTransportista = $routeParams.idTransportista; | |
200 | - delete $scope.chofer.transportista; | |
201 | - focaAbmChoferService.guardarChofer($scope.chofer).then(function() { | |
202 | - $location.path('/chofer'); | |
203 | - }); | |
204 | - }, function() { | |
205 | - focaModalService.alert('Dni existente'); | |
206 | - }); | |
207 | - } | |
208 | - }; | |
209 | - | |
210 | 231 | $scope.$watch('chofer', function(newValue) { |
211 | 232 | focaBotoneraLateralService.setPausarData({ |
212 | 233 | label: 'chofer', |
... | ... | @@ -219,35 +240,7 @@ angular.module('focaAbmChofer') |
219 | 240 | id: newValue.id |
220 | 241 | } |
221 | 242 | }); |
222 | - }, true); | |
243 | + }, true);*/ | |
223 | 244 | |
224 | - function salir() { | |
225 | - if ($scope.formChofer.$pristine == false) { | |
226 | - focaModalService.confirm( | |
227 | - 'ยฟEstรก seguro de que desea salir? Se perderรกn todos los datos cargados.' | |
228 | - ).then(function(data) { | |
229 | - if (data) { | |
230 | - $location.path('/chofer'); | |
231 | - } | |
232 | - }); | |
233 | - } else { | |
234 | - $location.path('/chofer'); | |
235 | - } | |
236 | - } | |
237 | - | |
238 | - function validaDni() { | |
239 | - return new Promise(function(resolve, reject) { | |
240 | - focaAbmChoferService | |
241 | - .getChoferPorDni($scope.chofer.dni) | |
242 | - .then(function(res) { | |
243 | - if (res.data.id && | |
244 | - $scope.chofer.id !== res.data.id) { | |
245 | - reject(res.data); | |
246 | - } else { | |
247 | - resolve(); | |
248 | - } | |
249 | - }); | |
250 | - }); | |
251 | - } | |
252 | 245 | } |
253 | 246 | ]); |
src/js/service.js
... | ... | @@ -16,6 +16,9 @@ angular.module('focaAbmChofer') |
16 | 16 | guardarChofer: function(chofer) { |
17 | 17 | return $http.post(API_ENDPOINT.URL + '/chofer', {chofer: chofer}); |
18 | 18 | }, |
19 | + guardarChoferes: function(choferes) { | |
20 | + return $http.post(API_ENDPOINT.URL + '/chofer', {choferes: choferes}); | |
21 | + }, | |
19 | 22 | getTransportistas: function() { |
20 | 23 | return $http.get(API_ENDPOINT.URL + '/transportista'); |
21 | 24 | }, |
src/views/foca-abm-choferes-listado.html
... | ... | @@ -16,29 +16,145 @@ |
16 | 16 | <thead> |
17 | 17 | <tr> |
18 | 18 | <th>Nombre</th> |
19 | + <th>Tipo</th> | |
19 | 20 | <th>Documento</th> |
20 | 21 | <th>Telรฉfono</th> |
21 | 22 | <th class="text-center"> |
22 | 23 | <button |
23 | - ng-disabled="!idTransportista" | |
24 | 24 | title="Agregar" |
25 | 25 | class="btn btn-outline-debo boton-accion" |
26 | - ng-click="editar(0)"> | |
26 | + ng-click="crearChofer()" | |
27 | + ng-disabled="!crear" | |
28 | + > | |
27 | 29 | <i class="fa fa-plus"></i> |
28 | 30 | </button> |
29 | 31 | </th> |
30 | 32 | </tr> |
31 | 33 | </thead> |
32 | 34 | <tbody> |
33 | - <tr ng-repeat="chofer in choferes | filter:filters"> | |
34 | - <td ng-bind="chofer.nombre"></td> | |
35 | - <td ng-bind="chofer.dni"></td> | |
36 | - <td ng-bind="chofer.telefono"></td> | |
37 | - <td class="text-center"> | |
35 | + <tr ng-show="creando"> | |
36 | + <td align="center"> | |
37 | + <input | |
38 | + class="form-control" | |
39 | + type="text" | |
40 | + teclado-virtual | |
41 | + ng-model="chofer.nombre" | |
42 | + ng-required="true" | |
43 | + ng-keypress="next($event.keyCode)" | |
44 | + foca-focus="focused == 1" | |
45 | + ng-focus="focused = 1" | |
46 | + > | |
47 | + </td> | |
48 | + <td align="center"> | |
49 | + <div class="col-sm-4"> | |
50 | + <select | |
51 | + class="form-control" | |
52 | + ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id" | |
53 | + ng-model="chofer.idTipoDocumento"> | |
54 | + </select> | |
55 | + </div> | |
56 | + </td> | |
57 | + <td align="center"> | |
58 | + <input | |
59 | + class="form-control" | |
60 | + foca-tipo-input | |
61 | + teclado-virtual | |
62 | + solo-positivos | |
63 | + limite-numeros-max="15" | |
64 | + ng-model="chofer.dni" | |
65 | + ng-required="true" | |
66 | + ng-keypress="next($event.keyCode)" | |
67 | + foca-focus="focused == 2" | |
68 | + ng-focus="focused = 2" | |
69 | + ng-disabled="!nuevo" | |
70 | + string-toNumber | |
71 | + > | |
72 | + </td> | |
73 | + <td align="center"> | |
74 | + <input | |
75 | + class="form-control" | |
76 | + foca-tipo-input | |
77 | + teclado-virtual | |
78 | + solo-positivos | |
79 | + limite-numeros-max="15" | |
80 | + ng-model="chofer.telefono" | |
81 | + ng-required="true" | |
82 | + foca-focus="focused == 3" | |
83 | + ng-focus="focused = 3" | |
84 | + string-toNumber | |
85 | + > | |
86 | + </td> | |
87 | + <td align="center"> | |
88 | + <button | |
89 | + class="btn btn-outline-dark boton-accion" | |
90 | + ng-click="agregarChofer()" | |
91 | + > | |
92 | + <i class="fa fa-save"></i> | |
93 | + </button> | |
94 | + </td> | |
95 | + </tr> | |
96 | + | |
97 | + <tr ng-repeat="(key, chofer) in choferes | filter:filters" ng-hide="chofer.desactivado"> | |
98 | + <td ng-bind="chofer.nombre" ng-hide="chofer.editando"></td> | |
99 | + <td align="center" ng-show="chofer.editando"> | |
100 | + <input | |
101 | + class="form-control" | |
102 | + type="text" | |
103 | + teclado-virtual | |
104 | + ng-model="chofer.nombre" | |
105 | + ng-required="true" | |
106 | + ng-keypress="next($event.keyCode)" | |
107 | + foca-focus="focused == 1" | |
108 | + ng-focus="focused = 1" | |
109 | + esc-key="volver(chofer, key)" | |
110 | + > | |
111 | + </td> | |
112 | + <td ng-bind="tipoDocumento(chofer.idTipoDocumento)" ng-hide="chofer.editando"></td> | |
113 | + <td align="center" ng-show="chofer.editando"> | |
114 | + <div class="col-sm-15"> | |
115 | + <select | |
116 | + class="form-control" | |
117 | + ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id" | |
118 | + ng-model="chofer.idTipoDocumento"> | |
119 | + </select> | |
120 | + </div> | |
121 | + </td> | |
122 | + <td ng-bind="chofer.dni" ng-hide="chofer.editando"> | |
123 | + <td align="center" ng-show="chofer.editando"> | |
124 | + <input | |
125 | + class="form-control" | |
126 | + type="text" | |
127 | + teclado-virtual | |
128 | + ng-model="chofer.dni" | |
129 | + ng-required="true" | |
130 | + ng-keypress="next($event.keyCode)" | |
131 | + foca-focus="focused == 2" | |
132 | + ng-focus="focused = 2" | |
133 | + esc-key="volver(chofer, key)" | |
134 | + > | |
135 | + </td> | |
136 | + </td> | |
137 | + <td ng-bind="chofer.telefono" ng-hide="chofer.editando"></td> | |
138 | + <td align="center" ng-show="chofer.editando"> | |
139 | + <input | |
140 | + class="form-control" | |
141 | + foca-tipo-input | |
142 | + teclado-virtual | |
143 | + solo-positivos | |
144 | + limite-numeros-max="15" | |
145 | + ng-model="chofer.telefono" | |
146 | + ng-required="true" | |
147 | + foca-focus="focused == 3" | |
148 | + ng-focus="focused = 3" | |
149 | + string-toNumber | |
150 | + esc-key="volver(chofer, key)" | |
151 | + > | |
152 | + </td> | |
153 | + <td class="text-center" ng-hide="chofer.editando"> | |
38 | 154 | <button |
39 | 155 | class="btn btn-outline-dark boton-accion" |
40 | 156 | title="Editar" |
41 | - ng-click="editar(chofer.id)" | |
157 | + ng-click="editar(chofer)" | |
42 | 158 | > |
43 | 159 | <i class="fa fa-pencil"></i> |
44 | 160 | </button> |
... | ... | @@ -50,6 +166,20 @@ |
50 | 166 | <i class="fa fa-trash"></i> |
51 | 167 | </button> |
52 | 168 | </td> |
169 | + <td align="center" ng-show="chofer.editando"> | |
170 | + <button | |
171 | + class="btn btn-outline-dark boton-accion" | |
172 | + ng-click="agregarChofer(chofer)" | |
173 | + > | |
174 | + <i class="fa fa-save"></i> | |
175 | + </button> | |
176 | + <button | |
177 | + class="btn btn-outline-dark boton-accion" | |
178 | + ng-click="volver(chofer, key)" | |
179 | + > | |
180 | + <i class="fa fa-undo" aria-hidden="true"></i> | |
181 | + </button> | |
182 | + </td> | |
53 | 183 | </tr> |
54 | 184 | </body> |
55 | 185 | </table> |