Commit 30577ea5f6d6f65d71d74e090a0fb313a6a4aeea

Authored by Jose Pinto
Exists in master and in 1 other branch develop

Merge branch 'master' into 'develop'

Master

See merge request !36
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,9 +158,21 @@ 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 177 if (key) {
158 178 $location.path('/vehiculo/' + $routeParams.idVehiculo +
... ... @@ -163,25 +183,24 @@ angular.module('focaAbmVehiculo')
163 183 };
164 184 $scope.guardar = function(key) {
165 185  
166   - if (!$scope.vehiculo.codigo) {
167   - focaModalService.alert('Ingrese unidad');
168   - return;
169   - } else if (!$scope.vehiculo.tractor) {
170   - focaModalService.alert('Ingrese dominio tractor');
171   - return;
172   - } else if (!$scope.vehiculo.semi) {
173   - focaModalService.alert('Ingrese dominio semi');
174   - return;
175   - } else if (!$scope.vehiculo.capacidad) {
176   - focaModalService.alert('Ingrse capacidad total');
177   - return;
178   - }
179   -
180   -
181 186 key = (typeof key === 'undefined') ? 13 : key;
  187 +
182 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 + }
183 202 //Valida si existe numero de unidad
184   - if(!validaTotalCargas() && !$scope.nuevo) {
  203 + if (!validaTotalCargas() && !$scope.nuevo) {
185 204 focaModalService.alert('La suma de las capacidades de las cisternas' +
186 205 ' debe ser igual a la capacidad total del vehículo');
187 206 return;
... ... @@ -206,11 +225,42 @@ angular.module('focaAbmVehiculo')
206 225 }
207 226  
208 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 +
209 259 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) {
210 260 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
211 261 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
212 262 function(data) {
213   - if(data) {
  263 + if (data) {
214 264 focaAbmVehiculoService.deleteCisterna(idx);
215 265 focaAbmVehiculoService
216 266 .getCisternas($routeParams.idVehiculo)
... ... @@ -233,9 +283,9 @@ angular.module('focaAbmVehiculo')
233 283 vehiculo.id !== $scope.vehiculo.id;
234 284 });
235 285  
236   - if(existe.length) {
  286 + if (existe.length) {
237 287 reject(existe);
238   - }else {
  288 + } else {
239 289 resolve();
240 290 }
241 291 });
... ... @@ -245,7 +295,7 @@ angular.module('focaAbmVehiculo')
245 295 function validaTotalCargas() {
246 296 var total = 0;
247 297 $scope.cisternas.forEach(function(cisterna) {
248   - if(!cisterna.desactivado) {
  298 + if (!cisterna.desactivado) {
249 299 total += parseInt(cisterna.capacidad);
250 300 }
251 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();
... ... @@ -23,9 +23,10 @@ angular.module('focaAbmVehiculo')
23 23 //SETEO BOTONERA LATERAL
24 24 $timeout(function() {
25 25 focaBotoneraLateralService.showSalir(false);
26   - focaBotoneraLateralService.showPausar(false);
27   - focaBotoneraLateralService.showCancelar(true);
  26 + focaBotoneraLateralService.showPausar(true);
  27 + focaBotoneraLateralService.showCancelar(false);
28 28 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
  29 + focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar);
29 30 });
30 31  
31 32 if ($routeParams.idx != -1) {
... ... @@ -56,7 +57,16 @@ angular.module('focaAbmVehiculo')
56 57 });
57 58 });
58 59 $scope.cancelar = function() {
59   - $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 + }
60 70 };
61 71 $scope.guardar = function() {
62 72  
... ... @@ -113,12 +123,12 @@ angular.module('focaAbmVehiculo')
113 123 var totalCargado = 0;
114 124 cisternas.forEach(function(cisterna, idx) {
115 125 //SI EL CODIGO YA EXISTE
116   - if(cisterna.codigo === $scope.cisterna.codigo &&
  126 + if (cisterna.codigo === $scope.cisterna.codigo &&
117 127 idx != $routeParams.idx &&
118 128 !cisterna.desactivado) {
119 129 reject('Código de cisterna existente');
120 130 }
121   - if(idx != $routeParams.idx &&
  131 + if (idx != $routeParams.idx &&
122 132 !cisterna.desactivado) {
123 133 totalCargado += cisterna.capacidad;
124 134 }