Commit 57bc8dfb4a209944dcd53aa9c14549ecfe2660ce
Exists in
master
and in
1 other branch
Merge branch 'develop' into 'master'
Develop See merge request !22
Showing
3 changed files
Show diff stats
src/js/controller.js
... | ... | @@ -2,40 +2,122 @@ 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.nombre) { | |
64 | + focaModalService.alert('Ingrese nombre'); | |
65 | + return; | |
66 | + } else if (!chofer.idTipoDocumento) { | |
67 | + focaModalService.alert('Ingrese tipo documento'); | |
68 | + return; | |
69 | + } | |
70 | + validaDni(chofer); | |
71 | + }; | |
72 | + | |
73 | + $scope.tipoDocumento = function (idTipoDocumento) { | |
74 | + var value = ''; | |
75 | + switch (parseInt(idTipoDocumento)) { | |
76 | + case 96 : | |
77 | + value = 'DNI'; | |
78 | + break; | |
79 | + case 80 : | |
80 | + value = 'CUIT'; | |
81 | + break; | |
82 | + case 86 : | |
83 | + value = 'CUIL'; | |
84 | + break; | |
85 | + default: | |
86 | + value = ''; | |
87 | + break; | |
88 | + } | |
89 | + return value; | |
90 | + }; | |
91 | + | |
92 | + $scope.volver = function (chofer, key) { | |
93 | + if (chofer.idTransportista === undefined) { | |
94 | + $scope.choferes.shift(); | |
95 | + $scope.crear = true; | |
96 | + chofer.editando = false; | |
97 | + return; | |
98 | + } else if (chofer.id !== 0 || !$scope.crear) { | |
99 | + $scope.choferes[key] = $scope.inicial; | |
100 | + $scope.choferes[key].editando = false; | |
101 | + } | |
102 | + $scope.crear = true; | |
103 | + }; | |
104 | + | |
105 | + $scope.guardar = function() { | |
106 | + $scope.choferes.forEach( function (chofer) { | |
107 | + if (chofer.id === 0) { | |
108 | + delete chofer.id; | |
109 | + } | |
110 | + delete chofer.transportista; | |
111 | + delete chofer.editando; | |
112 | + }); | |
113 | + focaAbmChoferService.guardarChoferes($scope.choferes); | |
31 | 114 | }; |
32 | 115 | |
33 | 116 | $scope.solicitarConfirmacion = function(chofer) { |
34 | 117 | focaModalService.confirm('ยฟEstรก seguro que desea borrar el chofer ' + |
35 | 118 | chofer.nombre + ' ?').then(function(confirmed) { |
36 | 119 | if (confirmed) { |
37 | - focaAbmChoferService.deleteChofer(chofer.id); | |
38 | - $scope.choferes.splice($scope.choferes.indexOf(chofer), 1); | |
120 | + chofer.desactivado = true; | |
39 | 121 | } |
40 | 122 | }); |
41 | 123 | }; |
... | ... | @@ -61,6 +143,7 @@ angular.module('focaAbmChofer') |
61 | 143 | }; |
62 | 144 | focaModalService.modal(parametrosModal).then( |
63 | 145 | function(transportista) { |
146 | + $scope.crear = true; | |
64 | 147 | elegirTransportista(transportista); |
65 | 148 | focaAbmChoferService.transportistaSeleccionado = transportista; |
66 | 149 | }, function() {} |
... | ... | @@ -90,164 +173,42 @@ angular.module('focaAbmChofer') |
90 | 173 | $location.path('/'); |
91 | 174 | } |
92 | 175 | |
93 | - if ($localStorage.chofer) { | |
94 | - var chofer = JSON.parse($localStorage.chofer); | |
95 | - if (!chofer.id) { chofer.id = 0; } | |
96 | - $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); | |
97 | - } | |
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 | - | |
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 | - }); | |
159 | - | |
160 | - function setearChofer(chofer) { | |
161 | - $scope.chofer = chofer; | |
162 | - $scope.$broadcast('addCabecera', { | |
163 | - label: 'Transportista:', | |
164 | - valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - ' | |
165 | - }); | |
166 | - } | |
167 | - function getLSChofer() { | |
168 | - var chofer = JSON.parse($localStorage.chofer || null); | |
169 | - | |
170 | - if (chofer) { | |
171 | - setearChofer(chofer); | |
172 | - delete $localStorage.chofer; | |
173 | - } | |
174 | - } | |
175 | - | |
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 | - $scope.$watch('chofer', function(newValue) { | |
211 | - focaBotoneraLateralService.setPausarData({ | |
212 | - label: 'chofer', | |
213 | - val: { | |
214 | - dni: newValue.dni, | |
215 | - idTransportista: newValue.idTransportista, | |
216 | - nombre: newValue.nombre, | |
217 | - telefono: newValue.telefono, | |
218 | - idTipoDocumento: newValue.idTipoDocumento, | |
219 | - id: newValue.id | |
220 | - } | |
221 | - }); | |
222 | - }, true); | |
223 | - | |
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'); | |
176 | + function validaDni(chofer) { | |
177 | + if (!chofer.dni) { | |
178 | + focaModalService.alert('Ingrese DNI'); | |
179 | + return; | |
180 | + } else if (!chofer.telefono) { | |
181 | + focaModalService.alert('Ingrese telรฉfono'); | |
182 | + return; | |
235 | 183 | } |
236 | - } | |
237 | 184 | |
238 | - function validaDni() { | |
239 | 185 | return new Promise(function(resolve, reject) { |
240 | 186 | focaAbmChoferService |
241 | - .getChoferPorDni($scope.chofer.dni) | |
187 | + .getChoferPorDni(chofer.dni) | |
242 | 188 | .then(function(res) { |
243 | 189 | if (res.data.id && |
244 | - $scope.chofer.id !== res.data.id) { | |
190 | + chofer.id !== res.data.id) { | |
245 | 191 | reject(res.data); |
246 | 192 | } else { |
247 | 193 | resolve(); |
248 | 194 | } |
195 | + }) | |
196 | + .then(function() { | |
197 | + chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD; | |
198 | + delete chofer.transportista; | |
199 | + }, function() { | |
200 | + focaModalService.alert('Dni existente'); | |
201 | + $scope.editando = true; | |
249 | 202 | }); |
203 | + $scope.crear = true; | |
204 | + chofer.editando = false; | |
250 | 205 | }); |
251 | 206 | } |
207 | + | |
208 | + if ($localStorage.chofer) { | |
209 | + var chofer = JSON.parse($localStorage.chofer); | |
210 | + if (!chofer.id) { chofer.id = 0; } | |
211 | + $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); | |
212 | + } | |
252 | 213 | } |
253 | 214 | ]); |
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> |