Commit f1a54f5ad469484ebf75be5f3f3a4c450a035696

Authored by Eric
Exists in master and in 1 other branch develop

conflictos

src/js/controller.js
1 1 angular.module('focaAbmVehiculo')
2 2 .controller('focaAbmVehiculosController', [
3 3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService',
4   - '$uibModal', 'focaBotoneraLateralService', '$timeout',
  4 + '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 5 function($scope, focaAbmVehiculoService, $location, focaModalService,
6   - $uibModal, focaBotoneraLateralService, $timeout) {
  6 + $uibModal, focaBotoneraLateralService, $timeout, $localStorage) {
7 7  
8 8 $scope.now = new Date();
9 9 $scope.botonera = [{
... ... @@ -20,7 +20,13 @@ angular.module('focaAbmVehiculo')
20 20 focaBotoneraLateralService.showGuardar(false);
21 21 focaBotoneraLateralService.addCustomButton('Salir', salir);
22 22  
23   - if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
  23 + if ($localStorage.vehiculo) {
  24 + var vehiculo = JSON.parse($localStorage.vehiculo);
  25 + if (!vehiculo.idVehiculo) vehiculo.idVehiculo = 0;
  26 + $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista);
  27 + }
  28 +
  29 + if (focaAbmVehiculoService.transportistaSeleccionado.COD) {
24 30 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
25 31 }
26 32 $scope.editar = function(id) {
... ... @@ -30,7 +36,7 @@ angular.module('focaAbmVehiculo')
30 36 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
31 37 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
32 38 function(data) {
33   - if(data) {
  39 + if (data) {
34 40 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
35 41 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
36 42 }
... ... @@ -93,9 +99,9 @@ angular.module('focaAbmVehiculo')
93 99 ])
94 100 .controller('focaAbmVehiculoController', [
95 101 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
96   - 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window',
  102 + 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter',
97 103 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
98   - focaModalService, $timeout, focaBotoneraLateralService, $window) {
  104 + focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) {
99 105 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
100 106 $scope.now = new Date();
101 107 $scope.focused = 1;
... ... @@ -104,13 +110,15 @@ angular.module('focaAbmVehiculo')
104 110  
105 111 $timeout(function() {
106 112 focaBotoneraLateralService.showSalir(false);
107   - focaBotoneraLateralService.showPausar(false);
  113 + focaBotoneraLateralService.showPausar(true);
108 114 focaBotoneraLateralService.showCancelar(false);
109 115 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
110   - focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar);
  116 + focaBotoneraLateralService.addCustomButton('Cancelar', cancelar);
111 117 });
  118 +
  119 + $timeout(function() {getLSVehiculo();});
112 120  
113   - if($scope.nuevo) {
  121 + if ($scope.nuevo) {
114 122 focaAbmVehiculoService
115 123 .getTransportistaPorId($routeParams.idTransportista)
116 124 .then(function(res) {
... ... @@ -125,7 +133,7 @@ angular.module('focaAbmVehiculo')
125 133 }
126 134 $scope.vehiculo = {};
127 135 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
128   - if(res.data) {
  136 + if (res.data) {
129 137 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
130 138 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
131 139  
... ... @@ -150,11 +158,23 @@ angular.module('focaAbmVehiculo')
150 158 $scope.next = function(key) {
151 159 if (key === 13) $scope.focused++;
152 160 };
153   - $scope.cancelar = function() {
154   - $location.path('/vehiculo');
155   - };
  161 +
  162 + function cancelar() {
  163 + if ($scope.formVehiculo.$pristine == false) {
  164 + focaModalService.confirm(
  165 + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
  166 + ).then(function(data) {
  167 + if (data) {
  168 + $location.path('/vehiculo');
  169 + }
  170 + });
  171 + } else {
  172 + $location.path('/vehiculo');
  173 + }
  174 + }
  175 +
156 176 $scope.editar = function(key) {
157   - if(key) {
  177 + if (key) {
158 178 $location.path('/vehiculo/' + $routeParams.idVehiculo +
159 179 '/cisterna/' + key);
160 180 } else {
... ... @@ -162,10 +182,25 @@ angular.module('focaAbmVehiculo')
162 182 }
163 183 };
164 184 $scope.guardar = function(key) {
  185 +
165 186 key = (typeof key === 'undefined') ? 13 : key;
166   - if(key === 13) {
  187 +
  188 + if (key === 13) {
  189 + if (!$scope.vehiculo.codigo) {
  190 + focaModalService.alert('Ingrese unidad');
  191 + return;
  192 + } else if (!$scope.vehiculo.tractor) {
  193 + focaModalService.alert('Ingrese dominio tractor');
  194 + return;
  195 + } else if (!$scope.vehiculo.semi) {
  196 + focaModalService.alert('Ingrese dominio semi');
  197 + return;
  198 + } else if (!$scope.vehiculo.capacidad) {
  199 + focaModalService.alert('Ingrese capacidad total');
  200 + return;
  201 + }
167 202 //Valida si existe numero de unidad
168   - if(!validaTotalCargas() && !$scope.nuevo) {
  203 + if (!validaTotalCargas() && !$scope.nuevo) {
169 204 focaModalService.alert('La suma de las capacidades de las cisternas' +
170 205 ' debe ser igual a la capacidad total del vehículo');
171 206 return;
... ... @@ -190,11 +225,42 @@ angular.module('focaAbmVehiculo')
190 225 }
191 226  
192 227 };
  228 +
  229 + $scope.$watch('vehiculo', function(newValue) {
  230 + focaBotoneraLateralService.setPausarData({
  231 + label:'vehiculo',
  232 + val: {
  233 + codigo: newValue.codigo,
  234 + tractor: newValue.tractor,
  235 + semi: newValue.semi,
  236 + capacidad: newValue.capacidad,
  237 + idVehiculo: newValue.idVehiculo,
  238 + idTransportista: newValue.idTransportista
  239 + }
  240 + });
  241 + }, true);
  242 +
  243 + function getLSVehiculo() {
  244 + var vehiculo = JSON.parse($localStorage.vehiculo|| null);
  245 + if (vehiculo) {
  246 + setearVehiculo(vehiculo);
  247 + delete $localStorage.vehiculo;
  248 + }
  249 + }
  250 +
  251 + function setearVehiculo(vehiculo) {
  252 + $scope.vehiculo = vehiculo;
  253 + $scope.$broadcast('addCabecera', {
  254 + label: 'Vehiculo:',
  255 + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - '
  256 + });
  257 + }
  258 +
193 259 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) {
194 260 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
195 261 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
196 262 function(data) {
197   - if(data) {
  263 + if (data) {
198 264 focaAbmVehiculoService.deleteCisterna(idx);
199 265 focaAbmVehiculoService
200 266 .getCisternas($routeParams.idVehiculo)
... ... @@ -217,9 +283,9 @@ angular.module('focaAbmVehiculo')
217 283 vehiculo.id !== $scope.vehiculo.id;
218 284 });
219 285  
220   - if(existe.length) {
  286 + if (existe.length) {
221 287 reject(existe);
222   - }else {
  288 + } else {
223 289 resolve();
224 290 }
225 291 });
... ... @@ -229,7 +295,7 @@ angular.module('focaAbmVehiculo')
229 295 function validaTotalCargas() {
230 296 var total = 0;
231 297 $scope.cisternas.forEach(function(cisterna) {
232   - if(!cisterna.desactivado) {
  298 + if (!cisterna.desactivado) {
233 299 total += parseInt(cisterna.capacidad);
234 300 }
235 301 });
src/js/controllerCisterna.js
1 1 angular.module('focaAbmVehiculo')
2 2 .controller('focaAbmVehiculoCisternaController', [
3 3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
4   - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
  4 + 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter',
5 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6   - focaModalService, focaBotoneraLateralService, $timeout, $window) {
  6 + focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) {
7 7 $scope.nuevo = ($routeParams.idx > -1) ? false : true;
8 8 $scope.editar = false;
9 9 $scope.now = new Date();
10   - $scope.cisterna = {};
  10 + $scope.cisterna = {
  11 + codigo: '',
  12 + capacidad: '',
  13 + unidadMedida: {}
  14 + };
11 15  
12 16 $scope.focused = $scope.nuevo ? 1 : 2;
13 17 $scope.next = function(key) {
... ... @@ -19,12 +23,14 @@ angular.module('focaAbmVehiculo')
19 23 //SETEO BOTONERA LATERAL
20 24 $timeout(function() {
21 25 focaBotoneraLateralService.showSalir(false);
22   - focaBotoneraLateralService.showPausar(false);
23   - focaBotoneraLateralService.showCancelar(true);
  26 + focaBotoneraLateralService.showPausar(true);
  27 + focaBotoneraLateralService.showCancelar(false);
24 28 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
  29 + focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar);
25 30 });
26 31  
27   - if($routeParams.idx !== -1) {
  32 + if ($routeParams.idx != -1) {
  33 +
28 34 $scope.cisterna = [$routeParams.idx];
29 35 focaAbmVehiculoService
30 36 .getCisternas($routeParams.idVehiculo)
... ... @@ -51,13 +57,30 @@ angular.module('focaAbmVehiculo')
51 57 });
52 58 });
53 59 $scope.cancelar = function() {
54   - $location.path('/vehiculo/' + $routeParams.idVehiculo);
  60 +
  61 + if ($scope.formCisterna.$pristine == false) {
  62 + focaModalService.confirm(
  63 + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
  64 + ).then(function(data) {
  65 + if (data) {
  66 + $location.path('/vehiculo');
  67 + }
  68 + });
  69 + }
55 70 };
56   - $scope.guardar = function() {
57   - if(!$scope.cisterna.unidadMedida) {
  71 + $scope.guardar = function() {
  72 +
  73 + if (!$scope.cisterna.codigo) {
  74 + focaModalService.alert('Ingrese codigo de cisterna');
  75 + return;
  76 + } else if (!$scope.cisterna.capacidad) {
  77 + focaModalService.alert('Ingrese capacidad');
  78 + return;
  79 + } else if (!$scope.cisterna.idUnidadMedida) {
58 80 focaModalService.alert('Ingrese unidad de medida');
59 81 return;
60 82 }
  83 +
61 84 validaCodigo()
62 85 .then(function() {
63 86 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
... ... @@ -100,12 +123,12 @@ angular.module('focaAbmVehiculo')
100 123 var totalCargado = 0;
101 124 cisternas.forEach(function(cisterna, idx) {
102 125 //SI EL CODIGO YA EXISTE
103   - if(cisterna.codigo === $scope.cisterna.codigo &&
  126 + if (cisterna.codigo === $scope.cisterna.codigo &&
104 127 idx != $routeParams.idx &&
105 128 !cisterna.desactivado) {
106 129 reject('Código de cisterna existente');
107 130 }
108   - if(idx != $routeParams.idx &&
  131 + if (idx != $routeParams.idx &&
109 132 !cisterna.desactivado) {
110 133 totalCargado += cisterna.capacidad;
111 134 }